diff --git a/src/CallMediaHandler.js b/src/CallMediaHandler.js index 9133a6548d..4f82e003b9 100644 --- a/src/CallMediaHandler.js +++ b/src/CallMediaHandler.js @@ -26,6 +26,8 @@ export default { const audioIn = {}; const videoIn = {}; + if (devices.some((device) => !device.label)) return false; + devices.forEach((device) => { switch (device.kind) { case 'audioinput': audioIn[device.deviceId] = device.label; break; diff --git a/src/components/structures/LoggedInView.js b/src/components/structures/LoggedInView.js index a84661bcd2..1a7b7e06e4 100644 --- a/src/components/structures/LoggedInView.js +++ b/src/components/structures/LoggedInView.js @@ -72,9 +72,7 @@ export default React.createClass({ // RoomView.getScrollState() this._scrollStateMap = {}; - // Only run these in electron, at least until a better mechanism for perms exists - // https://w3c.github.io/permissions/#dom-permissionname-device-info - if (window && window.process && window.process.type) CallMediaHandler.loadDevices(); + CallMediaHandler.loadDevices(); document.addEventListener('keydown', this._onKeyDown); }, diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index de88566300..58c6bb7c20 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -178,17 +178,7 @@ module.exports = React.createClass({ }); } - q().then(() => { - return CallMediaHandler.getDevices(); - }).then((mediaDevices) => { - console.log("got mediaDevices", mediaDevices, this._unmounted); - if (this._unmounted) return; - this.setState({ - mediaDevices, - activeAudioInput: this._localSettings['webrtc_audioinput'] || 'default', - activeVideoInput: this._localSettings['webrtc_videoinput'] || 'default', - }); - }); + this._refreshMediaDevices(); // Bulk rejecting invites: // /sync won't have had time to return when UserSettings re-renders from state changes, so getRooms() @@ -210,8 +200,6 @@ module.exports = React.createClass({ this._syncedSettings = syncedSettings; this._localSettings = UserSettingsStore.getLocalSettings(); - this._setAudioInput = this._setAudioInput.bind(this); - this._setVideoInput = this._setVideoInput.bind(this); }, componentDidMount: function() { @@ -233,6 +221,20 @@ module.exports = React.createClass({ } }, + _refreshMediaDevices: function() { + q().then(() => { + return CallMediaHandler.getDevices(); + }).then((mediaDevices) => { + // console.log("got mediaDevices", mediaDevices, this._unmounted); + if (this._unmounted) return; + this.setState({ + mediaDevices, + activeAudioInput: this._localSettings['webrtc_audioinput'] || 'default', + activeVideoInput: this._localSettings['webrtc_videoinput'] || 'default', + }); + }); + }, + _refreshFromServer: function() { const self = this; q.all([ @@ -818,9 +820,29 @@ module.exports = React.createClass({ CallMediaHandler.setVideoInput(deviceId); }, + _requestMediaPermissions: function() { + console.log("Request media perms"); + const getUserMedia = ( + window.navigator.getUserMedia || window.navigator.webkitGetUserMedia || window.navigator.mozGetUserMedia + ); + if (getUserMedia) { + return getUserMedia.apply(window.navigator, [ + { video: true, audio: true }, + this._refreshMediaDevices, + function() {}, + ]); + } + }, + _renderWebRtcSettings: function() { - if (!(window && window.process && window.process.type) - || !this.state.mediaDevices) return; + if (this.state.mediaDevices === false) { + return