Browse Source

Fixes the availableDevices.

Fixes the availableDevices, to reflect the devices for which we succeeded or failed to obtain stream.
master
damencho 9 years ago
parent
commit
991e4b6c7a
1 changed files with 19 additions and 10 deletions
  1. 19
    10
      modules/RTC/RTCUtils.js

+ 19
- 10
modules/RTC/RTCUtils.js View File

295
     return constraints;
295
     return constraints;
296
 }
296
 }
297
 
297
 
298
-function setAvailableDevices(um, available) {
298
+/**
299
+ * Sets the availbale devices based on the options we requested and the
300
+ * streams we received.
301
+ * @param um the options we requested to getUserMedia.
302
+ * @param stream the stream we received from calling getUserMedia.
303
+ */
304
+function setAvailableDevices(um, stream) {
305
+    var audioTracksReceived = !!stream.getAudioTracks().length;
306
+    var videoTracksReceived = !!stream.getVideoTracks().length;
307
+
299
     if (um.indexOf("video") != -1) {
308
     if (um.indexOf("video") != -1) {
300
-        devices.video = available;
309
+        devices.video = videoTracksReceived;
301
     }
310
     }
302
     if (um.indexOf("audio") != -1) {
311
     if (um.indexOf("audio") != -1) {
303
-        devices.audio = available;
312
+        devices.audio = audioTracksReceived;
304
     }
313
     }
305
 
314
 
306
     eventEmitter.emit(RTCEvents.AVAILABLE_DEVICES_CHANGED, devices);
315
     eventEmitter.emit(RTCEvents.AVAILABLE_DEVICES_CHANGED, devices);
361
  * @param {MediaDeviceInfo[]} devices - list of media devices.
370
  * @param {MediaDeviceInfo[]} devices - list of media devices.
362
  * @emits RTCEvents.DEVICE_LIST_CHANGED
371
  * @emits RTCEvents.DEVICE_LIST_CHANGED
363
  */
372
  */
364
-function onMediaDevicesListChanged(devices) {
365
-    currentlyAvailableMediaDevices = devices.slice(0);
373
+function onMediaDevicesListChanged(devicesReceived) {
374
+    currentlyAvailableMediaDevices = devicesReceived.slice(0);
366
     logger.info('list of media devices has changed:', currentlyAvailableMediaDevices);
375
     logger.info('list of media devices has changed:', currentlyAvailableMediaDevices);
367
 
376
 
368
     var videoInputDevices = currentlyAvailableMediaDevices.filter(function (d) {
377
     var videoInputDevices = currentlyAvailableMediaDevices.filter(function (d) {
382
 
391
 
383
     if (videoInputDevices.length &&
392
     if (videoInputDevices.length &&
384
         videoInputDevices.length === videoInputDevicesWithEmptyLabels.length) {
393
         videoInputDevices.length === videoInputDevicesWithEmptyLabels.length) {
385
-        setAvailableDevices(['video'], false);
394
+        devices.video = false;
386
     }
395
     }
387
 
396
 
388
     if (audioInputDevices.length &&
397
     if (audioInputDevices.length &&
389
         audioInputDevices.length === audioInputDevicesWithEmptyLabels.length) {
398
         audioInputDevices.length === audioInputDevicesWithEmptyLabels.length) {
390
-        setAvailableDevices(['audio'], false);
399
+        devices.audio = false;
391
     }
400
     }
392
 
401
 
393
-    eventEmitter.emit(RTCEvents.DEVICE_LIST_CHANGED, devices);
402
+    eventEmitter.emit(RTCEvents.DEVICE_LIST_CHANGED, devicesReceived);
394
 }
403
 }
395
 
404
 
396
 // In case of IE we continue from 'onReady' callback
405
 // In case of IE we continue from 'onReady' callback
905
             this.getUserMedia(constraints,
914
             this.getUserMedia(constraints,
906
                 function (stream) {
915
                 function (stream) {
907
                     logger.log('onUserMediaSuccess');
916
                     logger.log('onUserMediaSuccess');
908
-                    setAvailableDevices(um, true);
917
+                    setAvailableDevices(um, stream);
909
                     success_callback(stream);
918
                     success_callback(stream);
910
                 },
919
                 },
911
                 function (error) {
920
                 function (error) {
912
-                    setAvailableDevices(um, false);
921
+                    setAvailableDevices(um, stream);
913
                     logger.warn('Failed to get access to local media. Error ',
922
                     logger.warn('Failed to get access to local media. Error ',
914
                         error, constraints);
923
                         error, constraints);
915
 
924
 

Loading…
Cancel
Save