Skip to content

Commit b5a7fb2

Browse files
authored
fix: rare null activity when camera device is queried (#8)
1 parent 3fe2738 commit b5a7fb2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,17 @@ void getUserMedia(final ReadableMap constraints, final Callback successCallback,
195195

196196
Log.d(TAG, "getUserMedia(video): " + videoConstraintsMap);
197197

198+
Activity currentActivity = reactContext.getCurrentActivity();
199+
200+
if (currentActivity == null) {
201+
// Fail with DOMException with name InvalidStateError as per:
202+
// https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia
203+
errorCallback.invoke("DOMException", "InvalidStateError");
204+
return;
205+
}
206+
198207
CameraCaptureController cameraCaptureController =
199-
new CameraCaptureController(reactContext.getCurrentActivity(), getCameraEnumerator(), videoConstraintsMap);
208+
new CameraCaptureController(currentActivity, getCameraEnumerator(), videoConstraintsMap);
200209

201210
videoTrack = createVideoTrack(cameraCaptureController);
202211
}

0 commit comments

Comments
 (0)