@@ -96,7 +96,7 @@ private void checkSelfPermissions(boolean requestPermissions) {
96
96
if (resultCode != Activity .RESULT_OK ) {
97
97
Activity activity = this .getActivity ();
98
98
Bundle args = getArguments ();
99
- resultReceiver = ( ResultReceiver ) args .getParcelable (RESULT_RECEIVER );
99
+ resultReceiver = args .getParcelable (RESULT_RECEIVER );
100
100
requestCode = args .getInt (REQUEST_CODE );
101
101
requestStart (activity , requestCode );
102
102
}
@@ -151,7 +151,6 @@ private void finish() {
151
151
@ Override
152
152
public void onResume () {
153
153
super .onResume ();
154
-
155
154
checkSelfPermissions (/* requestPermissions */ true );
156
155
}
157
156
}
@@ -326,123 +325,8 @@ void getUserMedia(
326
325
}
327
326
}
328
327
329
- boolean requestScreenCapturer = videoConstraintsMandatory != null &&
330
- videoConstraintsMandatory .hasKey ("chromeMediaSource" ) &&
331
- videoConstraintsMandatory .getString ("chromeMediaSource" ).equals ("desktop" );
332
-
333
328
final ArrayList <String > requestPermissions = new ArrayList <>();
334
329
335
- if (requestScreenCapturer )
336
- {
337
- final ConstraintsMap videoConstraintsMandatory2 = videoConstraintsMandatory ;
338
- screenRequestPremissions (new ResultReceiver (new Handler (Looper .getMainLooper ())) {
339
- @ Override
340
- protected void onReceiveResult (
341
- int requestCode ,
342
- Bundle resultData ) {
343
-
344
- /*Create ScreenCapture*/
345
- int resultCode = resultData .getInt (GRANT_RESULTS );
346
- Intent mediaProjectionData = resultData .getParcelable (PROJECTION_DATA );
347
-
348
- if (resultCode != Activity .RESULT_OK ) {
349
- result .error ( null ,
350
- "User didn't give permission to capture the screen." , null );
351
- return ;
352
- }
353
-
354
- MediaStreamTrack [] tracks = new MediaStreamTrack [1 ];
355
- VideoCapturer videoCapturer = null ;
356
- videoCapturer = new ScreenCapturerAndroid (
357
- mediaProjectionData , new MediaProjection .Callback () {
358
- @ Override
359
- public void onStop () {
360
- Log .e (TAG , "User revoked permission to capture the screen." );
361
- result .error ( null ,
362
- "User revoked permission to capture the screen." , null );
363
- }
364
- });
365
-
366
- if (videoCapturer != null ) {
367
-
368
- PeerConnectionFactory pcFactory = plugin .mFactory ;
369
- VideoSource videoSource = pcFactory .createVideoSource (true );
370
-
371
- // Fall back to defaults if keys are missing.
372
- int width
373
- = videoConstraintsMandatory2 .hasKey ("minWidth" )
374
- ? videoConstraintsMandatory2 .getInt ("minWidth" )
375
- : DEFAULT_WIDTH ;
376
- int height
377
- = videoConstraintsMandatory2 .hasKey ("minHeight" )
378
- ? videoConstraintsMandatory2 .getInt ("minHeight" )
379
- : DEFAULT_HEIGHT ;
380
- int fps
381
- = videoConstraintsMandatory2 .hasKey ("minFrameRate" )
382
- ? videoConstraintsMandatory2 .getInt ("minFrameRate" )
383
- : DEFAULT_FPS ;
384
-
385
- videoCapturer .startCapture (width , height , fps );
386
-
387
- String trackId = plugin .getNextTrackUUID ();
388
- mVideoCapturers .put (trackId , videoCapturer );
389
-
390
- Log .d (TAG , "changeCaptureFormat: " + width + "x" + height + "@" + fps );
391
- videoSource .adaptOutputFormat (width , height , fps );
392
-
393
- tracks [0 ] = pcFactory .createVideoTrack (trackId , videoSource );
394
-
395
- ConstraintsArray audioTracks = new ConstraintsArray ();
396
- ConstraintsArray videoTracks = new ConstraintsArray ();
397
- ConstraintsMap successResult = new ConstraintsMap ();
398
-
399
- for (MediaStreamTrack track : tracks ) {
400
- if (track == null ) {
401
- continue ;
402
- }
403
-
404
- String id = track .id ();
405
-
406
- if (track instanceof AudioTrack ) {
407
- mediaStream .addTrack ((AudioTrack ) track );
408
- } else {
409
- mediaStream .addTrack ((VideoTrack ) track );
410
- }
411
- plugin .localTracks .put (id , track );
412
-
413
- ConstraintsMap track_ = new ConstraintsMap ();
414
- String kind = track .kind ();
415
-
416
- track_ .putBoolean ("enabled" , track .enabled ());
417
- track_ .putString ("id" , id );
418
- track_ .putString ("kind" , kind );
419
- track_ .putString ("label" , kind );
420
- track_ .putString ("readyState" , track .state ().toString ());
421
- track_ .putBoolean ("remote" , false );
422
-
423
- if (track instanceof AudioTrack ) {
424
- audioTracks .pushMap (track_ );
425
- } else {
426
- videoTracks .pushMap (track_ );
427
- }
428
- }
429
-
430
- String streamId = mediaStream .getId ();
431
-
432
- Log .d (TAG , "MediaStream id: " + streamId );
433
- plugin .localStreams .put (streamId , mediaStream );
434
-
435
- successResult .putString ("streamId" , streamId );
436
- successResult .putArray ("audioTracks" , audioTracks .toArrayList ());
437
- successResult .putArray ("videoTracks" , audioTracks .toArrayList ());
438
- result .success (successResult .toMap ());
439
- }
440
-
441
- }
442
- });
443
- return ;
444
- }
445
-
446
330
if (constraints .hasKey ("audio" )) {
447
331
switch (constraints .getType ("audio" )) {
448
332
case Boolean :
@@ -458,7 +342,7 @@ public void onStop() {
458
342
}
459
343
}
460
344
461
- if (constraints .hasKey ("video" ) && ! requestScreenCapturer ) {
345
+ if (constraints .hasKey ("video" )) {
462
346
switch (constraints .getType ("video" )) {
463
347
case Boolean :
464
348
if (constraints .getBoolean ("video" )) {
@@ -513,6 +397,134 @@ public void invoke(Object... args) {
513
397
);
514
398
}
515
399
400
+ void getDisplayMedia (
401
+ final ConstraintsMap constraints ,
402
+ final Result result ,
403
+ final MediaStream mediaStream ) {
404
+ ConstraintsMap videoConstraintsMap = null ;
405
+ ConstraintsMap videoConstraintsMandatory = null ;
406
+
407
+ if (constraints .getType ("video" ) == ObjectType .Map ) {
408
+ videoConstraintsMap = constraints .getMap ("video" );
409
+ if (videoConstraintsMap .hasKey ("mandatory" )
410
+ && videoConstraintsMap .getType ("mandatory" )
411
+ == ObjectType .Map ) {
412
+ videoConstraintsMandatory
413
+ = videoConstraintsMap .getMap ("mandatory" );
414
+ }
415
+ }
416
+
417
+ final ConstraintsMap videoConstraintsMandatory2 = videoConstraintsMandatory ;
418
+ screenRequestPremissions (new ResultReceiver (new Handler (Looper .getMainLooper ())) {
419
+ @ Override
420
+ protected void onReceiveResult (
421
+ int requestCode ,
422
+ Bundle resultData ) {
423
+
424
+ /* Create ScreenCapture */
425
+ int resultCode = resultData .getInt (GRANT_RESULTS );
426
+ Intent mediaProjectionData = resultData .getParcelable (PROJECTION_DATA );
427
+
428
+ if (resultCode != Activity .RESULT_OK ) {
429
+ result .error (null , "User didn't give permission to capture the screen." , null );
430
+ return ;
431
+ }
432
+
433
+ MediaStreamTrack [] tracks = new MediaStreamTrack [1 ];
434
+ VideoCapturer videoCapturer = null ;
435
+ videoCapturer = new ScreenCapturerAndroid (mediaProjectionData , new MediaProjection .Callback () {
436
+ @ Override
437
+ public void onStop () {
438
+ Log .e (TAG , "User revoked permission to capture the screen." );
439
+ result .error (null , "User revoked permission to capture the screen." , null );
440
+ }
441
+ });
442
+ if (videoCapturer != null ) {
443
+ PeerConnectionFactory pcFactory = plugin .mFactory ;
444
+ VideoSource videoSource = pcFactory .createVideoSource (true );
445
+
446
+ Context context = plugin .getContext ();
447
+ String threadName = Thread .currentThread ().getName ();
448
+ SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper .create (threadName , EglUtils .getRootEglBaseContext ());
449
+ videoCapturer .initialize (surfaceTextureHelper , context , videoSource .getCapturerObserver ());
450
+
451
+
452
+ // Fall back to defaults if keys are missing.
453
+ int width
454
+ = videoConstraintsMandatory2 .hasKey ("minWidth" )
455
+ ? videoConstraintsMandatory2 .getInt ("minWidth" )
456
+ : DEFAULT_WIDTH ;
457
+ int height
458
+ = videoConstraintsMandatory2 .hasKey ("minHeight" )
459
+ ? videoConstraintsMandatory2 .getInt ("minHeight" )
460
+ : DEFAULT_HEIGHT ;
461
+ int fps
462
+ = videoConstraintsMandatory2 .hasKey ("minFrameRate" )
463
+ ? videoConstraintsMandatory2 .getInt ("minFrameRate" )
464
+ : DEFAULT_FPS ;
465
+
466
+ videoCapturer .startCapture (width , height , fps );
467
+
468
+ String trackId = plugin .getNextTrackUUID ();
469
+ mVideoCapturers .put (trackId , videoCapturer );
470
+
471
+ Log .d (TAG , "changeCaptureFormat: " + width + "x" + height + "@" + fps );
472
+ videoSource .adaptOutputFormat (width , height , fps );
473
+
474
+ tracks [0 ] = pcFactory .createVideoTrack (trackId , videoSource );
475
+
476
+ ConstraintsArray audioTracks = new ConstraintsArray ();
477
+ ConstraintsArray videoTracks = new ConstraintsArray ();
478
+ ConstraintsMap successResult = new ConstraintsMap ();
479
+
480
+ for (MediaStreamTrack track : tracks ) {
481
+ if (track == null ) {
482
+ continue ;
483
+ }
484
+
485
+ String id = track .id ();
486
+
487
+ if (track instanceof AudioTrack ) {
488
+ mediaStream .addTrack ((AudioTrack ) track );
489
+ } else {
490
+ mediaStream .addTrack ((VideoTrack ) track );
491
+ }
492
+ plugin .localTracks .put (id , track );
493
+
494
+ ConstraintsMap track_ = new ConstraintsMap ();
495
+ String kind = track .kind ();
496
+
497
+ track_ .putBoolean ("enabled" , track .enabled ());
498
+ track_ .putString ("id" , id );
499
+ track_ .putString ("kind" , kind );
500
+ track_ .putString ("label" , kind );
501
+ track_ .putString ("readyState" , track .state ().toString ());
502
+ track_ .putBoolean ("remote" , false );
503
+
504
+ if (track instanceof AudioTrack ) {
505
+ audioTracks .pushMap (track_ );
506
+ } else {
507
+ videoTracks .pushMap (track_ );
508
+ }
509
+ }
510
+
511
+ String streamId = mediaStream .getId ();
512
+
513
+ Log .d (TAG , "MediaStream id: " + streamId );
514
+ plugin .localStreams .put (streamId , mediaStream );
515
+ successResult .putString ("streamId" , streamId );
516
+ successResult .putArray ("audioTracks" , audioTracks .toArrayList ());
517
+ successResult .putArray ("videoTracks" , audioTracks .toArrayList ());
518
+ result .success (successResult .toMap ());
519
+ }else {
520
+ result .error (
521
+ /* type */ "GetDisplayMediaFailed" ,
522
+ "Failed to create new VideoCapturer!" , null );
523
+ }
524
+ }
525
+ });
526
+ }
527
+
516
528
/**
517
529
* Implements {@code getUserMedia} with the knowledge that the necessary
518
530
* permissions have already been granted. If the necessary permissions have
0 commit comments