-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
single callback video event #81
Changes from 12 commits
b095cc6
3c7ffc7
e0188d3
4945379
e4cf951
3f48733
bffee1f
1e6b3f1
1ec7477
d50444d
f318b3c
0452c69
1eef24e
8ef7505
5be43c2
4105ce3
3dddf5d
89e336f
f5b435d
9fb883b
04fd03e
9d62cae
2729631
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -42,6 +42,8 @@ public class SimpleCameraPreview extends CordovaPlugin { | |||||
private LocationManager locationManager; | ||||||
private LocationListener mLocationCallback; | ||||||
private ViewParent webViewParent; | ||||||
private CallbackContext videoCallbackContext; | ||||||
|
||||||
|
||||||
private static final int containerViewId = 20; | ||||||
private static final int DIRECTION_FRONT = 0; | ||||||
|
@@ -72,6 +74,15 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo | |||||
case "torchSwitch": | ||||||
return torchSwitch(args.getBoolean(0), callbackContext); | ||||||
|
||||||
case "initVideoCallback": | ||||||
return initVideoCallback(callbackContext); | ||||||
|
||||||
case "startVideoCapture": | ||||||
return startVideoCapture(callbackContext); | ||||||
|
||||||
case "stopVideoCapture": | ||||||
return stopVideoCapture(callbackContext); | ||||||
|
||||||
case "deviceHasFlash": | ||||||
return deviceHasFlash(callbackContext); | ||||||
|
||||||
|
@@ -92,6 +103,89 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo | |||||
} | ||||||
} | ||||||
|
||||||
private boolean initVideoCallback(CallbackContext callbackContext) { | ||||||
this.videoCallbackContext = callbackContext; | ||||||
PluginResult result = new PluginResult(PluginResult.Status.OK, "video cb initialized"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
result.setKeepCallback(true); | ||||||
this.videoCallbackContext.sendPluginResult(result); | ||||||
return true; | ||||||
} | ||||||
|
||||||
private boolean startVideoCapture(CallbackContext callbackContext) { | ||||||
if (fragment == null) { | ||||||
callbackContext.error("Camera is closed"); | ||||||
return true; | ||||||
} | ||||||
|
||||||
if (this.videoCallbackContext != null) { | ||||||
fragment.startVideoCapture(new VideoCallback() { | ||||||
public void onStart(Boolean recording, String nativePath) { | ||||||
JSONObject data = new JSONObject(); | ||||||
if (recording) { | ||||||
try { | ||||||
data.put("recording", true); | ||||||
data.put("nativePath", null); | ||||||
} catch (JSONException e) { | ||||||
e.printStackTrace(); | ||||||
videoCallbackContext.error("Cannot send recording data"); | ||||||
return; | ||||||
} | ||||||
|
||||||
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, data); | ||||||
pluginResult.setKeepCallback(true); | ||||||
videoCallbackContext.sendPluginResult(pluginResult); | ||||||
} | ||||||
} | ||||||
|
||||||
public void onStop(Boolean recording, String nativePath) { | ||||||
JSONObject data = new JSONObject(); | ||||||
try { | ||||||
data.put("recording", false); | ||||||
data.put("nativePath", nativePath); | ||||||
} catch (JSONException e) { | ||||||
e.printStackTrace(); | ||||||
videoCallbackContext.error("Cannot send recording data"); | ||||||
return; | ||||||
} | ||||||
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, data); | ||||||
pluginResult.setKeepCallback(true); | ||||||
videoCallbackContext.sendPluginResult(pluginResult); | ||||||
} | ||||||
|
||||||
@Override | ||||||
public void onError(String errMessage) { | ||||||
JSONObject data = new JSONObject(); | ||||||
try { | ||||||
data.put("error", errMessage); | ||||||
} catch (JSONException e) { | ||||||
e.printStackTrace(); | ||||||
return; | ||||||
} | ||||||
PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, data); | ||||||
pluginResult.setKeepCallback(true); | ||||||
videoCallbackContext.sendPluginResult(pluginResult); | ||||||
} | ||||||
}); | ||||||
} | ||||||
callbackContext.success(); | ||||||
return true; | ||||||
} | ||||||
|
||||||
|
||||||
private boolean stopVideoCapture(CallbackContext callbackContext) { | ||||||
if (fragment == null) { | ||||||
callbackContext.error("Camera is closed"); | ||||||
return true; | ||||||
} | ||||||
|
||||||
if (this.videoCallbackContext != null) { | ||||||
fragment.stopVideoCapture(); | ||||||
} | ||||||
|
||||||
callbackContext.success(); | ||||||
return true; | ||||||
} | ||||||
|
||||||
private boolean setOptions(JSONObject options, CallbackContext callbackContext) { | ||||||
int targetSize = 0; | ||||||
try { | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,41 @@ var exec = require("cordova/exec"); | |||||
var PLUGIN_NAME = "SimpleCameraPreview"; | ||||||
var SimpleCameraPreview = function () {}; | ||||||
|
||||||
SimpleCameraPreview.videoInitialized = false; | ||||||
SimpleCameraPreview.videoCallback = null; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zfir we can consider it as a refactoring for the next version |
||||||
|
||||||
SimpleCameraPreview.startVideoCapture = function (onSuccess, onError) { | ||||||
if (!SimpleCameraPreview.videoCallback) { | ||||||
console.error("Call setVideoCallback first"); | ||||||
onError("Call setVideoCallback first"); | ||||||
return; | ||||||
} | ||||||
|
||||||
if (!SimpleCameraPreview.videoInitialized) { | ||||||
exec( | ||||||
(info) => { | ||||||
SimpleCameraPreview.videoInitialized = true; | ||||||
this.videoCallback(info); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} , | ||||||
(err) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
this.videoCallback(null, err); | ||||||
}, | ||||||
"SimpleCameraPreview", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"initVideoCallback", | ||||||
[] | ||||||
); | ||||||
} | ||||||
exec(onSuccess, onError, PLUGIN_NAME, "startVideoCapture"); | ||||||
dinitri marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}; | ||||||
|
||||||
SimpleCameraPreview.stopVideoCapture = function (onSuccess, onError) { | ||||||
exec(onSuccess, onError, PLUGIN_NAME, "stopVideoCapture"); | ||||||
}; | ||||||
|
||||||
SimpleCameraPreview.setVideoCallback = function (callback) { | ||||||
this.videoCallback = callback; | ||||||
} | ||||||
|
||||||
SimpleCameraPreview.setOptions = function (options, onSuccess, onError) { | ||||||
exec(onSuccess, onError, PLUGIN_NAME, "setOptions", [options]); | ||||||
}; | ||||||
|
@@ -43,3 +78,4 @@ SimpleCameraPreview.deviceHasUltraWideCamera = function (onSuccess, onError) { | |||||
}; | ||||||
|
||||||
module.exports = SimpleCameraPreview; | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to put this,