Explorar el Código

Remove a repetition of browser type checks

Depending on the type of browser within which the library is executing,
we take the decision how many times to call getUserMedia (e.g. once for
audio and once for video on Firefox). Upon getting a result of the
call, we used to perform similar browser type checks. I see this as
repetition of logic which makes it difficult to add new browser types
(e.g. React Native). Try to examine the result of the call to
getUserMedia and thus avoid re-checkign the browser type.
dev1
Lyubomir Marinov hace 9 años
padre
commit
30772c81a2
Se han modificado 1 ficheros con 25 adiciones y 21 borrados
  1. 25
    21
      modules/RTC/RTCUtils.js

+ 25
- 21
modules/RTC/RTCUtils.js Ver fichero

467
  */
467
  */
468
 function handleLocalStream(streams, resolution) {
468
 function handleLocalStream(streams, resolution) {
469
     var audioStream, videoStream, desktopStream, res = [];
469
     var audioStream, videoStream, desktopStream, res = [];
470
-    // If this is FF, the stream parameter is *not* a MediaStream object, it's
471
-    // an object with two properties: audioStream, videoStream.
472
-    if (window.webkitMediaStream) {
470
+
471
+    // XXX The function obtainAudioAndVideoPermissions has examined the type of
472
+    // the browser, its capabilities, etc. and has taken the decision whether to
473
+    // invoke getUserMedia per device (e.g. Firefox) or once for both audio and
474
+    // video (e.g. Chrome). In order to not duplicate the logic here, examine
475
+    // the specified streams and figure out what we've received based on
476
+    // obtainAudioAndVideoPermissions' decision.
477
+    if (streams) {
478
+        // As mentioned above, certian types of browser (e.g. Chrome) support
479
+        // (with a result which meets our requirements expressed bellow) calling
480
+        // getUserMedia once for both audio and video.
473
         var audioVideo = streams.audioVideo;
481
         var audioVideo = streams.audioVideo;
474
         if (audioVideo) {
482
         if (audioVideo) {
475
             var audioTracks = audioVideo.getAudioTracks();
483
             var audioTracks = audioVideo.getAudioTracks();
487
                     videoStream.addTrack(videoTracks[j]);
495
                     videoStream.addTrack(videoTracks[j]);
488
                 }
496
                 }
489
             }
497
             }
498
+        } else {
499
+          // On other types of browser (e.g. Firefox) we choose (namely,
500
+          // obtainAudioAndVideoPermissions) to call getUsermedia per device
501
+          // (type).
502
+          audioStream = streams.audio;
503
+          videoStream = streams.video;
490
         }
504
         }
491
-
492
-        // FIXME Checking streams here is unnecessary because there's
493
-        // streams.audioVideo above.
494
-        if (streams)
495
-            desktopStream = streams.desktopStream;
496
-
497
-    }
498
-    else if (RTCBrowserType.isFirefox() || RTCBrowserType.isTemasysPluginUsed()) {   // Firefox and Temasys plugin
499
-        if (streams) {
500
-            audioStream = streams.audio;
501
-            videoStream = streams.video;
502
-            desktopStream = streams.desktop;
503
-        }
505
+        // Again, different choices on different types of browser.
506
+        desktopStream = streams.desktopStream || streams.desktop;
504
     }
507
     }
505
 
508
 
506
-    if (desktopStream)
509
+    if (desktopStream) {
507
         res.push({
510
         res.push({
508
             stream: desktopStream,
511
             stream: desktopStream,
509
             track: desktopStream.getVideoTracks()[0],
512
             track: desktopStream.getVideoTracks()[0],
510
             mediaType: MediaType.VIDEO,
513
             mediaType: MediaType.VIDEO,
511
             videoType: VideoType.DESKTOP
514
             videoType: VideoType.DESKTOP
512
         });
515
         });
513
-
514
-    if(audioStream)
516
+    }
517
+    if (audioStream) {
515
         res.push({
518
         res.push({
516
             stream: audioStream,
519
             stream: audioStream,
517
             track: audioStream.getAudioTracks()[0],
520
             track: audioStream.getAudioTracks()[0],
518
             mediaType: MediaType.AUDIO,
521
             mediaType: MediaType.AUDIO,
519
             videoType: null
522
             videoType: null
520
         });
523
         });
521
-
522
-    if(videoStream)
524
+    }
525
+    if (videoStream) {
523
         res.push({
526
         res.push({
524
             stream: videoStream,
527
             stream: videoStream,
525
             track: videoStream.getVideoTracks()[0],
528
             track: videoStream.getVideoTracks()[0],
527
             videoType: VideoType.CAMERA,
530
             videoType: VideoType.CAMERA,
528
             resolution: resolution
531
             resolution: resolution
529
         });
532
         });
533
+    }
530
 
534
 
531
     return res;
535
     return res;
532
 }
536
 }

Loading…
Cancelar
Guardar