Przeglądaj źródła

Attempts to fix #258

j8
George Politis 10 lat temu
rodzic
commit
2c9d0606c3
1 zmienionych plików z 60 dodań i 18 usunięć
  1. 60
    18
      modules/RTC/RTCUtils.js

+ 60
- 18
modules/RTC/RTCUtils.js Wyświetl plik

333
         return;
333
         return;
334
     }
334
     }
335
 
335
 
336
-    this.getUserMediaWithConstraints(
336
+    if (navigator.mozGetUserMedia) {
337
+
338
+        // With FF we can't split the stream into audio and video because FF
339
+        // doesn't support media stream constructors. So, we need to get the
340
+        // audio stream separately from the video stream using two distinct GUM
341
+        // calls. Not very user friendly :-( but we don't have many other
342
+        // options neither.
343
+        //
344
+        // Note that we pack those 2 streams in a single object and pass it to
345
+        // the successCallback method.
346
+
347
+        self.getUserMediaWithConstraints(
348
+            ['audio'],
349
+            function (audioStream) {
350
+                self.getUserMediaWithConstraints(
351
+                    ['video'],
352
+                    function (videoStream) {
353
+                        return self.successCallback({
354
+                            audioStream: audioStream,
355
+                            videoStream: videoStream
356
+                        });
357
+                    },
358
+                    function (error) {
359
+                        console.error('failed to obtain video stream - stop',
360
+                            error);
361
+                        return self.successCallback(null);
362
+                    },
363
+                    config.resolution || '360');
364
+            },
365
+            function (error) {
366
+                console.error('failed to obtain audio stream - stop',
367
+                        error);
368
+                return self.successCallback(null);
369
+            }
370
+        );
371
+    } else {
372
+        this.getUserMediaWithConstraints(
337
         newDevices,
373
         newDevices,
338
         function (stream) {
374
         function (stream) {
339
             successCallback(stream);
375
             successCallback(stream);
342
             self.errorCallback(error);
378
             self.errorCallback(error);
343
         },
379
         },
344
         config.resolution || '360');
380
         config.resolution || '360');
381
+    }
382
+
345
 }
383
 }
346
 
384
 
347
 RTCUtils.prototype.successCallback = function (stream, usageOptions) {
385
 RTCUtils.prototype.successCallback = function (stream, usageOptions) {
348
-    if(stream)
386
+    // If this is FF, the stream parameter is *not* a MediaStream object, it's
387
+    // an object with two properties: audioStream, videoStream.
388
+    if(stream && !navigator.mozGetUserMedia)
349
         console.log('got', stream, stream.getAudioTracks().length,
389
         console.log('got', stream, stream.getAudioTracks().length,
350
             stream.getVideoTracks().length);
390
             stream.getVideoTracks().length);
351
     this.handleLocalStream(stream, usageOptions);
391
     this.handleLocalStream(stream, usageOptions);
388
 
428
 
389
 RTCUtils.prototype.handleLocalStream = function(stream, usageOptions)
429
 RTCUtils.prototype.handleLocalStream = function(stream, usageOptions)
390
 {
430
 {
431
+    // If this is FF, the stream parameter is *not* a MediaStream object, it's
432
+    // an object with two properties: audioStream, videoStream.
433
+    var audioStream, videoStream;
391
     if(window.webkitMediaStream)
434
     if(window.webkitMediaStream)
392
     {
435
     {
393
-        var audioStream = new webkitMediaStream();
394
-        var videoStream = new webkitMediaStream();
436
+        audioStream = new webkitMediaStream();
437
+        videoStream = new webkitMediaStream();
395
         if(stream) {
438
         if(stream) {
396
             var audioTracks = stream.getAudioTracks();
439
             var audioTracks = stream.getAudioTracks();
397
 
440
 
405
                 videoStream.addTrack(videoTracks[i]);
448
                 videoStream.addTrack(videoTracks[i]);
406
             }
449
             }
407
         }
450
         }
408
-
409
-        var audioMuted = (usageOptions && usageOptions.audio != 1),
410
-            videoMuted = (usageOptions && usageOptions.video != 1);
411
-
412
-        var audioGUM = (!usageOptions || usageOptions.audio != -1),
413
-            videoGUM = (!usageOptions || usageOptions.video != -1);
414
-
415
-
416
-        this.service.createLocalStream(audioStream, "audio", null, null,
417
-            audioMuted, audioGUM);
418
-
419
-        this.service.createLocalStream(videoStream, "video", null, null,
420
-            videoMuted, videoGUM);
421
     }
451
     }
422
     else
452
     else
423
     {//firefox
453
     {//firefox
424
-        this.service.createLocalStream(stream, "stream");
454
+        audioStream = stream.audioStream;
455
+        videoStream = stream.videoStream;
425
     }
456
     }
426
 
457
 
458
+    var audioMuted = (usageOptions && usageOptions.audio != 1),
459
+        videoMuted = (usageOptions && usageOptions.video != 1);
460
+
461
+    var audioGUM = (!usageOptions || usageOptions.audio != -1),
462
+        videoGUM = (!usageOptions || usageOptions.video != -1);
463
+
464
+    this.service.createLocalStream(audioStream, "audio", null, null,
465
+        audioMuted, audioGUM);
466
+
467
+    this.service.createLocalStream(videoStream, "video", null, null,
468
+        videoMuted, videoGUM);
427
 };
469
 };
428
 
470
 
429
 RTCUtils.prototype.createStream = function(stream, isVideo)
471
 RTCUtils.prototype.createStream = function(stream, isVideo)

Ładowanie…
Anuluj
Zapisz