@capgo/camera-preview 7.21.5 → 7.21.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -114,6 +114,8 @@ public class CameraPreview
|
|
|
114
114
|
private String captureCallbackId = "";
|
|
115
115
|
private String sampleCallbackId = "";
|
|
116
116
|
private String cameraStartCallbackId = "";
|
|
117
|
+
private final Object pendingStartLock = new Object();
|
|
118
|
+
private PluginCall pendingStartCall;
|
|
117
119
|
private int previousOrientationRequest =
|
|
118
120
|
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
|
119
121
|
private CameraXView cameraXView;
|
|
@@ -237,7 +239,18 @@ public class CameraPreview
|
|
|
237
239
|
// Prevent starting while an existing view is still active or stopping
|
|
238
240
|
if (cameraXView != null) {
|
|
239
241
|
try {
|
|
240
|
-
if (cameraXView.isRunning()
|
|
242
|
+
if (cameraXView.isRunning()) {
|
|
243
|
+
call.reject("Camera is already running");
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (cameraXView.isBusy()) {
|
|
247
|
+
if (enqueuePendingStart(call)) {
|
|
248
|
+
Log.d(
|
|
249
|
+
TAG,
|
|
250
|
+
"start: Camera busy; queued start request until stop completes"
|
|
251
|
+
);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
241
254
|
call.reject("Camera is busy or stopping. Please retry shortly.");
|
|
242
255
|
return;
|
|
243
256
|
}
|
|
@@ -261,6 +274,16 @@ public class CameraPreview
|
|
|
261
274
|
}
|
|
262
275
|
}
|
|
263
276
|
|
|
277
|
+
private boolean enqueuePendingStart(PluginCall call) {
|
|
278
|
+
synchronized (pendingStartLock) {
|
|
279
|
+
if (pendingStartCall == null) {
|
|
280
|
+
pendingStartCall = call;
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
|
|
264
287
|
@PluginMethod
|
|
265
288
|
public void flip(PluginCall call) {
|
|
266
289
|
if (cameraXView == null || !cameraXView.isRunning()) {
|
|
@@ -1555,6 +1578,20 @@ public class CameraPreview
|
|
|
1555
1578
|
public void onCameraStopped() {
|
|
1556
1579
|
// Ensure reference is cleared once underlying CameraXView has fully stopped
|
|
1557
1580
|
cameraXView = null;
|
|
1581
|
+
|
|
1582
|
+
PluginCall queuedCall = null;
|
|
1583
|
+
synchronized (pendingStartLock) {
|
|
1584
|
+
if (pendingStartCall != null) {
|
|
1585
|
+
queuedCall = pendingStartCall;
|
|
1586
|
+
pendingStartCall = null;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
if (queuedCall != null) {
|
|
1591
|
+
PluginCall finalQueuedCall = queuedCall;
|
|
1592
|
+
Log.d(TAG, "onCameraStopped: replaying pending start request");
|
|
1593
|
+
getBridge().getActivity().runOnUiThread(() -> start(finalQueuedCall));
|
|
1594
|
+
}
|
|
1558
1595
|
}
|
|
1559
1596
|
|
|
1560
1597
|
private JSObject getViewSize(
|