Browse Source

Introduced JitsiLocalTrack#getCameraFacingMode() method and CameraFacingMode enum

dev1
tsareg 9 years ago
parent
commit
32b9f91e5f
4 changed files with 79 additions and 10 deletions
  1. 44
    1
      modules/RTC/JitsiLocalTrack.js
  2. 9
    6
      modules/RTC/RTC.js
  3. 5
    3
      modules/RTC/RTCUtils.js
  4. 21
    0
      service/RTC/CameraFacingMode.js

+ 44
- 1
modules/RTC/JitsiLocalTrack.js View File

@@ -7,7 +7,9 @@ var JitsiTrackErrors = require("../../JitsiTrackErrors");
7 7
 var JitsiTrackError = require("../../JitsiTrackError");
8 8
 var RTCEvents = require("../../service/RTC/RTCEvents");
9 9
 var RTCUtils = require("./RTCUtils");
10
+var MediaType = require('../../service/RTC/MediaType');
10 11
 var VideoType = require('../../service/RTC/VideoType');
12
+var CameraFacingMode = require('../../service/RTC/CameraFacingMode');
11 13
 
12 14
 /**
13 15
  * Represents a single media track(either audio or video).
@@ -18,10 +20,11 @@ var VideoType = require('../../service/RTC/VideoType');
18 20
  * @param videoType the VideoType of the JitsiRemoteTrack
19 21
  * @param resolution the video resoultion if it's a video track
20 22
  * @param deviceId the ID of the local device for this track
23
+ * @param facingMode the camera facing mode used in getUserMedia call
21 24
  * @constructor
22 25
  */
23 26
 function JitsiLocalTrack(stream, track, mediaType, videoType, resolution,
24
-                         deviceId) {
27
+                         deviceId, facingMode) {
25 28
     var self = this;
26 29
 
27 30
     JitsiTrack.call(this,
@@ -40,6 +43,9 @@ function JitsiLocalTrack(stream, track, mediaType, videoType, resolution,
40 43
     this.initialMSID = this.getMSID();
41 44
     this.inMuteOrUnmuteProgress = false;
42 45
 
46
+    // Store camera facing mode used during getUserMedia call.
47
+    this.facingMode = facingMode;
48
+
43 49
     // Currently there is no way to know the MediaStreamTrack ended due to to
44 50
     // device disconnect in Firefox through e.g. "readyState" property. Instead
45 51
     // we will compare current track's label with device labels from
@@ -396,4 +402,41 @@ JitsiLocalTrack.prototype.getDeviceId = function () {
396 402
     return this._realDeviceId || this.deviceId;
397 403
 };
398 404
 
405
+/**
406
+ * Returns facing mode for video track from camera. For other cases (e.g. audio
407
+ * track or 'desktop' video track) returns undefined.
408
+ *
409
+ * @returns {CameraFacingMode|undefined}
410
+ */
411
+JitsiLocalTrack.prototype.getCameraFacingMode = function () {
412
+    if (this.isVideoTrack() && this.videoType === VideoType.CAMERA) {
413
+        // MediaStreamTrack#getSettings() is not implemented in many browsers,
414
+        // so we do a feature checking here. Progress on implementation can be
415
+        // tracked at https://bugs.chromium.org/p/webrtc/issues/detail?id=2481
416
+        // for Chromium and https://bugzilla.mozilla.org/show_bug.cgi?id=1213517
417
+        // for Firefox. Even if a browser already implements getSettings()
418
+        // it might still not return anything for 'facingMode' so we need to
419
+        // take into account this.
420
+        var trackSettings;
421
+
422
+        if (this.track &&
423
+            typeof this.track.getSettings === 'function' &&
424
+            (trackSettings = this.track.getSettings()) &&
425
+            'facingMode' in trackSettings) {
426
+            return trackSettings.facingMode;
427
+        } else if (typeof this.facingMode !== 'undefined') {
428
+            return this.facingMode;
429
+        } else {
430
+            // In most cases we are showing a webcam. So if we failed to satisfy
431
+            // any of the above conditions and got here, that means that we're
432
+            // probably showing the user facing camera.
433
+            return CameraFacingMode.USER;
434
+        }
435
+
436
+    }
437
+
438
+    return undefined;
439
+};
440
+
441
+
399 442
 module.exports = JitsiLocalTrack;

+ 9
- 6
modules/RTC/RTC.js View File

@@ -17,16 +17,19 @@ function createLocalTracks(tracksInfo, options) {
17 17
     var deviceId = null;
18 18
     tracksInfo.forEach(function(trackInfo){
19 19
         if (trackInfo.mediaType === MediaType.AUDIO) {
20
-          deviceId = options.micDeviceId;
20
+            deviceId = options.micDeviceId;
21 21
         } else if (trackInfo.videoType === VideoType.CAMERA){
22
-          deviceId = options.cameraDeviceId;
22
+            deviceId = options.cameraDeviceId;
23 23
         }
24 24
         var localTrack
25 25
             = new JitsiLocalTrack(
26
-                trackInfo.stream,
27
-                trackInfo.track,
28
-                trackInfo.mediaType,
29
-                trackInfo.videoType, trackInfo.resolution, deviceId);
26
+            trackInfo.stream,
27
+            trackInfo.track,
28
+            trackInfo.mediaType,
29
+            trackInfo.videoType,
30
+            trackInfo.resolution,
31
+            deviceId,
32
+            options.facingMode);
30 33
         newTracks.push(localTrack);
31 34
     });
32 35
     return newTracks;

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

@@ -17,6 +17,7 @@ var JitsiTrackErrors = require("../../JitsiTrackErrors");
17 17
 var JitsiTrackError = require("../../JitsiTrackError");
18 18
 var MediaType = require("../../service/RTC/MediaType");
19 19
 var VideoType = require("../../service/RTC/VideoType");
20
+var CameraFacingMode = require("../../service/RTC/CameraFacingMode");
20 21
 var GlobalOnErrorHandler = require("../util/GlobalOnErrorHandler");
21 22
 
22 23
 var eventEmitter = new EventEmitter();
@@ -103,7 +104,7 @@ function setResolutionConstraints(constraints, resolution) {
103 104
  * @param {string} options.desktopStream
104 105
  * @param {string} options.cameraDeviceId
105 106
  * @param {string} options.micDeviceId
106
- * @param {'user'|'environment'} options.facingMode
107
+ * @param {CameraFacingMode} options.facingMode
107 108
  * @param {bool} firefox_fake_device
108 109
  */
109 110
 function getConstraints(um, options) {
@@ -141,11 +142,12 @@ function getConstraints(um, options) {
141 142
             // but this probably needs to be decided when updating other
142 143
             // constraints, as we currently don't use "exact" syntax anywhere.
143 144
             if (isNewStyleConstraintsSupported) {
144
-                constraints.video.facingMode = options.facingMode || 'user';
145
+                constraints.video.facingMode =
146
+                    options.facingMode || CameraFacingMode.USER;
145 147
             }
146 148
 
147 149
             constraints.video.optional.push({
148
-                facingMode: options.facingMode || 'user'
150
+                facingMode: options.facingMode || CameraFacingMode.USER
149 151
             });
150 152
         }
151 153
 

+ 21
- 0
service/RTC/CameraFacingMode.js View File

@@ -0,0 +1,21 @@
1
+/* global module */
2
+/**
3
+ * Possible camera facing modes. For now support only 'user' and 'environment'
4
+ * modes as 'left' and 'right' and not used anywhere right at the moment.
5
+ * For more info see
6
+ * https://w3c.github.io/mediacapture-main/getusermedia.html#def-constraint-facingMode
7
+ *
8
+ * @enum {string}
9
+ */
10
+var CameraFacingMode = {
11
+    /**
12
+     * The user facing camera mode.
13
+     */
14
+    USER: "user",
15
+    /**
16
+     * The environment facing camera mode.
17
+     */
18
+    ENVIRONMENT: "environment"
19
+};
20
+
21
+module.exports = CameraFacingMode;

Loading…
Cancel
Save