Procházet zdrojové kódy

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

factor2
Horatiu Muresan před 2 roky
rodič
revize
acb91990bf
Žádný účet není propojen s e-mailovou adresou tvůrce revize

+ 2
- 0
react/features/base/devices/functions.web.ts Zobrazit soubor

@@ -2,6 +2,7 @@ import { IReduxState, IStore } from '../../app/types';
2 2
 import JitsiMeetJS from '../lib-jitsi-meet';
3 3
 import { updateSettings } from '../settings/actions';
4 4
 import { ISettingsState } from '../settings/reducer';
5
+import { setNewAudioOutputDevice } from '../sounds/functions.web';
5 6
 import { parseURLParams } from '../util/parseURLParams';
6 7
 
7 8
 import logger from './logger';
@@ -265,6 +266,7 @@ export function setAudioOutputDeviceId(
265 266
 
266 267
     return JitsiMeetJS.mediaDevices.setAudioOutputDevice(newId)
267 268
         .then(() => {
269
+            dispatch(setNewAudioOutputDevice(newId));
268 270
             const newSettings: Partial<ISettingsState> = {
269 271
                 audioOutputDeviceId: newId,
270 272
                 userSelectedAudioOutputDeviceId: undefined,

+ 18
- 0
react/features/base/sounds/functions.web.ts Zobrazit soubor

@@ -1,3 +1,5 @@
1
+import { IStore } from '../../app/types';
2
+
1 3
 /**
2 4
  * Returns the location of the sounds. On Web it's the relative path to
3 5
  * the sounds folder placed in the source root.
@@ -7,3 +9,19 @@
7 9
 export function getSoundsPath() {
8 10
     return 'sounds';
9 11
 }
12
+
13
+/**
14
+ * Set new audio output device on the global sound elements.
15
+ *
16
+ * @param {string } deviceId - The new output deviceId.
17
+ * @returns {Function}
18
+ */
19
+export function setNewAudioOutputDevice(deviceId: string) {
20
+    return function(_dispatch: IStore['dispatch'], getState: IStore['getState']) {
21
+        const sounds = getState()['features/base/sounds'];
22
+
23
+        for (const [ , sound ] of sounds) {
24
+            sound.audioElement?.setSinkId?.(deviceId);
25
+        }
26
+    };
27
+}

react/features/base/sounds/middleware.ts → react/features/base/sounds/middleware.any.ts Zobrazit soubor

@@ -5,12 +5,13 @@ import { PLAY_SOUND, STOP_SOUND } from './actionTypes';
5 5
 import logger from './logger';
6 6
 
7 7
 /**
8
- * Implements the entry point of the middleware of the feature base/media.
8
+ * Implements the entry point of the middleware of the feature base/sounds.
9 9
  *
10 10
  * @param {Store} store - The redux store.
11 11
  * @returns {Function}
12 12
  */
13 13
 MiddlewareRegistry.register(store => next => action => {
14
+
14 15
     switch (action.type) {
15 16
     case PLAY_SOUND:
16 17
         _playSound(store, action.soundId);

+ 1
- 0
react/features/base/sounds/middleware.native.ts Zobrazit soubor

@@ -0,0 +1 @@
1
+import './middleware.any';

+ 23
- 0
react/features/base/sounds/middleware.web.ts Zobrazit soubor

@@ -0,0 +1,23 @@
1
+import { getAudioOutputDeviceId } from '../devices/functions.web';
2
+import MiddlewareRegistry from '../redux/MiddlewareRegistry';
3
+
4
+import { _ADD_AUDIO_ELEMENT } from './actionTypes';
5
+
6
+import './middleware.any';
7
+
8
+/**
9
+ * Implements the entry point of the middleware of the feature base/sounds.
10
+ *
11
+ * @param {Store} store - The redux store.
12
+ * @returns {Function}
13
+ */
14
+MiddlewareRegistry.register(_store => next => action => {
15
+
16
+    switch (action.type) {
17
+    case _ADD_AUDIO_ELEMENT:
18
+        action.audioElement?.setSinkId?.(getAudioOutputDeviceId());
19
+        break;
20
+    }
21
+
22
+    return next(action);
23
+});

Načítá se…
Zrušit
Uložit