浏览代码

feat(iframe-api): Add deviceListChanged event.

master
Hristo Terezov 6 年前
父节点
当前提交
a7aaf31c79

+ 2
- 2
conference.js 查看文件

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

+ 8
- 0
doc/api.md 查看文件

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
 * **emailChange** - event notifications about email
311
 * **emailChange** - event notifications about email
304
 changes. The listener will receive an object with the following structure:
312
 changes. The listener will receive an object with the following structure:
305
 ```javascript
313
 ```javascript

+ 13
- 0
modules/API/API.js 查看文件

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
      * Notify external application (if API is enabled) that user changed their
403
      * Notify external application (if API is enabled) that user changed their
391
      * nickname.
404
      * nickname.

+ 1
- 0
modules/API/external/external_api.js 查看文件

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

+ 3
- 2
react/features/base/devices/functions.js 查看文件

20
     }
20
     }
21
 
21
 
22
     for (const type of [ 'audioInput', 'audioOutput', 'videoInput' ]) {
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
             return true;
24
             return true;
25
         }
25
         }
26
     }
26
     }
50
 
50
 
51
     for (const type of types) {
51
     for (const type of types) {
52
         const device
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
         if (device) {
56
         if (device) {
56
             return device.deviceId;
57
             return device.deviceId;

+ 7
- 5
react/features/base/devices/reducer.js 查看文件

10
 import { ReducerRegistry } from '../redux';
10
 import { ReducerRegistry } from '../redux';
11
 
11
 
12
 const DEFAULT_STATE = {
12
 const DEFAULT_STATE = {
13
-    audioInput: [],
14
-    audioOutput: [],
15
-    videoInput: [],
13
+    devices: {
14
+        audioInput: [],
15
+        audioOutput: [],
16
+        videoInput: []
17
+    },
16
     pendingRequests: []
18
     pendingRequests: []
17
 };
19
 };
18
 
20
 
34
             const deviceList = groupDevicesByKind(action.devices);
36
             const deviceList = groupDevicesByKind(action.devices);
35
 
37
 
36
             return {
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 查看文件

28
     const settings = state['features/base/settings'];
28
     const settings = state['features/base/settings'];
29
 
29
 
30
     return {
30
     return {
31
-        availableDevices: state['features/base/devices'],
31
+        availableDevices: state['features/base/devices'].devices,
32
         disableAudioInputChange:
32
         disableAudioInputChange:
33
             !JitsiMeetJS.isMultipleAudioInputSupported(),
33
             !JitsiMeetJS.isMultipleAudioInputSupported(),
34
         disableDeviceChange:
34
         disableDeviceChange:

+ 15
- 3
react/features/device-selection/middleware.js 查看文件

1
+// @flow
2
+
1
 import { UPDATE_DEVICE_LIST } from '../base/devices';
3
 import { UPDATE_DEVICE_LIST } from '../base/devices';
2
 import { MiddlewareRegistry } from '../base/redux';
4
 import { MiddlewareRegistry } from '../base/redux';
3
 
5
 
6
+declare var APP: Object;
7
+
4
 /**
8
 /**
5
  * Implements the middleware of the feature device-selection.
9
  * Implements the middleware of the feature device-selection.
6
  *
10
  *
12
     const result = next(action);
16
     const result = next(action);
13
 
17
 
14
     if (action.type === UPDATE_DEVICE_LIST) {
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
         if (popupDialogData) {
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
 

正在加载...
取消
保存