Browse Source

Switches camera id to mandatory when using old gum flow. (#731)

* Switches camera id to mandatory when using old gum flow.

When it fails we retry with different resolutions, and if that doesn't work we remove device id and let gum to decide which device to use.

* Fixes comments.
master
Дамян Минков 7 years ago
parent
commit
8aae4b71a6
3 changed files with 36 additions and 7 deletions
  1. 30
    3
      JitsiMeetJS.js
  2. 5
    1
      JitsiTrackError.js
  3. 1
    3
      modules/RTC/RTCUtils.js

+ 30
- 3
JitsiMeetJS.js View File

@@ -38,8 +38,12 @@ const logger = Logger.getLogger(__filename);
38 38
 const USER_MEDIA_PERMISSION_PROMPT_TIMEOUT = 1000;
39 39
 
40 40
 /**
41
+ * Gets the next lowest desirable resolution to try for a camera.  If the given
42
+ * resolution is already the lowest acceptable resolution, returns null.
41 43
  *
42
- * @param resolution
44
+ * @param resolution the current resolution
45
+ * @return the next lowest resolution from the given one, or null if it is
46
+ * already the lowest acceptable resolution.
43 47
  */
44 48
 function getLowerResolution(resolution) {
45 49
     if (!Resolutions[resolution]) {
@@ -58,6 +62,10 @@ function getLowerResolution(resolution) {
58 62
         }
59 63
     });
60 64
 
65
+    if (resName === resolution) {
66
+        resName = null;
67
+    }
68
+
61 69
     return resName;
62 70
 }
63 71
 
@@ -246,11 +254,14 @@ export default {
246 254
      *
247 255
      * @param {boolean} (firePermissionPromptIsShownEvent) - if event
248 256
      *      JitsiMediaDevicesEvents.PERMISSION_PROMPT_IS_SHOWN should be fired
257
+     * @param originalOptions - internal use only, to be able to store the
258
+     * originally requested options.
249 259
      * @returns {Promise.<{Array.<JitsiTrack>}, JitsiConferenceError>}
250 260
      *     A promise that returns an array of created JitsiTracks if resolved,
251 261
      *     or a JitsiConferenceError if rejected.
252 262
      */
253
-    createLocalTracks(options = {}, firePermissionPromptIsShownEvent) {
263
+    createLocalTracks(
264
+            options = {}, firePermissionPromptIsShownEvent, originalOptions) {
254 265
         let promiseFulfilled = false;
255 266
 
256 267
         if (firePermissionPromptIsShownEvent === true) {
@@ -336,7 +347,23 @@ export default {
336 347
                                 reason: 'unsupported resolution'
337 348
                             }));
338 349
 
339
-                        return this.createLocalTracks(options);
350
+                        return this.createLocalTracks(
351
+                            options,
352
+                            undefined,
353
+                            originalOptions || Object.assign({}, options));
354
+                    }
355
+
356
+                    // we tried everything, if there is a mandatory
357
+                    // device id, remove it and let gum find a device to
358
+                    // use
359
+                    if (originalOptions
360
+                        && error.gum.constraints
361
+                        && error.gum.constraints.video
362
+                        && error.gum.constraints.video.mandatory
363
+                        && error.gum.constraints.video.mandatory.sourceId) {
364
+                        originalOptions.cameraDeviceId = undefined;
365
+
366
+                        return this.createLocalTracks(originalOptions);
340 367
                     }
341 368
                 }
342 369
 

+ 5
- 1
JitsiTrackError.js View File

@@ -91,6 +91,9 @@ function JitsiTrackError(error, options, devices) {
91 91
         case 'OverconstrainedError': {
92 92
             const constraintName = error.constraintName || error.constraint;
93 93
 
94
+            // we treat deviceId as unsupported resolution, as we want to
95
+            // retry and finally if everything fails to remove deviceId from
96
+            // mandatory constraints
94 97
             if (options
95 98
                     && options.video
96 99
                     && (!devices || devices.indexOf('video') > -1)
@@ -99,7 +102,8 @@ function JitsiTrackError(error, options, devices) {
99 102
                         || constraintName === 'minHeight'
100 103
                         || constraintName === 'maxHeight'
101 104
                         || constraintName === 'width'
102
-                        || constraintName === 'height')) {
105
+                        || constraintName === 'height'
106
+                        || constraintName === 'deviceId')) {
103 107
                 this.name = JitsiTrackErrors.UNSUPPORTED_RESOLUTION;
104 108
                 this.message
105 109
                     = TRACK_ERROR_TO_MESSAGE_MAP[this.name]

+ 1
- 3
modules/RTC/RTCUtils.js View File

@@ -243,9 +243,7 @@ function getConstraints(um, options = {}) {
243 243
             }
244 244
 
245 245
             // Old style.
246
-            constraints.video.optional.push({
247
-                sourceId: options.cameraDeviceId
248
-            });
246
+            constraints.video.mandatory.sourceId = options.cameraDeviceId;
249 247
         } else {
250 248
             // Prefer the front i.e. user-facing camera (to the back i.e.
251 249
             // environment-facing camera, for example).

Loading…
Cancel
Save