From 40c3fed33e73ff1154daac2317a5aa81579a341e Mon Sep 17 00:00:00 2001 From: isymchych Date: Tue, 15 Mar 2016 13:30:47 +0200 Subject: [PATCH] handle device list changes --- conference.js | 16 +++++---- modules/UI/UI.js | 2 +- .../UI/side_pannels/settings/SettingsMenu.js | 36 ++++++++++--------- package.json | 2 +- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/conference.js b/conference.js index 57a660156..742624cb7 100644 --- a/conference.js +++ b/conference.js @@ -10,6 +10,8 @@ import ConnectionQuality from './modules/connectionquality/connectionquality'; import CQEvents from './service/connectionquality/CQEvents'; import UIEvents from './service/UI/UIEvents'; +const LibraryEvents = JitsiMeetJS.events.library; + const ConnectionEvents = JitsiMeetJS.events.connection; const ConnectionErrors = JitsiMeetJS.errors.connection; @@ -331,12 +333,14 @@ export default { JitsiMeetJS.isDesktopSharingEnabled(); // update list of available devices - if (JitsiMeetJS.isDeviceListAvailable() && - JitsiMeetJS.isDeviceChangeAvailable()) { - JitsiMeetJS.enumerateDevices( - devices => APP.UI.onAvailableDevicesChanged(devices) - ); - } + APP.UI.updateDevicesList(JitsiMeetJS.getDevicesList()); + JitsiMeetJS.on( + LibraryEvents.DEVICES_LIST_CHANGED, + function () { + APP.UI.updateDevicesList(JitsiMeetJS.getDevicesList()); + } + ); + // XXX The API will take care of disconnecting from the XMPP server // (and, thus, leaving the room) on unload. return new Promise((resolve, reject) => { diff --git a/modules/UI/UI.js b/modules/UI/UI.js index 8cfa0e067..b2a94916f 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -1018,7 +1018,7 @@ UI.onStartMutedChanged = function (startAudioMuted, startVideoMuted) { * Update list of available physical devices. * @param {object[]} devices new list of available devices */ -UI.onAvailableDevicesChanged = function (devices) { +UI.updateDevicesList = function (devices) { SettingsMenu.changeDevicesList(devices); }; diff --git a/modules/UI/side_pannels/settings/SettingsMenu.js b/modules/UI/side_pannels/settings/SettingsMenu.js index b2baecd0a..be6f528aa 100644 --- a/modules/UI/side_pannels/settings/SettingsMenu.js +++ b/modules/UI/side_pannels/settings/SettingsMenu.js @@ -33,7 +33,7 @@ function generateLanguagesOptions(items, currentLang) { * @returns {string} */ function generateDevicesOptions(items, selectedId) { - return items.map(function (item) { + let options = items.map(function (item) { let attrs = { value: item.deviceId }; @@ -44,7 +44,10 @@ function generateDevicesOptions(items, selectedId) { let attrsStr = UIUtil.attrsToString(attrs); return ``; - }).join('\n'); + }); + options.unshift(''); + + return options.join('\n'); } @@ -103,7 +106,6 @@ export default { // DEVICES LIST - this.changeDevicesList([]); $('#selectCamera').change(function () { let cameraDeviceId = $(this).val(); if (cameraDeviceId !== Settings.getCameraDeviceId()) { @@ -164,22 +166,24 @@ export default { * no devices available. * @param {{ deviceId, label, kind }[]} devices list of available devices */ - changeDevicesList (devices) { - if (!devices.length) { - $('#devicesOptions').hide(); - return; + changeDevicesList ({ audio = [], video = []}) { + let audioSelect = $('#selectMic'); + if (audio.length) { + audioSelect.html( + generateDevicesOptions(audio, Settings.getMicDeviceId()) + ); } + audioSelect.parent().toggle(!!audio.length); - let audio = devices.filter(device => device.kind === 'audioinput'); - let video = devices.filter(device => device.kind === 'videoinput'); - $('#selectCamera').html( - generateDevicesOptions(video, Settings.getCameraDeviceId()) - ); - $('#selectMic').html( - generateDevicesOptions(audio, Settings.getMicDeviceId()) - ); + let videoSelect = $('#selectCamera'); + if (video.length) { + videoSelect.html( + generateDevicesOptions(video, Settings.getCameraDeviceId()) + ); + } + videoSelect.parent().toggle(!!video.length); - $('#devicesOptions').show(); + $('#devicesOptions').toggle(!!(audio.length || video.length)); } }; diff --git a/package.json b/package.json index 0fd97c61a..ada7aaa7f 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "browserify": "11.1.x", "browserify-shim": "^3.8.10", "exorcist": "*", - "jshint": "2.8.0", + "jshint": "2.9.1", "precommit-hook": "3.0.0", "uglify-js": "2.4.24", "clean-css": "*",