Pārlūkot izejas kodu

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

j8
Hristo Terezov 6 gadus atpakaļ
vecāks
revīzija
829e5597d5

+ 2
- 2
conference.js Parādīt failu

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

+ 2
- 2
doc/api.md Parādīt failu

81
 
81
 
82
 ### Controlling the embedded Jitsi Meet Conference
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
 * **getAvailableDevices** - Retrieve a list of available devices.
85
 * **getAvailableDevices** - Retrieve a list of available devices.
86
 
86
 
87
 ```javascript
87
 ```javascript
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
 ```javascript
156
 ```javascript
157
 api.isMultipleAudioInputSupported().then(function(isMultipleAudioInputSupported) {
157
 api.isMultipleAudioInputSupported().then(function(isMultipleAudioInputSupported) {

+ 2
- 2
modules/API/API.js Parādīt failu

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

+ 17
- 11
modules/API/external/external_api.js Parādīt failu

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
      * @returns {Promise}
614
      * @returns {Promise}
615
      */
615
      */
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
      * and with false if not.
665
      * and with false if not.
666
      *
666
      *
667
      * @returns {Promise}
667
      * @returns {Promise}
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
      * @param {string} deviceId - The id of the new device.
844
      * @param {string} deviceId - The id of the new device.
843
      * @returns {Promise}
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
      * @param {string} deviceId - The id of the new device.
856
      * @param {string} deviceId - The id of the new device.
853
      * @returns {Promise}
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
      * @param {string} deviceId - The id of the new device.
868
      * @param {string} deviceId - The id of the new device.
863
      * @returns {Promise}
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 Parādīt failu

55
         deviceType,
55
         deviceType,
56
         type: 'devices',
56
         type: 'devices',
57
         name: 'isDeviceChangeAvailable'
57
         name: 'isDeviceChangeAvailable'
58
-    }).catch(e => {
59
-        logger.error(e);
60
-
61
-        return false;
62
     });
58
     });
63
 }
59
 }
64
 
60
 
74
     return transport.sendRequest({
70
     return transport.sendRequest({
75
         type: 'devices',
71
         type: 'devices',
76
         name: 'isDeviceListAvailable'
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
  * and with false if not.
78
  * and with false if not.
87
  *
79
  *
88
  * @param {Transport} transport - The @code{Transport} instance responsible for
80
  * @param {Transport} transport - The @code{Transport} instance responsible for
93
     return transport.sendRequest({
85
     return transport.sendRequest({
94
         type: 'devices',
86
         type: 'devices',
95
         name: 'isMultipleAudioInputSupported'
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 Parādīt failu

46
  * The type of Redux action which will remove all pending device requests.
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
 export const REMOVE_PENDING_DEVICE_REQUESTS = 'REMOVE_PENDING_DEVICE_REQUESTS';
52
 export const REMOVE_PENDING_DEVICE_REQUESTS = 'REMOVE_PENDING_DEVICE_REQUESTS';

+ 3
- 2
react/features/base/devices/functions.js Parādīt failu

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

+ 2
- 2
react/features/base/devices/middleware.js Parādīt failu

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

+ 2
- 2
react/features/base/devices/reducer.js Parādīt failu

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

+ 2
- 2
react/features/device-selection/actions.js Parādīt failu

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

+ 109
- 110
react/features/device-selection/functions.js Parādīt failu

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'].devices,
31
+        availableDevices: state['features/base/devices'].availableDevices,
32
         disableAudioInputChange:
32
         disableAudioInputChange:
33
             !JitsiMeetJS.isMultipleAudioInputSupported(),
33
             !JitsiMeetJS.isMultipleAudioInputSupported(),
34
         disableDeviceChange:
34
         disableDeviceChange:
52
  * @param {Object} request - The request to be processed.
52
  * @param {Object} request - The request to be processed.
53
  * @param {Function} responseCallback - The callback that will send the
53
  * @param {Function} responseCallback - The callback that will send the
54
  * response.
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
         dispatch: Dispatch<any>,
58
         dispatch: Dispatch<any>,
59
         getState: Function,
59
         getState: Function,
60
         request: Object,
60
         request: Object,
61
         responseCallback: Function) {
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
                 dispatch(addPendingDeviceRequest({
113
                 dispatch(addPendingDeviceRequest({
141
                     type: 'devices',
114
                     type: 'devices',
142
-                    name: 'setDevice',
143
-                    device,
115
+                    name: 'getCurrentDevices',
144
                     responseCallback
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
             } else {
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 Parādīt failu

18
     if (action.type === UPDATE_DEVICE_LIST) {
18
     if (action.type === UPDATE_DEVICE_LIST) {
19
         const state = store.getState();
19
         const state = store.getState();
20
         const { popupDialogData } = state['features/device-selection'];
20
         const { popupDialogData } = state['features/device-selection'];
21
-        const { devices } = state['features/base/devices'];
21
+        const { availableDevices } = state['features/base/devices'];
22
 
22
 
23
         if (popupDialogData) {
23
         if (popupDialogData) {
24
             popupDialogData.transport.sendEvent({
24
             popupDialogData.transport.sendEvent({
25
                 name: 'deviceListChanged',
25
                 name: 'deviceListChanged',
26
-                devices
26
+                devices: availableDevices
27
             });
27
             });
28
         }
28
         }
29
 
29
 
30
         if (typeof APP !== 'undefined') {
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 Parādīt failu

175
      * @returns {Promise}
175
      * @returns {Promise}
176
      */
176
      */
177
     _isDeviceChangeAvailable(deviceType) {
177
     _isDeviceChangeAvailable(deviceType) {
178
-        return isDeviceChangeAvailable(this._transport, deviceType);
178
+        return isDeviceChangeAvailable(this._transport, deviceType).catch(() => false);
179
     }
179
     }
180
 
180
 
181
     /**
181
     /**
185
      * @returns {Promise}
185
      * @returns {Promise}
186
      */
186
      */
187
     _isDeviceListAvailable() {
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
      * and with false if not.
193
      * and with false if not.
194
      *
194
      *
195
      * @returns {Promise}
195
      * @returns {Promise}
196
      */
196
      */
197
     _isMultipleAudioInputSupported() {
197
     _isMultipleAudioInputSupported() {
198
-        return isMultipleAudioInputSupported(this._transport);
198
+        return isMultipleAudioInputSupported(this._transport).catch(() => false);
199
     }
199
     }
200
 
200
 
201
     /**
201
     /**

Notiek ielāde…
Atcelt
Saglabāt