Browse Source

feat(permissions): adjust to changes in permissions checking

master
Saúl Ibarra Corretgé 6 years ago
parent
commit
b673c4a11a

+ 43
- 17
react/features/device-selection/components/DeviceSelection.js View File

5
 import { AbstractDialogTab } from '../../base/dialog';
5
 import { AbstractDialogTab } from '../../base/dialog';
6
 import type { Props as AbstractDialogTabProps } from '../../base/dialog';
6
 import type { Props as AbstractDialogTabProps } from '../../base/dialog';
7
 import { translate } from '../../base/i18n';
7
 import { translate } from '../../base/i18n';
8
-import { createLocalTrack } from '../../base/lib-jitsi-meet';
8
+import JitsiMeetJS, { createLocalTrack } from '../../base/lib-jitsi-meet';
9
 
9
 
10
 import AudioInputPreview from './AudioInputPreview';
10
 import AudioInputPreview from './AudioInputPreview';
11
 import AudioOutputPreview from './AudioOutputPreview';
11
 import AudioOutputPreview from './AudioOutputPreview';
40
      */
40
      */
41
     disableDeviceChange: boolean,
41
     disableDeviceChange: boolean,
42
 
42
 
43
-    /**
44
-     * Function that checks whether or not a new audio input source can be
45
-     * selected.
46
-     */
47
-    hasAudioPermission: Function,
48
-
49
-    /**
50
-     * Function that checks whether or not a new video input sources can be
51
-     * selected.
52
-     */
53
-    hasVideoPermission: Function,
54
-
55
     /**
43
     /**
56
      * If true, the audio meter will not display. Necessary for browsers or
44
      * If true, the audio meter will not display. Necessary for browsers or
57
      * configurations that do not support local stats to prevent a
45
      * configurations that do not support local stats to prevent a
98
  */
86
  */
99
 type State = {
87
 type State = {
100
 
88
 
89
+    /**
90
+     * Whether or not the audio permission was granted.
91
+     */
92
+    hasAudioPermission: boolean,
93
+
94
+    /**
95
+     * Whether or not the audio permission was granted.
96
+     */
97
+    hasVideoPermission: boolean,
98
+
101
     /**
99
     /**
102
      * The JitsiTrack to use for previewing audio input.
100
      * The JitsiTrack to use for previewing audio input.
103
      */
101
      */
130
         super(props);
128
         super(props);
131
 
129
 
132
         this.state = {
130
         this.state = {
131
+            hasAudioPermission: false,
132
+            hasVideoPermission: false,
133
             previewAudioTrack: null,
133
             previewAudioTrack: null,
134
             previewVideoTrack: null,
134
             previewVideoTrack: null,
135
             previewVideoTrackError: null
135
             previewVideoTrackError: null
150
         .then(() => this.props.mountCallback && this.props.mountCallback());
150
         .then(() => this.props.mountCallback && this.props.mountCallback());
151
     }
151
     }
152
 
152
 
153
+    /**
154
+     * Checks if audio / video permissions were granted.
155
+     *
156
+     * @param {Object} prevProps - Previous props this component received.
157
+     * @param {Object} prevState - Previous state this component had.
158
+     * @returns {void}
159
+     */
160
+    componentDidUpdate(prevProps, prevState) {
161
+        const { previewAudioTrack, previewVideoTrack } = prevState;
162
+
163
+        if ((!previewAudioTrack && this.state.previewAudioTrack)
164
+                || (!previewVideoTrack && this.state.previewVideoTrack)) {
165
+            Promise.all([
166
+                JitsiMeetJS.mediaDevices.isDevicePermissionGranted('audio'),
167
+                JitsiMeetJS.mediaDevices.isDevicePermissionGranted('video')
168
+            ]).then(r => {
169
+                const [ hasAudioPermission, hasVideoPermission ] = r;
170
+
171
+                this.setState({
172
+                    hasAudioPermission,
173
+                    hasVideoPermission
174
+                });
175
+            });
176
+        }
177
+    }
178
+
153
     /**
179
     /**
154
      * Updates audio input and video input previews.
180
      * Updates audio input and video input previews.
155
      *
181
      *
316
      */
342
      */
317
     _renderSelectors() {
343
     _renderSelectors() {
318
         const { availableDevices } = this.props;
344
         const { availableDevices } = this.props;
345
+        const { hasAudioPermission, hasVideoPermission } = this.state;
319
 
346
 
320
         const configurations = [
347
         const configurations = [
321
             {
348
             {
322
                 devices: availableDevices.videoInput,
349
                 devices: availableDevices.videoInput,
323
-                hasPermission: this.props.hasVideoPermission(),
350
+                hasPermission: hasVideoPermission,
324
                 icon: 'icon-camera',
351
                 icon: 'icon-camera',
325
                 isDisabled: this.props.disableDeviceChange,
352
                 isDisabled: this.props.disableDeviceChange,
326
                 key: 'videoInput',
353
                 key: 'videoInput',
331
             },
358
             },
332
             {
359
             {
333
                 devices: availableDevices.audioInput,
360
                 devices: availableDevices.audioInput,
334
-                hasPermission: this.props.hasAudioPermission(),
361
+                hasPermission: hasAudioPermission,
335
                 icon: 'icon-microphone',
362
                 icon: 'icon-microphone',
336
                 isDisabled: this.props.disableAudioInputChange
363
                 isDisabled: this.props.disableAudioInputChange
337
                     || this.props.disableDeviceChange,
364
                     || this.props.disableDeviceChange,
346
         if (!this.props.hideAudioOutputSelect) {
373
         if (!this.props.hideAudioOutputSelect) {
347
             configurations.push({
374
             configurations.push({
348
                 devices: availableDevices.audioOutput,
375
                 devices: availableDevices.audioOutput,
349
-                hasPermission: this.props.hasAudioPermission()
350
-                    || this.props.hasVideoPermission(),
376
+                hasPermission: hasAudioPermission || hasVideoPermission,
351
                 icon: 'icon-speaker',
377
                 icon: 'icon-speaker',
352
                 isDisabled: this.props.disableDeviceChange,
378
                 isDisabled: this.props.disableDeviceChange,
353
                 key: 'audioOutput',
379
                 key: 'audioOutput',

+ 0
- 4
react/features/device-selection/functions.js View File

20
             !JitsiMeetJS.isMultipleAudioInputSupported(),
20
             !JitsiMeetJS.isMultipleAudioInputSupported(),
21
         disableDeviceChange:
21
         disableDeviceChange:
22
             !JitsiMeetJS.mediaDevices.isDeviceChangeAvailable(),
22
             !JitsiMeetJS.mediaDevices.isDeviceChangeAvailable(),
23
-        hasAudioPermission: JitsiMeetJS.mediaDevices
24
-            .isDevicePermissionGranted.bind(null, 'audio'),
25
-        hasVideoPermission: JitsiMeetJS.mediaDevices
26
-            .isDevicePermissionGranted.bind(null, 'video'),
27
         hideAudioInputPreview:
23
         hideAudioInputPreview:
28
             !JitsiMeetJS.isCollectingLocalStats(),
24
             !JitsiMeetJS.isCollectingLocalStats(),
29
         hideAudioOutputSelect: !JitsiMeetJS.mediaDevices
25
         hideAudioOutputSelect: !JitsiMeetJS.mediaDevices

+ 0
- 4
react/features/settings/DeviceSelectionPopup.js View File

64
             disableAudioInputChange: true,
64
             disableAudioInputChange: true,
65
             disableBlanketClickDismiss: true,
65
             disableBlanketClickDismiss: true,
66
             disableDeviceChange: true,
66
             disableDeviceChange: true,
67
-            hasAudioPermission: JitsiMeetJS.mediaDevices
68
-                .isDevicePermissionGranted.bind(null, 'audio'),
69
-            hasVideoPermission: JitsiMeetJS.mediaDevices
70
-                .isDevicePermissionGranted.bind(null, 'video'),
71
             hideAudioInputPreview: !JitsiMeetJS.isCollectingLocalStats(),
67
             hideAudioInputPreview: !JitsiMeetJS.isCollectingLocalStats(),
72
             hideAudioOutputSelect: true
68
             hideAudioOutputSelect: true
73
 
69
 

Loading…
Cancel
Save