浏览代码

Introduced JitsiLocalTrack#getCameraFacingMode() method and CameraFacingMode enum

dev1
tsareg 9 年前
父节点
当前提交
32b9f91e5f
共有 4 个文件被更改,包括 79 次插入10 次删除
  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 查看文件

7
 var JitsiTrackError = require("../../JitsiTrackError");
7
 var JitsiTrackError = require("../../JitsiTrackError");
8
 var RTCEvents = require("../../service/RTC/RTCEvents");
8
 var RTCEvents = require("../../service/RTC/RTCEvents");
9
 var RTCUtils = require("./RTCUtils");
9
 var RTCUtils = require("./RTCUtils");
10
+var MediaType = require('../../service/RTC/MediaType');
10
 var VideoType = require('../../service/RTC/VideoType');
11
 var VideoType = require('../../service/RTC/VideoType');
12
+var CameraFacingMode = require('../../service/RTC/CameraFacingMode');
11
 
13
 
12
 /**
14
 /**
13
  * Represents a single media track(either audio or video).
15
  * Represents a single media track(either audio or video).
18
  * @param videoType the VideoType of the JitsiRemoteTrack
20
  * @param videoType the VideoType of the JitsiRemoteTrack
19
  * @param resolution the video resoultion if it's a video track
21
  * @param resolution the video resoultion if it's a video track
20
  * @param deviceId the ID of the local device for this track
22
  * @param deviceId the ID of the local device for this track
23
+ * @param facingMode the camera facing mode used in getUserMedia call
21
  * @constructor
24
  * @constructor
22
  */
25
  */
23
 function JitsiLocalTrack(stream, track, mediaType, videoType, resolution,
26
 function JitsiLocalTrack(stream, track, mediaType, videoType, resolution,
24
-                         deviceId) {
27
+                         deviceId, facingMode) {
25
     var self = this;
28
     var self = this;
26
 
29
 
27
     JitsiTrack.call(this,
30
     JitsiTrack.call(this,
40
     this.initialMSID = this.getMSID();
43
     this.initialMSID = this.getMSID();
41
     this.inMuteOrUnmuteProgress = false;
44
     this.inMuteOrUnmuteProgress = false;
42
 
45
 
46
+    // Store camera facing mode used during getUserMedia call.
47
+    this.facingMode = facingMode;
48
+
43
     // Currently there is no way to know the MediaStreamTrack ended due to to
49
     // Currently there is no way to know the MediaStreamTrack ended due to to
44
     // device disconnect in Firefox through e.g. "readyState" property. Instead
50
     // device disconnect in Firefox through e.g. "readyState" property. Instead
45
     // we will compare current track's label with device labels from
51
     // we will compare current track's label with device labels from
396
     return this._realDeviceId || this.deviceId;
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
 module.exports = JitsiLocalTrack;
442
 module.exports = JitsiLocalTrack;

+ 9
- 6
modules/RTC/RTC.js 查看文件

17
     var deviceId = null;
17
     var deviceId = null;
18
     tracksInfo.forEach(function(trackInfo){
18
     tracksInfo.forEach(function(trackInfo){
19
         if (trackInfo.mediaType === MediaType.AUDIO) {
19
         if (trackInfo.mediaType === MediaType.AUDIO) {
20
-          deviceId = options.micDeviceId;
20
+            deviceId = options.micDeviceId;
21
         } else if (trackInfo.videoType === VideoType.CAMERA){
21
         } else if (trackInfo.videoType === VideoType.CAMERA){
22
-          deviceId = options.cameraDeviceId;
22
+            deviceId = options.cameraDeviceId;
23
         }
23
         }
24
         var localTrack
24
         var localTrack
25
             = new JitsiLocalTrack(
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
         newTracks.push(localTrack);
33
         newTracks.push(localTrack);
31
     });
34
     });
32
     return newTracks;
35
     return newTracks;

+ 5
- 3
modules/RTC/RTCUtils.js 查看文件

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

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;

正在加载...
取消
保存