瀏覽代碼

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

j8
tsareg 8 年之前
父節點
當前提交
d149ba6fc5

+ 71
- 61
conference.js 查看文件

@@ -27,8 +27,6 @@ let room, connection, localAudio, localVideo, roomLocker;
27 27
 
28 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 31
  * Known custom conference commands.
34 32
  */
@@ -68,32 +66,26 @@ function connect(roomName) {
68 66
  */
69 67
 function createInitialLocalTracksAndConnect(roomName) {
70 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 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 78
         .catch(err => {
77 79
             // If failed then try to retrieve only audio.
78 80
             audioAndVideoError = err;
79
-            return createLocalTracks(['audio']);
81
+            return createLocalTracks({ devices: ['audio'] }, true);
80 82
         })
81 83
         .catch(err => {
82 84
             // If audio failed too then just return empty array for tracks.
83 85
             audioOnlyError = err;
84 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 89
     return Promise.all([ tryCreateLocalTracks, connect(roomName) ])
98 90
         .then(([tracks, con]) => {
99 91
             APP.UI.hideUserMediaPermissionsGuidanceOverlay();
@@ -245,32 +237,42 @@ function hangup (requestFeedback = false) {
245 237
 
246 238
 /**
247 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 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 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 278
  * Changes the email for the local user
@@ -861,7 +863,7 @@ export default {
861 863
         this.videoSwitchInProgress = true;
862 864
 
863 865
         if (shareScreen) {
864
-            createLocalTracks(['desktop']).then(([stream]) => {
866
+            createLocalTracks({ devices: ['desktop'] }).then(([stream]) => {
865 867
                 stream.on(
866 868
                     TrackEvents.LOCAL_TRACK_STOPPED,
867 869
                     () => {
@@ -918,7 +920,7 @@ export default {
918 920
                 APP.UI.messageHandler.openDialog(dialogTitle, dialogTxt, false);
919 921
             });
920 922
         } else {
921
-            createLocalTracks(['video']).then(
923
+            createLocalTracks({ devices: ['video'] }).then(
922 924
                 ([stream]) => this.useVideoStream(stream)
923 925
             ).then(() => {
924 926
                 this.videoSwitchInProgress = false;
@@ -1260,32 +1262,40 @@ export default {
1260 1262
         APP.UI.addListener(
1261 1263
             UIEvents.VIDEO_DEVICE_CHANGED,
1262 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 1282
         APP.UI.addListener(
1277 1283
             UIEvents.AUDIO_DEVICE_CHANGED,
1278 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,6 +14,7 @@
14 14
     "userMedia": {
15 15
       "react-nativeGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Allow</i> button",
16 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 18
       "firefoxGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Share Selected Device</i> button",
18 19
       "operaGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>Allow</i> button",
19 20
       "iexplorerGrantPermissions": "Please grant permissions to use your camera and microphone by pressing <i>OK</i> button",

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

@@ -1388,9 +1388,11 @@ UI.hideRingOverLay = function () {
1388 1388
 
1389 1389
 /**
1390 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,11 +5,10 @@ let $overlay;
5 5
 /**
6 6
  * Internal function that constructs overlay with guidance how to proceed with
7 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 12
     $overlay = $(`
14 13
         <div class='overlay_container'>
15 14
             <div class='overlay overlay_transparent' />
@@ -28,11 +27,13 @@ export default {
28 27
     /**
29 28
      * Shows browser-specific overlay with guidance how to proceed with
30 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,8 +191,11 @@ export default {
191 191
 
192 192
         if (audioRequested && videoRequested) {
193 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 199
                     // If we fail to do this, try to create them separately.
197 200
                     .catch(() => Promise.all(
198 201
                         [createAudioTrack(false), createVideoTrack(false)]))
@@ -213,7 +216,11 @@ export default {
213 216
         }
214 217
 
215 218
         function createAudioTrack(showError) {
216
-            return createLocalTracks(['audio'], null, micDeviceId)
219
+            return createLocalTracks({
220
+                    devices: ['audio'],
221
+                    cameraDeviceId: null,
222
+                    micDeviceId: micDeviceId
223
+                })
217 224
                 .catch(err => {
218 225
                     audioTrackError = err;
219 226
                     showError && APP.UI.showDeviceErrorDialog(err, null);
@@ -222,7 +229,11 @@ export default {
222 229
         }
223 230
 
224 231
         function createVideoTrack(showError) {
225
-            return createLocalTracks(['video'], cameraDeviceId, null)
232
+            return createLocalTracks({
233
+                    devices: ['video'],
234
+                    cameraDeviceId: cameraDeviceId,
235
+                    micDeviceId: null
236
+                })
226 237
                 .catch(err => {
227 238
                     videoTrackError = err;
228 239
                     showError && APP.UI.showDeviceErrorDialog(null, err);

Loading…
取消
儲存