소스 검색

fix(gum) update permissions prompt detection

Fire PERMISSION_PROMPT_IS_SHOWN when none of the devices have a label
Fire a new SLOW_GET_USER_MEDIA event if the timeout for getUserMedia is exceeded

Update JitsiMeetJS.createLocalTracks to include the options for firing the above events
in the provided options argument. Deprecate the firePermissionPromptIsShownEvent flag in
method's signature
dev1
Tudor-Ovidiu Avram 4 년 전
부모
커밋
41a5ee63c9
4개의 변경된 파일44개의 추가작업 그리고 18개의 파일을 삭제
  1. 2
    0
      JitsiMediaDevicesEvents.js
  2. 23
    17
      JitsiMeetJS.js
  3. 8
    0
      modules/RTC/RTC.js
  4. 11
    1
      modules/RTC/RTCUtils.js

+ 2
- 0
JitsiMediaDevicesEvents.js 파일 보기

@@ -30,3 +30,5 @@ export const PERMISSIONS_CHANGED = 'rtc.permissions_changed';
30 30
  */
31 31
 export const PERMISSION_PROMPT_IS_SHOWN
32 32
     = 'mediaDevices.permissionPromptIsShown';
33
+
34
+export const SLOW_GET_USER_MEDIA = 'mediaDevices.slowGetUserMedia';

+ 23
- 17
JitsiMeetJS.js 파일 보기

@@ -46,7 +46,7 @@ const logger = Logger.getLogger(__filename);
46 46
  * The amount of time to wait until firing
47 47
  * {@link JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN} event.
48 48
  */
49
-const USER_MEDIA_PERMISSION_PROMPT_TIMEOUT = 1000;
49
+const USER_MEDIA_SLOW_PROMISE_TIMEOUT = 1000;
50 50
 
51 51
 /**
52 52
  * Gets the next lowest desirable resolution to try for a camera. If the given
@@ -300,6 +300,10 @@ export default _mergeNamespaceAndModule({
300 300
      * which should be created. should be created or some additional
301 301
      * configurations about resolution for example.
302 302
      * @param {Array} options.effects optional effects array for the track
303
+     * @param {boolean} options.firePermissionPromptIsShownEvent - if event
304
+     * JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN should be fired
305
+     * @param {boolean} options.fireSlowPromiseEvent - if event
306
+     * JitsiMediaDevicesEvents.USER_MEDIA_SLOW_PROMISE_TIMEOUT should be fired
303 307
      * @param {Array} options.devices the devices that will be requested
304 308
      * @param {string} options.resolution resolution constraints
305 309
      * @param {string} options.cameraDeviceId
@@ -322,26 +326,29 @@ export default _mergeNamespaceAndModule({
322 326
      * will finish the execution. If checkAgain returns false, createLocalTracks
323 327
      * will finish the execution with rejected Promise.
324 328
      *
325
-     * @param {boolean} (firePermissionPromptIsShownEvent) - if event
326
-     * JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN should be fired
329
+     * @deprecated old firePermissionPromptIsShownEvent
327 330
      * @param originalOptions - internal use only, to be able to store the
328 331
      * originally requested options.
329 332
      * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>} A promise
330 333
      * that returns an array of created JitsiTracks if resolved, or a
331 334
      * JitsiConferenceError if rejected.
332 335
      */
333
-    createLocalTracks(
334
-            options = {}, firePermissionPromptIsShownEvent, originalOptions) {
336
+    createLocalTracks(options = {}, oldfirePermissionPromptIsShownEvent, originalOptions) {
335 337
         let promiseFulfilled = false;
336 338
 
337
-        if (firePermissionPromptIsShownEvent === true) {
339
+        const { firePermissionPromptIsShownEvent, fireSlowPromiseEvent, ...restOptions } = options;
340
+        const firePermissionPrompt = firePermissionPromptIsShownEvent || oldfirePermissionPromptIsShownEvent;
341
+
342
+        if (firePermissionPrompt && !RTC.arePermissionsGrantedForAvailableDevices()) {
343
+            JitsiMediaDevices.emitEvent(
344
+                JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN,
345
+                browser.getName());
346
+        } else if (fireSlowPromiseEvent) {
338 347
             window.setTimeout(() => {
339 348
                 if (!promiseFulfilled) {
340
-                    JitsiMediaDevices.emitEvent(
341
-                        JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN,
342
-                        browser.getName());
349
+                    JitsiMediaDevices.emitEvent(JitsiMediaDevicesEvents.SLOW_GET_USER_MEDIA);
343 350
                 }
344
-            }, USER_MEDIA_PERMISSION_PROMPT_TIMEOUT);
351
+            }, USER_MEDIA_SLOW_PROMISE_TIMEOUT);
345 352
         }
346 353
 
347 354
         if (!window.connectionTimes) {
@@ -350,7 +357,7 @@ export default _mergeNamespaceAndModule({
350 357
         window.connectionTimes['obtainPermissions.start']
351 358
             = window.performance.now();
352 359
 
353
-        return RTC.obtainAudioAndVideoPermissions(options)
360
+        return RTC.obtainAudioAndVideoPermissions(restOptions)
354 361
             .then(tracks => {
355 362
                 promiseFulfilled = true;
356 363
 
@@ -360,7 +367,7 @@ export default _mergeNamespaceAndModule({
360 367
                 Statistics.sendAnalytics(
361 368
                     createGetUserMediaEvent(
362 369
                         'success',
363
-                        getAnalyticsAttributesFromOptions(options)));
370
+                        getAnalyticsAttributesFromOptions(restOptions)));
364 371
 
365 372
                 if (!RTC.options.disableAudioLevels) {
366 373
                     for (let i = 0; i < tracks.length; i++) {
@@ -408,11 +415,11 @@ export default _mergeNamespaceAndModule({
408 415
 
409 416
                 if (error.name === JitsiTrackErrors.UNSUPPORTED_RESOLUTION
410 417
                     && !browser.usesNewGumFlow()) {
411
-                    const oldResolution = options.resolution || '720';
418
+                    const oldResolution = restOptions.resolution || '720';
412 419
                     const newResolution = getLowerResolution(oldResolution);
413 420
 
414 421
                     if (newResolution !== null) {
415
-                        options.resolution = newResolution;
422
+                        restOptions.resolution = newResolution;
416 423
 
417 424
                         logger.debug(
418 425
                             'Retry createLocalTracks with resolution',
@@ -427,9 +434,8 @@ export default _mergeNamespaceAndModule({
427 434
                             }));
428 435
 
429 436
                         return this.createLocalTracks(
430
-                            options,
431
-                            undefined,
432
-                            originalOptions || Object.assign({}, options));
437
+                            restOptions,
438
+                            originalOptions || Object.assign({}, restOptions));
433 439
                     }
434 440
 
435 441
                     // We tried everything. If there is a mandatory device id,

+ 8
- 0
modules/RTC/RTC.js 파일 보기

@@ -742,6 +742,14 @@ export default class RTC extends Listenable {
742 742
         return RTCUtils.getCurrentlyAvailableMediaDevices();
743 743
     }
744 744
 
745
+    /**
746
+     * Returns whether available devices have permissions granted
747
+     * @returns {Boolean}
748
+     */
749
+    static arePermissionsGrantedForAvailableDevices() {
750
+        return RTCUtils.arePermissionsGrantedForAvailableDevices();
751
+    }
752
+
745 753
     /**
746 754
      * Returns event data for device to be reported to stats.
747 755
      * @returns {MediaDeviceInfo} device.

+ 11
- 1
modules/RTC/RTCUtils.js 파일 보기

@@ -120,7 +120,9 @@ function initEnumerateDevicesWithCallback() {
120 120
                 .then(devices => {
121 121
                     updateKnownDevices(devices);
122 122
                     callback(devices);
123
-                }, () => {
123
+                })
124
+                .catch(error => {
125
+                    logger.warn(`Failed to  enumerate devices. ${error}`);
124 126
                     updateKnownDevices([]);
125 127
                     callback([]);
126 128
                 });
@@ -1500,6 +1502,14 @@ class RTCUtils extends Listenable {
1500 1502
         return availableDevices;
1501 1503
     }
1502 1504
 
1505
+    /**
1506
+     * Returns whether available devices have permissions granted
1507
+     * @returns {Boolean}
1508
+     */
1509
+    arePermissionsGrantedForAvailableDevices() {
1510
+        return availableDevices.some(device => Boolean(device.label));
1511
+    }
1512
+
1503 1513
     /**
1504 1514
      * Returns event data for device to be reported to stats.
1505 1515
      * @returns {MediaDeviceInfo} device.

Loading…
취소
저장