瀏覽代碼

Fix typos around permissions (#883)

* fix(permissions): remove space from requesting camera

Chrome errors on querying permissions with "camera "
because it does not match an expected enum.

* fix(permissions): check value of returned PermissionStatus

A permissions query returns an object with a status/status
of whether or not permission has been granted. Check that
value in addition to the existence of the object.

* fix(permissions): prevent permission being set to undefined

* ref(permissions): move permissions strings to constants
release-8443
virtuacoplenny 6 年之前
父節點
當前提交
83af6e78a8
No account linked to committer's email address
共有 2 個文件被更改,包括 30 次插入8 次删除
  1. 26
    6
      JitsiMediaDevices.js
  2. 4
    2
      modules/RTC/RTCUtils.js

+ 26
- 6
JitsiMediaDevices.js 查看文件

8
 
8
 
9
 import * as JitsiMediaDevicesEvents from './JitsiMediaDevicesEvents';
9
 import * as JitsiMediaDevicesEvents from './JitsiMediaDevicesEvents';
10
 
10
 
11
+const AUDIO_PERMISSION_NAME = 'microphone';
12
+const PERMISSION_GRANTED_STATUS = 'granted';
13
+const VIDEO_PERMISSION_NAME = 'camera';
14
+
11
 /**
15
 /**
12
  * Media devices utilities for Jitsi.
16
  * Media devices utilities for Jitsi.
13
  */
17
  */
47
                 return;
51
                 return;
48
             }
52
             }
49
 
53
 
50
-            navigator.permissions.query({ name: 'camera ' })
54
+            navigator.permissions.query({ name: VIDEO_PERMISSION_NAME })
51
                 .then(() => resolve(true), () => resolve(false));
55
                 .then(() => resolve(true), () => resolve(false));
52
         });
56
         });
53
     }
57
     }
142
                 switch (type) {
146
                 switch (type) {
143
                 case MediaType.VIDEO:
147
                 case MediaType.VIDEO:
144
                     promises.push(
148
                     promises.push(
145
-                        navigator.permissions.query({ name: 'camera' }));
149
+                        navigator.permissions.query({
150
+                            name: VIDEO_PERMISSION_NAME
151
+                        }));
146
                     break;
152
                     break;
147
                 case MediaType.AUDIO:
153
                 case MediaType.AUDIO:
148
                     promises.push(
154
                     promises.push(
149
-                        navigator.permissions.query({ name: 'microphone' }));
155
+                        navigator.permissions.query({
156
+                            name: AUDIO_PERMISSION_NAME
157
+                        }));
150
                     break;
158
                     break;
151
                 default:
159
                 default:
152
                     promises.push(
160
                     promises.push(
153
-                        navigator.permissions.query({ name: 'camera' }));
161
+                        navigator.permissions.query({
162
+                            name: VIDEO_PERMISSION_NAME
163
+                        }));
154
                     promises.push(
164
                     promises.push(
155
-                        navigator.permissions.query({ name: 'microphone' }));
165
+                        navigator.permissions.query({
166
+                            name: AUDIO_PERMISSION_NAME
167
+                        }));
156
                 }
168
                 }
157
 
169
 
158
                 Promise.all(promises).then(
170
                 Promise.all(promises).then(
159
-                    r => resolve(r.every(Boolean)),
171
+                    results => resolve(results.every(permissionStatus => {
172
+                        // The status attribute is deprecated, and state
173
+                        // should be used instead, but check both for now
174
+                        // for backwards compatibility.
175
+                        const grantStatus = permissionStatus.state
176
+                            || permissionStatus.status;
177
+
178
+                        return grantStatus === PERMISSION_GRANTED_STATUS;
179
+                    })),
160
                     () => resolve(false)
180
                     () => resolve(false)
161
                 );
181
                 );
162
             });
182
             });

+ 4
- 2
modules/RTC/RTCUtils.js 查看文件

494
  * @param stream the stream we received from calling getUserMedia.
494
  * @param stream the stream we received from calling getUserMedia.
495
  */
495
  */
496
 function updateGrantedPermissions(um, stream) {
496
 function updateGrantedPermissions(um, stream) {
497
-    const audioTracksReceived = stream && stream.getAudioTracks().length > 0;
498
-    const videoTracksReceived = stream && stream.getVideoTracks().length > 0;
497
+    const audioTracksReceived
498
+        = Boolean(stream) && stream.getAudioTracks().length > 0;
499
+    const videoTracksReceived
500
+        = Boolean(stream) && stream.getVideoTracks().length > 0;
499
     const grantedPermissions = {};
501
     const grantedPermissions = {};
500
 
502
 
501
     if (um.indexOf('video') !== -1) {
503
     if (um.indexOf('video') !== -1) {

Loading…
取消
儲存