Skip to content

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

fix(notif-sounds) Set correct audio output device for notifs (#13436)

Horatiu Muresanacb91990bfca
diff --git a/react/features/base/devices/functions.web.ts b/react/features/base/devices/functions.web.ts
index 65e5085f5f..ab7079a885 100644
--- a/react/features/base/devices/functions.web.ts
+++ b/react/features/base/devices/functions.web.ts
@@ -2,6 +2,7 @@ import { IReduxState, IStore } from '../../app/types';
import JitsiMeetJS from '../lib-jitsi-meet';
import { updateSettings } from '../settings/actions';
import { ISettingsState } from '../settings/reducer';
+import { setNewAudioOutputDevice } from '../sounds/functions.web';
import { parseURLParams } from '../util/parseURLParams';
import logger from './logger';
@@ -265,6 +266,7 @@ export function setAudioOutputDeviceId(
return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
.then(() => {
+ dispatch(setNewAudioOutputDevice(newId));
const newSettings: Partial<ISettingsState> = {
audioOutputDeviceId: newId,
userSelectedAudioOutputDeviceId: undefined,
diff --git a/react/features/base/sounds/functions.web.ts b/react/features/base/sounds/functions.web.ts
index b4dba52811..33a60a393b 100644
--- a/react/features/base/sounds/functions.web.ts
+++ b/react/features/base/sounds/functions.web.ts
@@ -1,3 +1,5 @@
+import { IStore } from '../../app/types';
+
/**
* Returns the location of the sounds. On Web it's the relative path to
* the sounds folder placed in the source root.
@@ -7,3 +9,19 @@
export function getSoundsPath() {
return 'sounds';
}
+
+/**
+ * Set new audio output device on the global sound elements.
+ *
+ * @param {string } deviceId - The new output deviceId.
+ * @returns {Function}
+ */
+export function setNewAudioOutputDevice(deviceId: string) {
+ return function(_dispatch: IStore['dispatch'], getState: IStore['getState']) {
+ const sounds = getState()['features/base/sounds'];
+
+ for (const [ , sound ] of sounds) {
+ sound.audioElement?.setSinkId?.(deviceId);
+ }
+ };
+}
diff --git a/react/features/base/sounds/middleware.ts b/react/features/base/sounds/middleware.any.ts
similarity index 99%
rename from react/features/base/sounds/middleware.ts
rename to react/features/base/sounds/middleware.any.ts
index 5a647ae175..5267783838 100644
--- a/react/features/base/sounds/middleware.ts
+++ b/react/features/base/sounds/middleware.any.ts
@@ -5,12 +5,13 @@ import { PLAY_SOUND, STOP_SOUND } from './actionTypes';
import logger from './logger';
/**
- * Implements the entry point of the middleware of the feature base/media.
+ * Implements the entry point of the middleware of the feature base/sounds.
*
* @param {Store} store - The redux store.
* @returns {Function}
*/
MiddlewareRegistry.register(store => next => action => {
+
switch (action.type) {
case PLAY_SOUND:
_playSound(store, action.soundId);
diff --git a/react/features/base/sounds/middleware.native.ts b/react/features/base/sounds/middleware.native.ts
new file mode 100644
index 0000000000..fefd329e8a
--- /dev/null
+++ b/react/features/base/sounds/middleware.native.ts
@@ -0,0 +1 @@
+import './middleware.any';
diff --git a/react/features/base/sounds/middleware.web.ts b/react/features/base/sounds/middleware.web.ts
new file mode 100644
index 0000000000..049c55b54a
--- /dev/null
+++ b/react/features/base/sounds/middleware.web.ts
@@ -0,0 +1,23 @@
+import { getAudioOutputDeviceId } from '../devices/functions.web';
+import MiddlewareRegistry from '../redux/MiddlewareRegistry';
+
+import { _ADD_AUDIO_ELEMENT } from './actionTypes';
+
+import './middleware.any';
+
+/**
+ * Implements the entry point of the middleware of the feature base/sounds.
+ *
+ * @param {Store} store - The redux store.
+ * @returns {Function}
+ */
+MiddlewareRegistry.register(_store => next => action => {
+
+ switch (action.type) {
+ case _ADD_AUDIO_ELEMENT:
+ action.audioElement?.setSinkId?.(getAudioOutputDeviceId());
+ break;
+ }
+
+ return next(action);
+});