diff --git a/browser/components/loop/content/shared/js/activeRoomStore.js b/browser/components/loop/content/shared/js/activeRoomStore.js index b126ec2f0fb0..2ac93cff584b 100644 --- a/browser/components/loop/content/shared/js/activeRoomStore.js +++ b/browser/components/loop/content/shared/js/activeRoomStore.js @@ -435,7 +435,7 @@ loop.store.ActiveRoomStore = (function() { // 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. diff --git a/browser/components/loop/content/shared/js/utils.js b/browser/components/loop/content/shared/js/utils.js index 624bc4294097..130d5557690c 100644 --- a/browser/components/loop/content/shared/js/utils.js +++ b/browser/components/loop/content/shared/js/utils.js @@ -312,12 +312,12 @@ var inChrome = typeof Components != "undefined" && "utils" in Components; * @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)); @@ -329,7 +329,7 @@ var inChrome = typeof Components != "undefined" && "utils" in Components; } 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)); @@ -745,7 +745,7 @@ var inChrome = typeof Components != "undefined" && "utils" in Components; isFirefoxOS: isFirefoxOS, isOpera: isOpera, getUnsupportedPlatform: getUnsupportedPlatform, - hasAudioDevices: hasAudioDevices, + hasAudioOrVideoDevices: hasAudioOrVideoDevices, locationData: locationData, atob: atob, btoa: btoa, diff --git a/browser/components/loop/test/shared/activeRoomStore_test.js b/browser/components/loop/test/shared/activeRoomStore_test.js index daca85ace42a..b168e43afb53 100644 --- a/browser/components/loop/test/shared/activeRoomStore_test.js +++ b/browser/components/loop/test/shared/activeRoomStore_test.js @@ -640,7 +640,7 @@ describe("loop.store.ActiveRoomStore", function () { }); 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(); @@ -648,7 +648,7 @@ describe("loop.store.ActiveRoomStore", function () { }); 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(); @@ -656,7 +656,7 @@ describe("loop.store.ActiveRoomStore", function () { }); 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(); diff --git a/browser/components/loop/test/shared/utils_test.js b/browser/components/loop/test/shared/utils_test.js index ad94a0e8b6cf..70142b4d7dd8 100644 --- a/browser/components/loop/test/shared/utils_test.js +++ b/browser/components/loop/test/shared/utils_test.js @@ -141,7 +141,7 @@ describe("loop.shared.utils", function() { }); }); - describe("hasAudioDevices", function() { + describe("#hasAudioOrVideoDevices", function() { var fakeNavigatorObject, fakeWindowObject; beforeEach(function() { @@ -168,17 +168,18 @@ describe("loop.shared.utils", function() { 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(); @@ -193,11 +194,6 @@ describe("loop.shared.utils", function() { fakeNavigatorObject.mediaDevices.enumerateDevices.returns( Promise.resolve([{ - deviceId: "15234", - groupId: "", - kind: "videoinput", - label: "" - }, { deviceId: "54321", groupId: "", kind: "audioinput", @@ -205,7 +201,7 @@ describe("loop.shared.utils", function() { }]) ); - sharedUtils.hasAudioDevices(function(result) { + sharedUtils.hasAudioOrVideoDevices(function(result) { try { expect(result).eql(true); done(); @@ -215,11 +211,33 @@ describe("loop.shared.utils", function() { }); }); - 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(); @@ -233,18 +251,33 @@ describe("loop.shared.utils", function() { 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();