@@ -211,6 +211,12 @@ public void onResume() {
211
211
this .applicationContext = applicationContext ;
212
212
}
213
213
214
+ static private void resultError (String method , String error , Result result ) {
215
+ String errorMsg = method + "(): " + error ;
216
+ result .error (method , errorMsg ,null );
217
+ Log .d (TAG , errorMsg );
218
+ }
219
+
214
220
/**
215
221
* Includes default constraints set for the audio media type.
216
222
*
@@ -396,7 +402,7 @@ void getUserMedia(
396
402
// requestedMediaTypes is the empty set, the method invocation fails
397
403
// with a TypeError.
398
404
if (requestPermissions .isEmpty ()) {
399
- result . error ( "TypeError " , "constraints requests no media types" , null );
405
+ resultError ( "getUserMedia " , "TypeError, constraints requests no media types" , result );
400
406
return ;
401
407
}
402
408
@@ -423,7 +429,7 @@ public void invoke(Object... args) {
423
429
// getUserMedia() algorithm, if the user has denied
424
430
// permission, fail "with a new DOMException object whose
425
431
// name attribute has the value NotAllowedError."
426
- result . error ( "DOMException " , "NotAllowedError" , null );
432
+ resultError ( "getUserMedia " , "DOMException, NotAllowedError" , result );
427
433
}
428
434
});
429
435
}
@@ -453,7 +459,7 @@ protected void onReceiveResult(int requestCode, Bundle resultData) {
453
459
Intent mediaProjectionData = resultData .getParcelable (PROJECTION_DATA );
454
460
455
461
if (resultCode != Activity .RESULT_OK ) {
456
- result . error ( null , "User didn't give permission to capture the screen." , null );
462
+ resultError ( "screenRequestPremissions" , "User didn't give permission to capture the screen." , result );
457
463
return ;
458
464
}
459
465
@@ -465,13 +471,11 @@ protected void onReceiveResult(int requestCode, Bundle resultData) {
465
471
new MediaProjection .Callback () {
466
472
@ Override
467
473
public void onStop () {
468
- Log .e (TAG , "User revoked permission to capture the screen." );
469
- result .error (null , "User revoked permission to capture the screen." , null );
474
+ resultError ("MediaProjection.Callback()" , "User revoked permission to capture the screen." , result );
470
475
}
471
476
});
472
477
if (videoCapturer == null ) {
473
- result .error (
474
- /* type */ "GetDisplayMediaFailed" , "Failed to create new VideoCapturer!" , null );
478
+ resultError ("screenRequestPremissions" , "GetDisplayMediaFailed, User revoked permission to capture the screen." , result );
475
479
return ;
476
480
}
477
481
@@ -573,7 +577,7 @@ private void getUserMedia(
573
577
// specified by
574
578
// https://www.w3.org/TR/mediacapture-streams/#dom-mediadevices-getusermedia
575
579
// with respect to distinguishing the various causes of failure.
576
- result . error ( /* type */ "GetUserMediaFailed " , "Failed to create new track" , null );
580
+ resultError ( "getUserMedia " , "Failed to create new track. " , result );
577
581
return ;
578
582
}
579
583
@@ -753,7 +757,7 @@ private void requestPermissions(
753
757
void switchCamera (String id , Result result ) {
754
758
VideoCapturer videoCapturer = mVideoCapturers .get (id );
755
759
if (videoCapturer == null ) {
756
- result . error ( null , "Video capturer not found for id: " + id , null );
760
+ resultError ( "switchCamera" , "Video capturer not found for id: " + id , result );
757
761
return ;
758
762
}
759
763
@@ -767,7 +771,7 @@ public void onCameraSwitchDone(boolean b) {
767
771
768
772
@ Override
769
773
public void onCameraSwitchError (String s ) {
770
- result . error ( " Switching camera failed" , s , null );
774
+ resultError ( "switchCamera" , " Switching camera failed: " + id , result );
771
775
}
772
776
});
773
777
}
@@ -818,7 +822,7 @@ void stopRecording(Integer id) {
818
822
void hasTorch (String trackId , Result result ) {
819
823
VideoCapturer videoCapturer = mVideoCapturers .get (trackId );
820
824
if (videoCapturer == null ) {
821
- result . error ( null , "Video capturer not found for id: " + trackId , null );
825
+ resultError ( "hasTorch" , "Video capturer not found for id: " + trackId , result );
822
826
return ;
823
827
}
824
828
@@ -837,8 +841,7 @@ void hasTorch(String trackId, Result result) {
837
841
(CameraDevice ) getPrivateProperty (session .getClass (), session , "cameraDevice" );
838
842
} catch (NoSuchFieldWithNameException e ) {
839
843
// Most likely the upstream Camera2Capturer class have changed
840
- Log .e (TAG , "[TORCH] Failed to get `" + e .fieldName + "` from `" + e .className + "`" );
841
- result .error (null , "Failed to get `" + e .fieldName + "` from `" + e .className + "`" , null );
844
+ resultError ("hasTorch" , "[TORCH] Failed to get `" + e .fieldName + "` from `" + e .className + "`" , result );
842
845
return ;
843
846
}
844
847
@@ -866,8 +869,7 @@ void hasTorch(String trackId, Result result) {
866
869
camera = (Camera ) getPrivateProperty (session .getClass (), session , "camera" );
867
870
} catch (NoSuchFieldWithNameException e ) {
868
871
// Most likely the upstream Camera1Capturer class have changed
869
- Log .e (TAG , "[TORCH] Failed to get `" + e .fieldName + "` from `" + e .className + "`" );
870
- result .error (null , "Failed to get `" + e .fieldName + "` from `" + e .className + "`" , null );
872
+ resultError ("hasTorch" , "[TORCH] Failed to get `" + e .fieldName + "` from `" + e .className + "`" , result );
871
873
return ;
872
874
}
873
875
@@ -879,15 +881,14 @@ void hasTorch(String trackId, Result result) {
879
881
return ;
880
882
}
881
883
882
- Log .e (TAG , "[TORCH] Video capturer not compatible" );
883
- result .error (null , "Video capturer not compatible" , null );
884
+ resultError ("hasTorch" , "[TORCH] Video capturer not compatible" , result );
884
885
}
885
886
886
887
@ RequiresApi (api = VERSION_CODES .LOLLIPOP )
887
888
void setTorch (String trackId , boolean torch , Result result ) {
888
889
VideoCapturer videoCapturer = mVideoCapturers .get (trackId );
889
890
if (videoCapturer == null ) {
890
- result . error ( null , "Video capturer not found for id: " + trackId , null );
891
+ resultError ( "setTorch" , "Video capturer not found for id: " + trackId , result );
891
892
return ;
892
893
}
893
894
@@ -919,8 +920,7 @@ void setTorch(String trackId, boolean torch, Result result) {
919
920
(Handler ) getPrivateProperty (session .getClass (), session , "cameraThreadHandler" );
920
921
} catch (NoSuchFieldWithNameException e ) {
921
922
// Most likely the upstream Camera2Capturer class have changed
922
- Log .e (TAG , "[TORCH] Failed to get `" + e .fieldName + "` from `" + e .className + "`" );
923
- result .error (null , "Failed to get `" + e .fieldName + "` from `" + e .className + "`" , null );
923
+ resultError ("setTorch" , "[TORCH] Failed to get `" + e .fieldName + "` from `" + e .className + "`" , result );
924
924
return ;
925
925
}
926
926
@@ -959,8 +959,7 @@ void setTorch(String trackId, boolean torch, Result result) {
959
959
camera = (Camera ) getPrivateProperty (session .getClass (), session , "camera" );
960
960
} catch (NoSuchFieldWithNameException e ) {
961
961
// Most likely the upstream Camera1Capturer class have changed
962
- Log .e (TAG , "[TORCH] Failed to get `" + e .fieldName + "` from `" + e .className + "`" );
963
- result .error (null , "Failed to get `" + e .fieldName + "` from `" + e .className + "`" , null );
962
+ resultError ("setTorch" , "[TORCH] Failed to get `" + e .fieldName + "` from `" + e .className + "`" , result );
964
963
return ;
965
964
}
966
965
@@ -972,9 +971,7 @@ void setTorch(String trackId, boolean torch, Result result) {
972
971
result .success (null );
973
972
return ;
974
973
}
975
-
976
- Log .e (TAG , "[TORCH] Video capturer not compatible" );
977
- result .error (null , "Video capturer not compatible" , null );
974
+ resultError ("setTorch" , "[TORCH] Video capturer not compatible" , result );
978
975
}
979
976
980
977
private Object getPrivateProperty (Class klass , Object object , String fieldName )
0 commit comments