Bug 1168788 - Check for devices should check for audio or video not just audio. r=mikedeboer
authorMark Banner <standard8@mozilla.com>
Wed, 27 May 2015 13:47:56 +0100
changeset 246004 276bef47549224c2e86de2ded7bd5665576823b2
parent 246003 cb827b44f564a552e4973dc3adf38ae812cefdd6
child 246005 622af20a746a5030dffa04bb741856cff5464e56
push id60333
push userryanvm@gmail.com
push dateThu, 28 May 2015 14:20:47 +0000
treeherdermozilla-inbound@8225a3b75df6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1168788
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1168788 - Check for devices should check for audio or video not just audio. r=mikedeboer
browser/components/loop/content/shared/js/activeRoomStore.js
browser/components/loop/content/shared/js/utils.js
browser/components/loop/test/shared/activeRoomStore_test.js
browser/components/loop/test/shared/utils_test.js
--- a/browser/components/loop/content/shared/js/activeRoomStore.js
+++ b/browser/components/loop/content/shared/js/activeRoomStore.js
@@ -430,17 +430,17 @@ loop.store.ActiveRoomStore = (function()
       // Reset the failure reason if necessary.
       if (this.getStoreState().failureReason) {
         this.setStoreState({failureReason: undefined});
       }
 
       // XXX Ideally we'd do this check before joining a room, but we're waiting
       // for the UX for that. See bug 1166824. In the meantime this gives us
       // additional information for analysis.
-      loop.shared.utils.hasAudioDevices(function(hasAudio) {
+      loop.shared.utils.hasAudioOrVideoDevices(function(hasAudio) {
         if (hasAudio) {
           // MEDIA_WAIT causes the views to dispatch sharedActions.SetupStreamElements,
           // which in turn starts the sdk obtaining the device permission.
           this.setStoreState({roomState: ROOM_STATES.MEDIA_WAIT});
         } else {
           this.dispatchAction(new sharedActions.ConnectionFailure({
             reason: FAILURE_DETAILS.NO_MEDIA
           }));
--- a/browser/components/loop/content/shared/js/utils.js
+++ b/browser/components/loop/content/shared/js/utils.js
@@ -307,34 +307,34 @@ var inChrome = typeof Components != "und
   };
 
   /**
    * Determines if the user has any audio devices installed.
    *
    * @param  {Function} callback Called with a boolean which is true if there
    *                             are audio devices present.
    */
-  function hasAudioDevices(callback) {
+  function hasAudioOrVideoDevices(callback) {
     // mediaDevices is the official API for the spec.
     if ("mediaDevices" in rootNavigator) {
       rootNavigator.mediaDevices.enumerateDevices().then(function(result) {
         function checkForInput(device) {
-          return device.kind === "audioinput";
+          return device.kind === "audioinput" || device.kind === "videoinput";
         }
 
         callback(result.some(checkForInput));
       }).catch(function() {
         callback(false);
       });
     // MediaStreamTrack is the older version of the API, implemented originally
     // by Google Chrome.
     } else if ("MediaStreamTrack" in rootObject) {
       rootObject.MediaStreamTrack.getSources(function(result) {
         function checkForInput(device) {
-          return device.kind === "audio";
+          return device.kind === "audio" || device.kind === "video";
         }
 
         callback(result.some(checkForInput));
       });
     } else {
       // We don't know, so assume true.
       callback(true);
     }
@@ -740,17 +740,17 @@ var inChrome = typeof Components != "und
     getOS: getOS,
     getOSVersion: getOSVersion,
     getPlatform: getPlatform,
     isChrome: isChrome,
     isFirefox: isFirefox,
     isFirefoxOS: isFirefoxOS,
     isOpera: isOpera,
     getUnsupportedPlatform: getUnsupportedPlatform,
-    hasAudioDevices: hasAudioDevices,
+    hasAudioOrVideoDevices: hasAudioOrVideoDevices,
     locationData: locationData,
     atob: atob,
     btoa: btoa,
     strToUint8Array: strToUint8Array,
     Uint8ArrayToStr: Uint8ArrayToStr,
     objectDiff: objectDiff,
     stripFalsyValues: stripFalsyValues
   };
--- a/browser/components/loop/test/shared/activeRoomStore_test.js
+++ b/browser/components/loop/test/shared/activeRoomStore_test.js
@@ -635,33 +635,33 @@ describe("loop.store.ActiveRoomStore", f
       store.setStoreState({failureReason: "Test"});
 
       store.joinRoom();
 
       expect(store.getStoreState().failureReason).eql(undefined);
     });
 
     it("should set the state to MEDIA_WAIT if media devices are present", function() {
-      sandbox.stub(loop.shared.utils, "hasAudioDevices").callsArgWith(0, true);
+      sandbox.stub(loop.shared.utils, "hasAudioOrVideoDevices").callsArgWith(0, true);
 
       store.joinRoom();
 
       expect(store.getStoreState().roomState).eql(ROOM_STATES.MEDIA_WAIT);
     });
 
     it("should not set the state to MEDIA_WAIT if no media devices are present", function() {
-      sandbox.stub(loop.shared.utils, "hasAudioDevices").callsArgWith(0, false);
+      sandbox.stub(loop.shared.utils, "hasAudioOrVideoDevices").callsArgWith(0, false);
 
       store.joinRoom();
 
       expect(store.getStoreState().roomState).eql(ROOM_STATES.READY);
     });
 
     it("should dispatch `ConnectionFailure` if no media devices are present", function() {
-      sandbox.stub(loop.shared.utils, "hasAudioDevices").callsArgWith(0, false);
+      sandbox.stub(loop.shared.utils, "hasAudioOrVideoDevices").callsArgWith(0, false);
 
       store.joinRoom();
 
       sinon.assert.calledOnce(dispatcher.dispatch);
       sinon.assert.calledWithExactly(dispatcher.dispatch,
         new sharedActions.ConnectionFailure({
           reason: FAILURE_DETAILS.NO_MEDIA
         }));
--- a/browser/components/loop/test/shared/utils_test.js
+++ b/browser/components/loop/test/shared/utils_test.js
@@ -136,17 +136,17 @@ describe("loop.shared.utils", function()
       it("should return the localStorage value", function() {
         localStorage.setItem("test.true", true);
 
         expect(sharedUtils.getBoolPreference("test.true")).eql(true);
       });
     });
   });
 
-  describe("hasAudioDevices", function() {
+  describe("#hasAudioOrVideoDevices", function() {
     var fakeNavigatorObject, fakeWindowObject;
 
     beforeEach(function() {
       fakeNavigatorObject = {
         mediaDevices: {
           enumerateDevices: sinon.stub()
         }
       };
@@ -163,93 +163,126 @@ describe("loop.shared.utils", function()
     afterEach(function() {
       sharedUtils.setRootObjects();
     });
 
     it("should return true if no APIs to detect devices exist", function(done) {
       delete fakeNavigatorObject.mediaDevices;
       delete fakeWindowObject.MediaStreamTrack;
 
-      sharedUtils.hasAudioDevices(function(result) {
+      sharedUtils.hasAudioOrVideoDevices(function(result) {
         expect(result).eql(true);
         done();
       });
     });
 
-    it("should return false if no audio devices exist according to navigator.mediaDevices", function(done) {
+    it("should return false if no audio nor video devices exist according to navigator.mediaDevices", function(done) {
       delete fakeWindowObject.MediaStreamTrack;
 
       fakeNavigatorObject.mediaDevices.enumerateDevices.returns(Promise.resolve([]));
-      sharedUtils.hasAudioDevices(function(result) {
+
+      sharedUtils.hasAudioOrVideoDevices(function(result) {
         try {
           expect(result).eql(false);
           done();
         } catch (ex) {
           done(ex);
         }
       });
     });
 
     it("should return true if audio devices exist according to navigator.mediaDevices", function(done) {
       delete fakeWindowObject.MediaStreamTrack;
 
       fakeNavigatorObject.mediaDevices.enumerateDevices.returns(
         Promise.resolve([{
-          deviceId: "15234",
-          groupId: "",
-          kind: "videoinput",
-          label: ""
-        }, {
           deviceId: "54321",
           groupId: "",
           kind: "audioinput",
           label: ""
         }])
       );
 
-      sharedUtils.hasAudioDevices(function(result) {
+      sharedUtils.hasAudioOrVideoDevices(function(result) {
         try {
           expect(result).eql(true);
           done();
         } catch (ex) {
           done(ex);
         }
       });
     });
 
-    it("should return false if no audio devices exist according to window.MediaStreamTrack", function(done) {
+    it("should return true if video devices exist according to navigator.mediaDevices", function(done) {
+      delete fakeWindowObject.MediaStreamTrack;
+
+      fakeNavigatorObject.mediaDevices.enumerateDevices.returns(
+        Promise.resolve([{
+          deviceId: "15234",
+          groupId: "",
+          kind: "videoinput",
+          label: ""
+        }])
+      );
+
+      sharedUtils.hasAudioOrVideoDevices(function(result) {
+        try {
+          expect(result).eql(true);
+          done();
+        } catch (ex) {
+          done(ex);
+        }
+      });
+    });
+
+    it("should return false if no audio nor video devices exist according to window.MediaStreamTrack", function(done) {
       delete fakeNavigatorObject.mediaDevices;
 
       fakeWindowObject.MediaStreamTrack.getSources.callsArgWith(0, []);
-      sharedUtils.hasAudioDevices(function(result) {
+      sharedUtils.hasAudioOrVideoDevices(function(result) {
         try {
           expect(result).eql(false);
           done();
         } catch (ex) {
           done(ex);
         }
       });
     });
 
     it("should return true if audio devices exist according to window.MediaStreamTrack", function(done) {
       delete fakeNavigatorObject.mediaDevices;
 
       fakeWindowObject.MediaStreamTrack.getSources.callsArgWith(0, [{
         facing: "",
-        id: "15234",
-        kind: "video",
-        label: ""
-      }, {
-        facing: "",
         id: "54321",
         kind: "audio",
         label: ""
       }]);
 
-      sharedUtils.hasAudioDevices(function(result) {
+      sharedUtils.hasAudioOrVideoDevices(function(result) {
+        try {
+          expect(result).eql(true);
+          done();
+        } catch (ex) {
+          done(ex);
+        }
+      });
+    });
+
+    it("should return true if video devices exist according to window.MediaStreamTrack", function(done) {
+      delete fakeNavigatorObject.mediaDevices;
+
+      fakeWindowObject.MediaStreamTrack.getSources.callsArgWith(0, [{
+        facing: "",
+        id: "15234",
+        kind: "video",
+        label: ""
+      }]);
+
+      sharedUtils.hasAudioOrVideoDevices(function(result) {
         try {
           expect(result).eql(true);
           done();
         } catch (ex) {
           done(ex);
         }
       });
     });