소스 검색

Fire an optional JitsiMediaDevices.PERMISSION_PROMPT_IS_SHOWN event when browser shows user media permission prompt when calling createLocalTracks

j8
tsareg 8 년 전
부모
커밋
d149ba6fc5
5개의 변경된 파일99개의 추가작업 그리고 74개의 파일을 삭제
  1. 71
    61
      conference.js
  2. 1
    0
      lang/main.json
  3. 4
    2
      modules/UI/UI.js
  4. 8
    7
      modules/UI/gum_overlay/UserMediaPermissionsGuidanceOverlay.js
  5. 15
    4
      modules/devices/mediaDeviceHelper.js

+ 71
- 61
conference.js 파일 보기

27
 
27
 
28
 import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/LargeVideo";
28
 import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/LargeVideo";
29
 
29
 
30
-const USER_MEDIA_PERMISSIONS_GUIDANCE_OVERLAY_TIMEOUT = 500;
31
-
32
 /**
30
 /**
33
  * Known custom conference commands.
31
  * Known custom conference commands.
34
  */
32
  */
68
  */
66
  */
69
 function createInitialLocalTracksAndConnect(roomName) {
67
 function createInitialLocalTracksAndConnect(roomName) {
70
     let audioAndVideoError,
68
     let audioAndVideoError,
71
-        audioOnlyError,
72
-        tracksCreated;
69
+        audioOnlyError;
70
+
71
+    JitsiMeetJS.mediaDevices.addEventListener(
72
+        JitsiMeetJS.events.mediaDevices.PERMISSION_PROMPT_IS_SHOWN,
73
+        browser => APP.UI.showUserMediaPermissionsGuidanceOverlay(browser));
73
 
74
 
74
     // First try to retrieve both audio and video.
75
     // First try to retrieve both audio and video.
75
-    let tryCreateLocalTracks = createLocalTracks(['audio', 'video'])
76
+    let tryCreateLocalTracks = createLocalTracks(
77
+            { devices: ['audio', 'video'] }, true)
76
         .catch(err => {
78
         .catch(err => {
77
             // If failed then try to retrieve only audio.
79
             // If failed then try to retrieve only audio.
78
             audioAndVideoError = err;
80
             audioAndVideoError = err;
79
-            return createLocalTracks(['audio']);
81
+            return createLocalTracks({ devices: ['audio'] }, true);
80
         })
82
         })
81
         .catch(err => {
83
         .catch(err => {
82
             // If audio failed too then just return empty array for tracks.
84
             // If audio failed too then just return empty array for tracks.
83
             audioOnlyError = err;
85
             audioOnlyError = err;
84
             return [];
86
             return [];
85
-        })
86
-        .then(tracks => {
87
-            tracksCreated = true;
88
-            return tracks;
89
         });
87
         });
90
 
88
 
91
-    window.setTimeout(() => {
92
-        if (!audioAndVideoError && !audioOnlyError && !tracksCreated) {
93
-            APP.UI.showUserMediaPermissionsGuidanceOverlay();
94
-        }
95
-    }, USER_MEDIA_PERMISSIONS_GUIDANCE_OVERLAY_TIMEOUT);
96
-
97
     return Promise.all([ tryCreateLocalTracks, connect(roomName) ])
89
     return Promise.all([ tryCreateLocalTracks, connect(roomName) ])
98
         .then(([tracks, con]) => {
90
         .then(([tracks, con]) => {
99
             APP.UI.hideUserMediaPermissionsGuidanceOverlay();
91
             APP.UI.hideUserMediaPermissionsGuidanceOverlay();
245
 
237
 
246
 /**
238
 /**
247
  * Create local tracks of specified types.
239
  * Create local tracks of specified types.
248
- * @param {string[]} devices - required track types ('audio', 'video' etc.)
249
- * @param {string|null} [cameraDeviceId] - camera device id, if undefined - one
250
- *      from settings will be used
251
- * @param {string|null} [micDeviceId] - microphone device id, if undefined - one
252
- *      from settings will be used
240
+ * @param {Object} options
241
+ * @param {string[]} options.devices - required track types
242
+ *      ('audio', 'video' etc.)
243
+ * @param {string|null} (options.cameraDeviceId) - camera device id, if
244
+ *      undefined - one from settings will be used
245
+ * @param {string|null} (options.micDeviceId) - microphone device id, if
246
+ *      undefined - one from settings will be used
247
+ * @param {boolean} (checkForPermissionPrompt) - if lib-jitsi-meet should check
248
+ *      for gUM permission prompt
253
  * @returns {Promise<JitsiLocalTrack[]>}
249
  * @returns {Promise<JitsiLocalTrack[]>}
254
  */
250
  */
255
-function createLocalTracks (devices, cameraDeviceId, micDeviceId) {
256
-    return JitsiMeetJS.createLocalTracks({
257
-        // copy array to avoid mutations inside library
258
-        devices: devices.slice(0),
259
-        resolution: config.resolution,
260
-        cameraDeviceId: typeof cameraDeviceId === 'undefined'
261
-            || cameraDeviceId === null
251
+function createLocalTracks (options, checkForPermissionPrompt) {
252
+    options || (options = {});
253
+
254
+    return JitsiMeetJS
255
+        .createLocalTracks({
256
+            // copy array to avoid mutations inside library
257
+            devices: options.devices.slice(0),
258
+            resolution: config.resolution,
259
+            cameraDeviceId: typeof options.cameraDeviceId === 'undefined' ||
260
+                    options.cameraDeviceId === null
262
                 ? APP.settings.getCameraDeviceId()
261
                 ? APP.settings.getCameraDeviceId()
263
-                : cameraDeviceId,
264
-        micDeviceId: typeof micDeviceId === 'undefined' || micDeviceId === null
265
-            ? APP.settings.getMicDeviceId()
266
-            : micDeviceId,
267
-        // adds any ff fake device settings if any
268
-        firefox_fake_device: config.firefox_fake_device
269
-    }).catch(function (err) {
270
-        console.error('failed to create local tracks', ...devices, err);
271
-        return Promise.reject(err);
272
-    });
273
-}
262
+                : options.cameraDeviceId,
263
+            micDeviceId: typeof options.micDeviceId === 'undefined' ||
264
+                    options.micDeviceId === null
265
+                ? APP.settings.getMicDeviceId()
266
+                : options.micDeviceId,
267
+            // adds any ff fake device settings if any
268
+            firefox_fake_device: config.firefox_fake_device
269
+        }, checkForPermissionPrompt)
270
+        .catch(function (err) {
271
+            console.error(
272
+                'failed to create local tracks', options.devices, err);
273
+            return Promise.reject(err);
274
+        });
275
+    }
274
 
276
 
275
 /**
277
 /**
276
  * Changes the email for the local user
278
  * Changes the email for the local user
861
         this.videoSwitchInProgress = true;
863
         this.videoSwitchInProgress = true;
862
 
864
 
863
         if (shareScreen) {
865
         if (shareScreen) {
864
-            createLocalTracks(['desktop']).then(([stream]) => {
866
+            createLocalTracks({ devices: ['desktop'] }).then(([stream]) => {
865
                 stream.on(
867
                 stream.on(
866
                     TrackEvents.LOCAL_TRACK_STOPPED,
868
                     TrackEvents.LOCAL_TRACK_STOPPED,
867
                     () => {
869
                     () => {
918
                 APP.UI.messageHandler.openDialog(dialogTitle, dialogTxt, false);
920
                 APP.UI.messageHandler.openDialog(dialogTitle, dialogTxt, false);
919
             });
921
             });
920
         } else {
922
         } else {
921
-            createLocalTracks(['video']).then(
923
+            createLocalTracks({ devices: ['video'] }).then(
922
                 ([stream]) => this.useVideoStream(stream)
924
                 ([stream]) => this.useVideoStream(stream)
923
             ).then(() => {
925
             ).then(() => {
924
                 this.videoSwitchInProgress = false;
926
                 this.videoSwitchInProgress = false;
1260
         APP.UI.addListener(
1262
         APP.UI.addListener(
1261
             UIEvents.VIDEO_DEVICE_CHANGED,
1263
             UIEvents.VIDEO_DEVICE_CHANGED,
1262
             (cameraDeviceId) => {
1264
             (cameraDeviceId) => {
1263
-                createLocalTracks(['video'], cameraDeviceId, null)
1264
-                    .then(([stream]) => {
1265
-                        this.useVideoStream(stream);
1266
-                        console.log('switched local video device');
1267
-                        APP.settings.setCameraDeviceId(cameraDeviceId);
1268
-                    })
1269
-                    .catch((err) => {
1270
-                        APP.UI.showDeviceErrorDialog(null, err);
1271
-                        APP.UI.setSelectedCameraFromSettings();
1272
-                    });
1265
+                createLocalTracks({
1266
+                    devices: ['video'],
1267
+                    cameraDeviceId: cameraDeviceId,
1268
+                    micDeviceId: null
1269
+                })
1270
+                .then(([stream]) => {
1271
+                    this.useVideoStream(stream);
1272
+                    console.log('switched local video device');
1273
+                    APP.settings.setCameraDeviceId(cameraDeviceId);
1274
+                })
1275
+                .catch((err) => {
1276
+                    APP.UI.showDeviceErrorDialog(null, err);
1277
+                    APP.UI.setSelectedCameraFromSettings();
1278
+                });
1273
             }
1279
             }
1274
         );
1280
         );
1275
 
1281
 
1276
         APP.UI.addListener(
1282
         APP.UI.addListener(
1277
             UIEvents.AUDIO_DEVICE_CHANGED,
1283
             UIEvents.AUDIO_DEVICE_CHANGED,
1278
             (micDeviceId) => {
1284
             (micDeviceId) => {
1279
-                createLocalTracks(['audio'], null, micDeviceId)
1280
-                    .then(([stream]) => {
1281
-                        this.useAudioStream(stream);
1282
-                        console.log('switched local audio device');
1283
-                        APP.settings.setMicDeviceId(micDeviceId);
1284
-                    })
1285
-                    .catch((err) => {
1286
-                        APP.UI.showDeviceErrorDialog(err, null);
1287
-                        APP.UI.setSelectedMicFromSettings();
1288
-                    });
1285
+                createLocalTracks({
1286
+                    devices: ['audio'],
1287
+                    cameraDeviceId: null,
1288
+                    micDeviceId: micDeviceId
1289
+                })
1290
+                .then(([stream]) => {
1291
+                    this.useAudioStream(stream);
1292
+                    console.log('switched local audio device');
1293
+                    APP.settings.setMicDeviceId(micDeviceId);
1294
+                })
1295
+                .catch((err) => {
1296
+                    APP.UI.showDeviceErrorDialog(err, null);
1297
+                    APP.UI.setSelectedMicFromSettings();
1298
+                });
1289
             }
1299
             }
1290
         );
1300
         );
1291
 
1301
 

+ 1
- 0
lang/main.json 파일 보기

14
     "userMedia": {
14
     "userMedia": {
15
       "react-nativeGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Allow</i> button",
15
       "react-nativeGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Allow</i> button",
16
       "chromeGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Allow</i> button",
16
       "chromeGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Allow</i> button",
17
+      "androidGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Allow</i> button",
17
       "firefoxGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Share Selected Device</i> button",
18
       "firefoxGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Share Selected Device</i> button",
18
       "operaGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Allow</i> button",
19
       "operaGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Allow</i> button",
19
       "iexplorerGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>OK</i> button",
20
       "iexplorerGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>OK</i> button",

+ 4
- 2
modules/UI/UI.js 파일 보기

1388
 
1388
 
1389
 /**
1389
 /**
1390
  * Shows browser-specific overlay with guidance how to proceed with gUM prompt.
1390
  * Shows browser-specific overlay with guidance how to proceed with gUM prompt.
1391
+ * @param {string} browser - name of browser for which to show the guidance
1392
+ *      overlay.
1391
  */
1393
  */
1392
-UI.showUserMediaPermissionsGuidanceOverlay = function () {
1393
-    GumPermissionsOverlay.show();
1394
+UI.showUserMediaPermissionsGuidanceOverlay = function (browser) {
1395
+    GumPermissionsOverlay.show(browser);
1394
 };
1396
 };
1395
 
1397
 
1396
 /**
1398
 /**

+ 8
- 7
modules/UI/gum_overlay/UserMediaPermissionsGuidanceOverlay.js 파일 보기

5
 /**
5
 /**
6
  * Internal function that constructs overlay with guidance how to proceed with
6
  * Internal function that constructs overlay with guidance how to proceed with
7
  * gUM prompt.
7
  * gUM prompt.
8
+ * @param {string} browser - name of browser for which to construct the
9
+ *      guidance overlay.
8
  */
10
  */
9
-function buildOverlayHtml() {
10
-    let browser = JitsiMeetJS.environment.getBrowserType()
11
-            .split('rtc_browser.')[1] || 'chrome';
12
-
11
+function buildOverlayHtml(browser) {
13
     $overlay = $(`
12
     $overlay = $(`
14
         <div class='overlay_container'>
13
         <div class='overlay_container'>
15
             <div class='overlay overlay_transparent' />
14
             <div class='overlay overlay_transparent' />
28
     /**
27
     /**
29
      * Shows browser-specific overlay with guidance how to proceed with
28
      * Shows browser-specific overlay with guidance how to proceed with
30
      * gUM prompt.
29
      * gUM prompt.
30
+     * @param {string} browser - name of browser for which to show the
31
+     *      guidance overlay.
31
      */
32
      */
32
-    show() {
33
-        !$overlay && buildOverlayHtml();
33
+    show(browser) {
34
+        !$overlay && buildOverlayHtml(browser);
34
 
35
 
35
-        $overlay && $overlay.appendTo('body');
36
+        !$overlay.parents('body').length && $overlay.appendTo('body');
36
     },
37
     },
37
 
38
 
38
     /**
39
     /**

+ 15
- 4
modules/devices/mediaDeviceHelper.js 파일 보기

191
 
191
 
192
         if (audioRequested && videoRequested) {
192
         if (audioRequested && videoRequested) {
193
             // First we try to create both audio and video tracks together.
193
             // First we try to create both audio and video tracks together.
194
-            return createLocalTracks(
195
-                    ['audio', 'video'], cameraDeviceId, micDeviceId)
194
+            return createLocalTracks({
195
+                        devices: ['audio', 'video'],
196
+                        cameraDeviceId: cameraDeviceId,
197
+                        micDeviceId: micDeviceId
198
+                    })
196
                     // If we fail to do this, try to create them separately.
199
                     // If we fail to do this, try to create them separately.
197
                     .catch(() => Promise.all(
200
                     .catch(() => Promise.all(
198
                         [createAudioTrack(false), createVideoTrack(false)]))
201
                         [createAudioTrack(false), createVideoTrack(false)]))
213
         }
216
         }
214
 
217
 
215
         function createAudioTrack(showError) {
218
         function createAudioTrack(showError) {
216
-            return createLocalTracks(['audio'], null, micDeviceId)
219
+            return createLocalTracks({
220
+                    devices: ['audio'],
221
+                    cameraDeviceId: null,
222
+                    micDeviceId: micDeviceId
223
+                })
217
                 .catch(err => {
224
                 .catch(err => {
218
                     audioTrackError = err;
225
                     audioTrackError = err;
219
                     showError && APP.UI.showDeviceErrorDialog(err, null);
226
                     showError && APP.UI.showDeviceErrorDialog(err, null);
222
         }
229
         }
223
 
230
 
224
         function createVideoTrack(showError) {
231
         function createVideoTrack(showError) {
225
-            return createLocalTracks(['video'], cameraDeviceId, null)
232
+            return createLocalTracks({
233
+                    devices: ['video'],
234
+                    cameraDeviceId: cameraDeviceId,
235
+                    micDeviceId: null
236
+                })
226
                 .catch(err => {
237
                 .catch(err => {
227
                     videoTrackError = err;
238
                     videoTrackError = err;
228
                     showError && APP.UI.showDeviceErrorDialog(null, err);
239
                     showError && APP.UI.showDeviceErrorDialog(null, err);

Loading…
취소
저장