Просмотр исходного кода

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 9 лет назад
Родитель
Сommit
30772c81a2
1 измененных файлов: 25 добавлений и 21 удалений
  1. 25
    21
      modules/RTC/RTCUtils.js

+ 25
- 21
modules/RTC/RTCUtils.js Просмотреть файл

@@ -467,9 +467,17 @@ function obtainDevices(options) {
467 467
  */
468 468
 function handleLocalStream(streams, resolution) {
469 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 481
         var audioVideo = streams.audioVideo;
474 482
         if (audioVideo) {
475 483
             var audioTracks = audioVideo.getAudioTracks();
@@ -487,39 +495,34 @@ function handleLocalStream(streams, resolution) {
487 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 510
         res.push({
508 511
             stream: desktopStream,
509 512
             track: desktopStream.getVideoTracks()[0],
510 513
             mediaType: MediaType.VIDEO,
511 514
             videoType: VideoType.DESKTOP
512 515
         });
513
-
514
-    if(audioStream)
516
+    }
517
+    if (audioStream) {
515 518
         res.push({
516 519
             stream: audioStream,
517 520
             track: audioStream.getAudioTracks()[0],
518 521
             mediaType: MediaType.AUDIO,
519 522
             videoType: null
520 523
         });
521
-
522
-    if(videoStream)
524
+    }
525
+    if (videoStream) {
523 526
         res.push({
524 527
             stream: videoStream,
525 528
             track: videoStream.getVideoTracks()[0],
@@ -527,6 +530,7 @@ function handleLocalStream(streams, resolution) {
527 530
             videoType: VideoType.CAMERA,
528 531
             resolution: resolution
529 532
         });
533
+    }
530 534
 
531 535
     return res;
532 536
 }

Загрузка…
Отмена
Сохранить