Просмотр исходного кода

fix(iframe-api-devices): Misc small issues.

j8
Hristo Terezov 6 лет назад
Родитель
Сommit
829e5597d5

+ 2
- 2
conference.js Просмотреть файл

@@ -2417,7 +2417,7 @@ export default {
2417 2417
      */
2418 2418
     updateAudioIconEnabled() {
2419 2419
         const audioMediaDevices
2420
-            = APP.store.getState()['features/base/devices'].devices.audioInput;
2420
+            = APP.store.getState()['features/base/devices'].availableDevices.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'].devices.videoInput;
2443
+            = APP.store.getState()['features/base/devices'].availableDevices.videoInput;
2444 2444
         const videoDeviceCount
2445 2445
             = videoMediaDevices ? videoMediaDevices.length : 0;
2446 2446
 

+ 2
- 2
doc/api.md Просмотреть файл

@@ -81,7 +81,7 @@ var api = new JitsiMeetExternalAPI(domain, options);
81 81
 
82 82
 ### Controlling the embedded Jitsi Meet Conference
83 83
 
84
-You can control the available devices  with the following methods of `JitsiMeetExternalAPI` instance:
84
+Device management `JitsiMeetExternalAPI` methods:
85 85
 * **getAvailableDevices** - Retrieve a list of available devices.
86 86
 
87 87
 ```javascript
@@ -151,7 +151,7 @@ api.isDeviceListAvailable().then(function(isDeviceListAvailable) {
151 151
     ...
152 152
 });
153 153
 ```
154
-* **isMultipleAudioInputSupported** - Resolves with true if the device list is available and with false if not.
154
+* **isMultipleAudioInputSupported** - Resolves with true if multiple audio input is supported and with false if not.
155 155
 
156 156
 ```javascript
157 157
 api.isMultipleAudioInputSupported().then(function(isMultipleAudioInputSupported) {

+ 2
- 2
modules/API/API.js Просмотреть файл

@@ -12,7 +12,7 @@ import { getJitsiMeetTransport } from '../transport';
12 12
 
13 13
 import { API_ID } from './constants';
14 14
 import {
15
-    processRequest
15
+    processExternalDeviceRequest
16 16
 } from '../../react/features/device-selection/functions';
17 17
 
18 18
 const logger = require('jitsi-meet-logger').getLogger(__filename);
@@ -122,7 +122,7 @@ function initCommands() {
122 122
     transport.on('request', (request, callback) => {
123 123
         const { dispatch, getState } = APP.store;
124 124
 
125
-        if (processRequest(dispatch, getState, request, callback)) {
125
+        if (processExternalDeviceRequest(dispatch, getState, request, callback)) {
126 126
             return true;
127 127
         }
128 128
 

+ 17
- 11
modules/API/external/external_api.js Просмотреть файл

@@ -609,7 +609,7 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
609 609
     }
610 610
 
611 611
     /**
612
-     * Returns Promise that resolves with result an list of available devices.
612
+     * Returns Promise that resolves with a list of available devices.
613 613
      *
614 614
      * @returns {Promise}
615 615
      */
@@ -661,7 +661,7 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
661 661
     }
662 662
 
663 663
     /**
664
-     * Returns Promise that resolves with true if the device list is available
664
+     * Returns Promise that resolves with true if multiple audio input is supported
665 665
      * and with false if not.
666 666
      *
667 667
      * @returns {Promise}
@@ -837,33 +837,39 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
837 837
     }
838 838
 
839 839
     /**
840
-     * Sets the audio input device to the one with the id that is passed.
840
+     * Sets the audio input device to the one with the label or id that is
841
+     * passed.
841 842
      *
843
+     * @param {string} label - The label of the new device.
842 844
      * @param {string} deviceId - The id of the new device.
843 845
      * @returns {Promise}
844 846
      */
845
-    setAudioInputDevice(deviceId) {
846
-        return setAudioInputDevice(this._transport, deviceId);
847
+    setAudioInputDevice(label, deviceId) {
848
+        return setAudioInputDevice(this._transport, label, deviceId);
847 849
     }
848 850
 
849 851
     /**
850
-     * Sets the audio output device to the one with the id that is passed.
852
+     * Sets the audio output device to the one with the label or id that is
853
+     * passed.
851 854
      *
855
+     * @param {string} label - The label of the new device.
852 856
      * @param {string} deviceId - The id of the new device.
853 857
      * @returns {Promise}
854 858
      */
855
-    setAudioOutputDevice(deviceId) {
856
-        return setAudioOutputDevice(this._transport, deviceId);
859
+    setAudioOutputDevice(label, deviceId) {
860
+        return setAudioOutputDevice(this._transport, label, deviceId);
857 861
     }
858 862
 
859 863
     /**
860
-     * Sets the video input device to the one with the id that is passed.
864
+     * Sets the video input device to the one with the label or id that is
865
+     * passed.
861 866
      *
867
+     * @param {string} label - The label of the new device.
862 868
      * @param {string} deviceId - The id of the new device.
863 869
      * @returns {Promise}
864 870
      */
865
-    setVideoInputDevice(deviceId) {
866
-        return setVideoInputDevice(this._transport, deviceId);
871
+    setVideoInputDevice(label, deviceId) {
872
+        return setVideoInputDevice(this._transport, label, deviceId);
867 873
     }
868 874
 
869 875
     /**

+ 1
- 13
modules/API/external/functions.js Просмотреть файл

@@ -55,10 +55,6 @@ export function isDeviceChangeAvailable(transport: Object, deviceType: string) {
55 55
         deviceType,
56 56
         type: 'devices',
57 57
         name: 'isDeviceChangeAvailable'
58
-    }).catch(e => {
59
-        logger.error(e);
60
-
61
-        return false;
62 58
     });
63 59
 }
64 60
 
@@ -74,15 +70,11 @@ export function isDeviceListAvailable(transport: Object) {
74 70
     return transport.sendRequest({
75 71
         type: 'devices',
76 72
         name: 'isDeviceListAvailable'
77
-    }).catch(e => {
78
-        logger.error(e);
79
-
80
-        return false;
81 73
     });
82 74
 }
83 75
 
84 76
 /**
85
- * Returns Promise that resolves with true if the device list is available
77
+ * Returns Promise that resolves with true if multiple audio input is supported
86 78
  * and with false if not.
87 79
  *
88 80
  * @param {Transport} transport - The @code{Transport} instance responsible for
@@ -93,10 +85,6 @@ export function isMultipleAudioInputSupported(transport: Object) {
93 85
     return transport.sendRequest({
94 86
         type: 'devices',
95 87
         name: 'isMultipleAudioInputSupported'
96
-    }).catch(e => {
97
-        logger.error(e);
98
-
99
-        return false;
100 88
     });
101 89
 }
102 90
 

+ 1
- 2
react/features/base/devices/actionTypes.js Просмотреть файл

@@ -46,8 +46,7 @@ export const ADD_PENDING_DEVICE_REQUEST = 'ADD_PENDING_DEVICE_REQUEST';
46 46
  * The type of Redux action which will remove all pending device requests.
47 47
  *
48 48
  * {
49
- *     type: REMOVE_PENDING_DEVICE_REQUESTS,
50
- *     request: Object
49
+ *     type: REMOVE_PENDING_DEVICE_REQUESTS
51 50
  * }
52 51
  */
53 52
 export const REMOVE_PENDING_DEVICE_REQUESTS = 'REMOVE_PENDING_DEVICE_REQUESTS';

+ 3
- 2
react/features/base/devices/functions.js Просмотреть файл

@@ -15,12 +15,13 @@ declare var APP: Object;
15 15
  * otherwise.
16 16
  */
17 17
 export function areDeviceLabelsInitialized(state: Object) {
18
+    // TODO: Replace with something that doesn't use APP when the conference.js logic is reactified.
18 19
     if (APP.conference._localTracksInitialized) {
19 20
         return true;
20 21
     }
21 22
 
22 23
     for (const type of [ 'audioInput', 'audioOutput', 'videoInput' ]) {
23
-        if (state['features/base/devices'].devices[type].find(d => Boolean(d.label))) {
24
+        if ((state['features/base/devices'].availableDevices[type] || []).find(d => Boolean(d.label))) {
24 25
             return true;
25 26
         }
26 27
     }
@@ -50,7 +51,7 @@ export function getDeviceIdByLabel(state: Object, label: string) {
50 51
 
51 52
     for (const type of types) {
52 53
         const device
53
-            = state['features/base/devices'].devices[type]
54
+            = (state['features/base/devices'].availableDevices[type] || [])
54 55
                 .find(d => d.label === label);
55 56
 
56 57
         if (device) {

+ 2
- 2
react/features/base/devices/middleware.js Просмотреть файл

@@ -1,7 +1,7 @@
1 1
 /* global APP */
2 2
 
3 3
 import { CONFERENCE_JOINED } from '../conference';
4
-import { processRequest } from '../../device-selection';
4
+import { processExternalDeviceRequest } from '../../device-selection';
5 5
 import { MiddlewareRegistry } from '../redux';
6 6
 import UIEvents from '../../../../service/UI/UIEvents';
7 7
 
@@ -53,7 +53,7 @@ function _conferenceJoined({ dispatch, getState }, next, action) {
53 53
     const { pendingRequests } = state['features/base/devices'];
54 54
 
55 55
     pendingRequests.forEach(request => {
56
-        processRequest(
56
+        processExternalDeviceRequest(
57 57
             dispatch,
58 58
             getState,
59 59
             request,

+ 2
- 2
react/features/base/devices/reducer.js Просмотреть файл

@@ -10,7 +10,7 @@ import { groupDevicesByKind } from './functions';
10 10
 import { ReducerRegistry } from '../redux';
11 11
 
12 12
 const DEFAULT_STATE = {
13
-    devices: {
13
+    availableDevices: {
14 14
         audioInput: [],
15 15
         audioOutput: [],
16 16
         videoInput: []
@@ -37,7 +37,7 @@ ReducerRegistry.register(
37 37
 
38 38
             return {
39 39
                 ...state,
40
-                devices: deviceList
40
+                availableDevices: deviceList
41 41
             };
42 42
         }
43 43
 

+ 2
- 2
react/features/device-selection/actions.js Просмотреть файл

@@ -14,7 +14,7 @@ import { i18next } from '../base/i18n';
14 14
 import { updateSettings } from '../base/settings';
15 15
 
16 16
 import { SET_DEVICE_SELECTION_POPUP_DATA } from './actionTypes';
17
-import { getDeviceSelectionDialogProps, processRequest } from './functions';
17
+import { getDeviceSelectionDialogProps, processExternalDeviceRequest } from './functions';
18 18
 
19 19
 const logger = require('jitsi-meet-logger').getLogger(__filename);
20 20
 
@@ -58,7 +58,7 @@ export function openDeviceSelectionPopup() {
58 58
         });
59 59
 
60 60
         transport.on('request',
61
-            processRequest.bind(undefined, dispatch, getState));
61
+            processExternalDeviceRequest.bind(undefined, dispatch, getState));
62 62
         transport.on('event', event => {
63 63
             if (event.type === 'devices-dialog' && event.name === 'close') {
64 64
                 popup.close();

+ 109
- 110
react/features/device-selection/functions.js Просмотреть файл

@@ -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'].devices,
31
+        availableDevices: state['features/base/devices'].availableDevices,
32 32
         disableAudioInputChange:
33 33
             !JitsiMeetJS.isMultipleAudioInputSupported(),
34 34
         disableDeviceChange:
@@ -52,133 +52,132 @@ export function getDeviceSelectionDialogProps(stateful: Object | Function) {
52 52
  * @param {Object} request - The request to be processed.
53 53
  * @param {Function} responseCallback - The callback that will send the
54 54
  * response.
55
- * @returns {boolean}
55
+ * @returns {boolean} - True if the request has been processed and false otherwise.
56 56
  */
57
-export function processRequest( // eslint-disable-line max-params
57
+export function processExternalDeviceRequest( // eslint-disable-line max-params
58 58
         dispatch: Dispatch<any>,
59 59
         getState: Function,
60 60
         request: Object,
61 61
         responseCallback: Function) {
62
-    if (request.type === 'devices') {
63
-        const state = getState();
64
-        const settings = state['features/base/settings'];
65
-        const { conference } = state['features/base/conference'];
66
-        let result = true;
67
-
68
-        switch (request.name) {
69
-        case 'isDeviceListAvailable':
70
-            responseCallback(JitsiMeetJS.mediaDevices.isDeviceListAvailable());
71
-            break;
72
-        case 'isDeviceChangeAvailable':
73
-            responseCallback(
74
-                JitsiMeetJS.mediaDevices.isDeviceChangeAvailable(
75
-                    request.deviceType));
76
-            break;
77
-        case 'isMultipleAudioInputSupported':
78
-            responseCallback(JitsiMeetJS.isMultipleAudioInputSupported());
79
-            break;
80
-        case 'getCurrentDevices':
81
-            dispatch(getAvailableDevices()).then(devices => {
82
-                if (areDeviceLabelsInitialized(state)) {
83
-                    let audioInput, audioOutput, videoInput;
84
-                    const audioOutputDeviceId = getAudioOutputDeviceId();
85
-                    const { cameraDeviceId, micDeviceId } = settings;
86
-
87
-                    devices.forEach(device => {
88
-                        const { deviceId } = device;
89
-
90
-                        switch (deviceId) {
91
-                        case micDeviceId:
92
-                            audioInput = device;
93
-                            break;
94
-                        case audioOutputDeviceId:
95
-                            audioOutput = device;
96
-                            break;
97
-                        case cameraDeviceId:
98
-                            videoInput = device;
99
-                            break;
100
-                        }
101
-                    });
102
-
103
-                    responseCallback({
104
-                        audioInput,
105
-                        audioOutput,
106
-                        videoInput
107
-                    });
108
-                } else {
109
-                    // The labels are not available if the A/V permissions are
110
-                    // not yet granted.
111
-                    dispatch(addPendingDeviceRequest({
112
-                        type: 'devices',
113
-                        name: 'getCurrentDevices',
114
-                        responseCallback
115
-                    }));
116
-                }
117
-            });
118
-
119
-            break;
120
-        case 'getAvailableDevices':
121
-            dispatch(getAvailableDevices()).then(devices => {
122
-                if (areDeviceLabelsInitialized(state)) {
123
-                    responseCallback(groupDevicesByKind(devices));
124
-                } else {
125
-                    // The labels are not available if the A/V permissions are
126
-                    // not yet granted.
127
-                    dispatch(addPendingDeviceRequest({
128
-                        type: 'devices',
129
-                        name: 'getAvailableDevices',
130
-                        responseCallback
131
-                    }));
132
-                }
133
-            });
134
-
135
-            break;
136
-        case 'setDevice': {
137
-            const { device } = request;
138
-
139
-            if (!conference) {
62
+    if (request.type !== 'devices') {
63
+        return false;
64
+    }
65
+    const state = getState();
66
+    const settings = state['features/base/settings'];
67
+    const { conference } = state['features/base/conference'];
68
+    let result = true;
69
+
70
+    switch (request.name) {
71
+    case 'isDeviceListAvailable':
72
+        responseCallback(JitsiMeetJS.mediaDevices.isDeviceListAvailable());
73
+        break;
74
+    case 'isDeviceChangeAvailable':
75
+        responseCallback(
76
+            JitsiMeetJS.mediaDevices.isDeviceChangeAvailable(
77
+                request.deviceType));
78
+        break;
79
+    case 'isMultipleAudioInputSupported':
80
+        responseCallback(JitsiMeetJS.isMultipleAudioInputSupported());
81
+        break;
82
+    case 'getCurrentDevices':
83
+        dispatch(getAvailableDevices()).then(devices => {
84
+            if (areDeviceLabelsInitialized(state)) {
85
+                let audioInput, audioOutput, videoInput;
86
+                const audioOutputDeviceId = getAudioOutputDeviceId();
87
+                const { cameraDeviceId, micDeviceId } = settings;
88
+
89
+                devices.forEach(device => {
90
+                    const { deviceId } = device;
91
+
92
+                    switch (deviceId) {
93
+                    case micDeviceId:
94
+                        audioInput = device;
95
+                        break;
96
+                    case audioOutputDeviceId:
97
+                        audioOutput = device;
98
+                        break;
99
+                    case cameraDeviceId:
100
+                        videoInput = device;
101
+                        break;
102
+                    }
103
+                });
104
+
105
+                responseCallback({
106
+                    audioInput,
107
+                    audioOutput,
108
+                    videoInput
109
+                });
110
+            } else {
111
+                // The labels are not available if the A/V permissions are
112
+                // not yet granted.
140 113
                 dispatch(addPendingDeviceRequest({
141 114
                     type: 'devices',
142
-                    name: 'setDevice',
143
-                    device,
115
+                    name: 'getCurrentDevices',
144 116
                     responseCallback
145 117
                 }));
146
-
147
-                return true;
148 118
             }
119
+        });
149 120
 
150
-            const { label, id } = device;
151
-            const deviceId = label ? getDeviceIdByLabel(state, device.label) : id;
152
-
153
-            if (deviceId) {
154
-                switch (device.kind) {
155
-                case 'audioinput': {
156
-                    dispatch(setAudioInputDevice(deviceId));
157
-                    break;
158
-                }
159
-                case 'audiooutput':
160
-                    setAudioOutputDeviceId(deviceId, dispatch);
161
-                    break;
162
-                case 'videoinput':
163
-                    dispatch(setVideoInputDevice(deviceId));
164
-                    break;
165
-                default:
166
-                    result = false;
167
-                }
121
+        break;
122
+    case 'getAvailableDevices':
123
+        dispatch(getAvailableDevices()).then(devices => {
124
+            if (areDeviceLabelsInitialized(state)) {
125
+                responseCallback(groupDevicesByKind(devices));
168 126
             } else {
169
-                result = false;
127
+                // The labels are not available if the A/V permissions are
128
+                // not yet granted.
129
+                dispatch(addPendingDeviceRequest({
130
+                    type: 'devices',
131
+                    name: 'getAvailableDevices',
132
+                    responseCallback
133
+                }));
170 134
             }
135
+        });
171 136
 
172
-            responseCallback(result);
173
-            break;
137
+        break;
138
+    case 'setDevice': {
139
+        const { device } = request;
140
+
141
+        if (!conference) {
142
+            dispatch(addPendingDeviceRequest({
143
+                type: 'devices',
144
+                name: 'setDevice',
145
+                device,
146
+                responseCallback
147
+            }));
148
+
149
+            return true;
174 150
         }
175
-        default:
176 151
 
177
-            return false;
152
+        const { label, id } = device;
153
+        const deviceId = label ? getDeviceIdByLabel(state, device.label) : id;
154
+
155
+        if (deviceId) {
156
+            switch (device.kind) {
157
+            case 'audioinput': {
158
+                dispatch(setAudioInputDevice(deviceId));
159
+                break;
160
+            }
161
+            case 'audiooutput':
162
+                setAudioOutputDeviceId(deviceId, dispatch);
163
+                break;
164
+            case 'videoinput':
165
+                dispatch(setVideoInputDevice(deviceId));
166
+                break;
167
+            default:
168
+                result = false;
169
+            }
170
+        } else {
171
+            result = false;
178 172
         }
179 173
 
180
-        return true;
174
+        responseCallback(result);
175
+        break;
176
+    }
177
+    default:
178
+        return false;
181 179
     }
182 180
 
183
-    return false;
181
+    return true;
184 182
 }
183
+

+ 3
- 3
react/features/device-selection/middleware.js Просмотреть файл

@@ -18,17 +18,17 @@ MiddlewareRegistry.register(store => next => action => {
18 18
     if (action.type === UPDATE_DEVICE_LIST) {
19 19
         const state = store.getState();
20 20
         const { popupDialogData } = state['features/device-selection'];
21
-        const { devices } = state['features/base/devices'];
21
+        const { availableDevices } = state['features/base/devices'];
22 22
 
23 23
         if (popupDialogData) {
24 24
             popupDialogData.transport.sendEvent({
25 25
                 name: 'deviceListChanged',
26
-                devices
26
+                devices: availableDevices
27 27
             });
28 28
         }
29 29
 
30 30
         if (typeof APP !== 'undefined') {
31
-            APP.API.notifyDeviceListChanged(devices);
31
+            APP.API.notifyDeviceListChanged(availableDevices);
32 32
         }
33 33
     }
34 34
 

+ 4
- 4
react/features/settings/components/web/DeviceSelectionPopup.js Просмотреть файл

@@ -175,7 +175,7 @@ export default class DeviceSelectionPopup {
175 175
      * @returns {Promise}
176 176
      */
177 177
     _isDeviceChangeAvailable(deviceType) {
178
-        return isDeviceChangeAvailable(this._transport, deviceType);
178
+        return isDeviceChangeAvailable(this._transport, deviceType).catch(() => false);
179 179
     }
180 180
 
181 181
     /**
@@ -185,17 +185,17 @@ export default class DeviceSelectionPopup {
185 185
      * @returns {Promise}
186 186
      */
187 187
     _isDeviceListAvailable() {
188
-        return isDeviceListAvailable(this._transport);
188
+        return isDeviceListAvailable(this._transport).catch(() => false);
189 189
     }
190 190
 
191 191
     /**
192
-     * Returns Promise that resolves with true if the device list is available
192
+     * Returns Promise that resolves with true if multiple audio input is supported
193 193
      * and with false if not.
194 194
      *
195 195
      * @returns {Promise}
196 196
      */
197 197
     _isMultipleAudioInputSupported() {
198
-        return isMultipleAudioInputSupported(this._transport);
198
+        return isMultipleAudioInputSupported(this._transport).catch(() => false);
199 199
     }
200 200
 
201 201
     /**

Загрузка…
Отмена
Сохранить