Bläddra i källkod

feat(iframe-api): Add deviceListChanged event.

master
Hristo Terezov 6 år sedan
förälder
incheckning
a7aaf31c79

+ 2
- 2
conference.js Visa fil

@@ -2417,7 +2417,7 @@ export default {
2417 2417
      */
2418 2418
     updateAudioIconEnabled() {
2419 2419
         const audioMediaDevices
2420
-            = APP.store.getState()['features/base/devices'].audioInput;
2420
+            = APP.store.getState()['features/base/devices'].devices.audioInput;
2421 2421
         const audioDeviceCount
2422 2422
             = audioMediaDevices ? audioMediaDevices.length : 0;
2423 2423
 
@@ -2440,7 +2440,7 @@ export default {
2440 2440
      */
2441 2441
     updateVideoIconEnabled() {
2442 2442
         const videoMediaDevices
2443
-            = APP.store.getState()['features/base/devices'].videoInput;
2443
+            = APP.store.getState()['features/base/devices'].devices.videoInput;
2444 2444
         const videoDeviceCount
2445 2445
             = videoMediaDevices ? videoMediaDevices.length : 0;
2446 2446
 

+ 8
- 0
doc/api.md Visa fil

@@ -300,6 +300,14 @@ changes. The listener will receive an object with the following structure:
300 300
 }
301 301
 ```
302 302
 
303
+* **deviceListChanged** - event notifications about device list changes. The listener will receive an object with the following structure:
304
+```javascript
305
+{
306
+"devices": devices // the new list of available devices.
307
+}
308
+```
309
+NOTE: The devices object has the same format as the getAvailableDevices result format.
310
+
303 311
 * **emailChange** - event notifications about email
304 312
 changes. The listener will receive an object with the following structure:
305 313
 ```javascript

+ 13
- 0
modules/API/API.js Visa fil

@@ -386,6 +386,19 @@ class API {
386 386
         });
387 387
     }
388 388
 
389
+    /**
390
+     * Notify external application (if API is enabled) that the device list has
391
+     * changed.
392
+     *
393
+     * @param {Object} devices - The new device list.
394
+     * @returns {void}
395
+     */
396
+    notifyDeviceListChanged(devices: Object) {
397
+        this._sendEvent({
398
+            name: 'device-list-changed',
399
+            devices });
400
+    }
401
+
389 402
     /**
390 403
      * Notify external application (if API is enabled) that user changed their
391 404
      * nickname.

+ 1
- 0
modules/API/external/external_api.js Visa fil

@@ -50,6 +50,7 @@ const events = {
50 50
     'avatar-changed': 'avatarChanged',
51 51
     'audio-availability-changed': 'audioAvailabilityChanged',
52 52
     'audio-mute-status-changed': 'audioMuteStatusChanged',
53
+    'device-list-changed': 'deviceListChanged',
53 54
     'display-name-change': 'displayNameChange',
54 55
     'email-change': 'emailChange',
55 56
     'feedback-submitted': 'feedbackSubmitted',

+ 3
- 2
react/features/base/devices/functions.js Visa fil

@@ -20,7 +20,7 @@ export function areDeviceLabelsInitialized(state: Object) {
20 20
     }
21 21
 
22 22
     for (const type of [ 'audioInput', 'audioOutput', 'videoInput' ]) {
23
-        if (state['features/base/devices'][type].find(d => Boolean(d.label))) {
23
+        if (state['features/base/devices'].devices[type].find(d => Boolean(d.label))) {
24 24
             return true;
25 25
         }
26 26
     }
@@ -50,7 +50,8 @@ export function getDeviceIdByLabel(state: Object, label: string) {
50 50
 
51 51
     for (const type of types) {
52 52
         const device
53
-            = state['features/base/devices'][type].find(d => d.label === label);
53
+            = state['features/base/devices'].devices[type]
54
+                .find(d => d.label === label);
54 55
 
55 56
         if (device) {
56 57
             return device.deviceId;

+ 7
- 5
react/features/base/devices/reducer.js Visa fil

@@ -10,9 +10,11 @@ import { groupDevicesByKind } from './functions';
10 10
 import { ReducerRegistry } from '../redux';
11 11
 
12 12
 const DEFAULT_STATE = {
13
-    audioInput: [],
14
-    audioOutput: [],
15
-    videoInput: [],
13
+    devices: {
14
+        audioInput: [],
15
+        audioOutput: [],
16
+        videoInput: []
17
+    },
16 18
     pendingRequests: []
17 19
 };
18 20
 
@@ -34,8 +36,8 @@ ReducerRegistry.register(
34 36
             const deviceList = groupDevicesByKind(action.devices);
35 37
 
36 38
             return {
37
-                pendingRequests: state.pendingRequests,
38
-                ...deviceList
39
+                ...state,
40
+                devices: deviceList
39 41
             };
40 42
         }
41 43
 

+ 1
- 1
react/features/device-selection/functions.js Visa fil

@@ -28,7 +28,7 @@ export function getDeviceSelectionDialogProps(stateful: Object | Function) {
28 28
     const settings = state['features/base/settings'];
29 29
 
30 30
     return {
31
-        availableDevices: state['features/base/devices'],
31
+        availableDevices: state['features/base/devices'].devices,
32 32
         disableAudioInputChange:
33 33
             !JitsiMeetJS.isMultipleAudioInputSupported(),
34 34
         disableDeviceChange:

+ 15
- 3
react/features/device-selection/middleware.js Visa fil

@@ -1,6 +1,10 @@
1
+// @flow
2
+
1 3
 import { UPDATE_DEVICE_LIST } from '../base/devices';
2 4
 import { MiddlewareRegistry } from '../base/redux';
3 5
 
6
+declare var APP: Object;
7
+
4 8
 /**
5 9
  * Implements the middleware of the feature device-selection.
6 10
  *
@@ -12,11 +16,19 @@ MiddlewareRegistry.register(store => next => action => {
12 16
     const result = next(action);
13 17
 
14 18
     if (action.type === UPDATE_DEVICE_LIST) {
15
-        const { popupDialogData }
16
-            = store.getState()['features/device-selection'];
19
+        const state = store.getState();
20
+        const { popupDialogData } = state['features/device-selection'];
21
+        const { devices } = state['features/base/devices'];
17 22
 
18 23
         if (popupDialogData) {
19
-            popupDialogData.transport.sendEvent({ name: 'deviceListChanged' });
24
+            popupDialogData.transport.sendEvent({
25
+                name: 'deviceListChanged',
26
+                devices
27
+            });
28
+        }
29
+
30
+        if (typeof APP !== 'undefined') {
31
+            APP.API.notifyDeviceListChanged(devices);
20 32
         }
21 33
     }
22 34
 

Laddar…
Avbryt
Spara