Browse Source

Attempts to fix #258

j8
George Politis 10 years ago
parent
commit
2c9d0606c3
1 changed files with 60 additions and 18 deletions
  1. 60
    18
      modules/RTC/RTCUtils.js

+ 60
- 18
modules/RTC/RTCUtils.js View File

@@ -333,7 +333,43 @@ RTCUtils.prototype.obtainAudioAndVideoPermissions = function(devices, callback,
333 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 373
         newDevices,
338 374
         function (stream) {
339 375
             successCallback(stream);
@@ -342,10 +378,14 @@ RTCUtils.prototype.obtainAudioAndVideoPermissions = function(devices, callback,
342 378
             self.errorCallback(error);
343 379
         },
344 380
         config.resolution || '360');
381
+    }
382
+
345 383
 }
346 384
 
347 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 389
         console.log('got', stream, stream.getAudioTracks().length,
350 390
             stream.getVideoTracks().length);
351 391
     this.handleLocalStream(stream, usageOptions);
@@ -388,10 +428,13 @@ RTCUtils.prototype.errorCallback = function (error) {
388 428
 
389 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 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 438
         if(stream) {
396 439
             var audioTracks = stream.getAudioTracks();
397 440
 
@@ -405,25 +448,24 @@ RTCUtils.prototype.handleLocalStream = function(stream, usageOptions)
405 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 452
     else
423 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 471
 RTCUtils.prototype.createStream = function(stream, isVideo)

Loading…
Cancel
Save