From d34adb67dd2995c1b85769a199e70173fdd85b0c Mon Sep 17 00:00:00 2001 From: Kostiantyn Tsaregradskyi Date: Fri, 6 May 2016 17:31:23 +0300 Subject: [PATCH] Added ability to switch audio output device --- conference.js | 36 +++---------------- lang/main.json | 1 + .../UI/side_pannels/settings/SettingsMenu.js | 17 ++++----- modules/settings/Settings.js | 21 ++++++++--- 4 files changed, 32 insertions(+), 43 deletions(-) diff --git a/conference.js b/conference.js index 9ff866dd7..0a945bfb1 100644 --- a/conference.js +++ b/conference.js @@ -1106,37 +1106,11 @@ export default { APP.UI.addListener( UIEvents.AUDIO_OUTPUT_DEVICE_CHANGED, (audioOutputDeviceId) => { - APP.settings.setAudioOutputDeviceId(audioOutputDeviceId); - - let promises = [], - track; - - for (let key in room.rtc.remoteTracks) { - track = room.rtc.remoteTracks[key].video; - - if (track && track.containers.length) { - promises.push( - track.changeAudioOutput(audioOutputDeviceId)); - } - - track = room.rtc.remoteTracks[key].audio; - - if (track && track.containers.length) { - promises.push( - track.changeAudioOutput(audioOutputDeviceId)); - } - } - - room.rtc.localTracks.forEach((track) => { - if (track.containers.length) { - promises.push( - track.changeAudioOutput(audioOutputDeviceId)); - } - }); - - Promise.all(promises).then( - () => console.log('audio devices switched'), - (err) => console.error(err)); + APP.settings.setAudioOutputDeviceId(audioOutputDeviceId) + .then(() => console.log('changed output device')) + .catch((err) => { + console.error('failed to set audio output device', err); + }); } ); diff --git a/lang/main.json b/lang/main.json index 0e5233b05..cdc9f056b 100644 --- a/lang/main.json +++ b/lang/main.json @@ -89,6 +89,7 @@ "startVideoMuted": "Start without video", "selectCamera": "Select camera", "selectMic": "Select microphone", + "selectAudioOutput": "Select audio output", "followMe": "Enable follow me" }, "videothumbnail": diff --git a/modules/UI/side_pannels/settings/SettingsMenu.js b/modules/UI/side_pannels/settings/SettingsMenu.js index 58c087da1..c380ec42f 100644 --- a/modules/UI/side_pannels/settings/SettingsMenu.js +++ b/modules/UI/side_pannels/settings/SettingsMenu.js @@ -1,4 +1,4 @@ -/* global APP, $ */ +/* global APP, $, JitsiMeetJS */ import UIUtil from "../../util/UIUtil"; import UIEvents from "../../../../service/UI/UIEvents"; import languages from "../../../../service/translation/languages"; @@ -202,7 +202,8 @@ export default { let $selectCamera= $('#selectCamera'), $selectMic = $('#selectMic'), - $selectAudioOutput = $('#selectAudioOutput'); + $selectAudioOutput = $('#selectAudioOutput'), + $selectAudioOutputParent = $selectAudioOutput.parent(); let audio = devices.filter(device => device.kind === 'audioinput'); let video = devices.filter(device => device.kind === 'videoinput'); @@ -216,15 +217,15 @@ export default { generateDevicesOptions(audio, Settings.getMicDeviceId()) ); - if (audioOutput.length) { + if (audioOutput.length && + JitsiMeetJS.isAudioOutputDeviceChangeAvailable()) { $selectAudioOutput.html( generateDevicesOptions(audioOutput, - Settings.getAudioOutputDeviceId()) - ).show(); + Settings.getAudioOutputDeviceId())); + + $selectAudioOutputParent.show(); } else { - // if we have no audiooutput devices, that means current browser - // doesn't support it, so don't show the select box at all - $selectAudioOutput.hide(); + $selectAudioOutputParent.hide(); } $devicesOptions.show(); diff --git a/modules/settings/Settings.js b/modules/settings/Settings.js index a9c925542..0cca951ca 100644 --- a/modules/settings/Settings.js +++ b/modules/settings/Settings.js @@ -1,3 +1,5 @@ +/* global JitsiMeetJS */ + import UIUtil from '../UI/util/UIUtil'; let email = ''; @@ -5,7 +7,6 @@ let displayName = ''; let language = null; let cameraDeviceId = ''; let micDeviceId = ''; -let audioOutputDeviceId = ''; let welcomePageDisabled = false; function supportsLocalStorage() { @@ -39,6 +40,17 @@ if (supportsLocalStorage()) { welcomePageDisabled = JSON.parse( window.localStorage.welcomePageDisabled || false ); + + var audioOutputDeviceId = window.localStorage.audioOutputDeviceId; + + if (typeof audioOutputDeviceId !== 'undefined' && + audioOutputDeviceId !== JitsiMeetJS.getAudioOutputDevice()) { + JitsiMeetJS.setAudioOutputDevice( + window.localStorage.audioOutputDeviceId).catch((ex) => { + console.error('failed to set audio output device from local ' + + 'storage', ex); + }); + } } else { console.log("local storage is not supported"); } @@ -130,16 +142,17 @@ export default { * @returns {String} */ getAudioOutputDeviceId: function () { - return audioOutputDeviceId; + return JitsiMeetJS.getAudioOutputDevice(); }, /** * Set device id of the audio output device which is currently in use. * Empty string stands for default device. * @param {string} newId new audio output device id + * @returns {Promise} */ setAudioOutputDeviceId: function (newId = '') { - audioOutputDeviceId = newId; - window.localStorage.audioOutputDeviceId = newId; + return JitsiMeetJS.setAudioOutputDevice(newId) + .then(() => window.localStorage.audioOutputDeviceId = newId); }, /**