Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

Added ability to switch audio output device

Kostiantyn Tsaregradskyid34adb67dd29
diff --git a/conference.js b/conference.js
index 9ff866dd78..0a945bfb1a 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 0e5233b05f..cdc9f056b9 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 58c087da16..c380ec42f3 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 a9c925542d..0cca951ca1 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);
},
/**