Преглед изворни кода

feat(JitsiLocalTrack): expose source id for desktop sharing tracks

dev1
hristoterezov пре 8 година
родитељ
комит
b25f411484
4 измењених фајлова са 49 додато и 40 уклоњено
  1. 20
    13
      modules/RTC/JitsiLocalTrack.js
  2. 6
    10
      modules/RTC/RTC.js
  3. 9
    7
      modules/RTC/RTCUtils.js
  4. 14
    10
      modules/RTC/ScreenObtainer.js

+ 20
- 13
modules/RTC/JitsiLocalTrack.js Прегледај датотеку

@@ -46,20 +46,25 @@ function createMuteUnmutePromise(track, mute) {
46 46
  * One <tt>JitsiLocalTrack</tt> corresponds to one WebRTC MediaStreamTrack.
47 47
  */
48 48
 export default class JitsiLocalTrack extends JitsiTrack {
49
-    /* eslint-disable max-params */
50 49
     /**
51 50
      * Constructs new JitsiLocalTrack instanse.
52
-     * @param {number} rtcId the ID assigned by the RTC module
53
-     * @param stream WebRTC MediaStream, parent of the track
54
-     * @param track underlying WebRTC MediaStreamTrack for new JitsiRemoteTrack
55
-     * @param mediaType the MediaType of the JitsiRemoteTrack
56
-     * @param videoType the VideoType of the JitsiRemoteTrack
57
-     * @param resolution the video resolution if it's a video track
58
-     * @param deviceId the ID of the local device for this track
59
-     * @param facingMode the camera facing mode used in getUserMedia call
51
+     * @param {Object} trackInfo
52
+     * @param {number} trackInfo.rtcId the ID assigned by the RTC module
53
+     * @param trackInfo.stream WebRTC MediaStream, parent of the track
54
+     * @param trackInfo.track underlying WebRTC MediaStreamTrack for new
55
+     * JitsiRemoteTrack
56
+     * @param trackInfo.mediaType the MediaType of the JitsiRemoteTrack
57
+     * @param trackInfo.videoType the VideoType of the JitsiRemoteTrack
58
+     * @param trackInfo.resolution the video resolution if it's a video track
59
+     * @param trackInfo.deviceId the ID of the local device for this track
60
+     * @param trackInfo.facingMode the camera facing mode used in getUserMedia
61
+     * call
62
+     * @param {sourceId} trackInfo.sourceId - The id of the desktop sharing
63
+     * source. NOTE: defined for desktop sharing tracks only.
60 64
      * @constructor
61 65
      */
62
-    constructor(
66
+    constructor(trackInfo) {
67
+        const {
63 68
             rtcId,
64 69
             stream,
65 70
             track,
@@ -67,7 +72,10 @@ export default class JitsiLocalTrack extends JitsiTrack {
67 72
             videoType,
68 73
             resolution,
69 74
             deviceId,
70
-            facingMode) {
75
+            facingMode,
76
+            sourceId
77
+        } = trackInfo;
78
+
71 79
         super(
72 80
             null /* RTC */,
73 81
             stream,
@@ -88,6 +96,7 @@ export default class JitsiLocalTrack extends JitsiTrack {
88 96
         this.rtcId = rtcId;
89 97
         this.dontFireRemoveEvent = false;
90 98
         this.resolution = resolution;
99
+        this.sourceId = sourceId;
91 100
 
92 101
         // FIXME: currently firefox is ignoring our constraints about
93 102
         // resolutions so we do not store it, to avoid wrong reporting of local
@@ -177,8 +186,6 @@ export default class JitsiLocalTrack extends JitsiTrack {
177 186
         this._initNoDataFromSourceHandlers();
178 187
     }
179 188
 
180
-    /* eslint-enable max-params */
181
-
182 189
     /**
183 190
      * Returns if associated MediaStreamTrack is in the 'ended' state
184 191
      * @returns {boolean}

+ 6
- 10
modules/RTC/RTC.js Прегледај датотеку

@@ -35,16 +35,12 @@ function createLocalTracks(tracksInfo, options) {
35 35
             deviceId = options.cameraDeviceId;
36 36
         }
37 37
         rtcTrackIdCounter += 1;
38
-        const localTrack
39
-            = new JitsiLocalTrack(
40
-                rtcTrackIdCounter,
41
-                trackInfo.stream,
42
-                trackInfo.track,
43
-                trackInfo.mediaType,
44
-                trackInfo.videoType,
45
-                trackInfo.resolution,
46
-                deviceId,
47
-                options.facingMode);
38
+        const localTrack = new JitsiLocalTrack({
39
+            ...trackInfo,
40
+            deviceId,
41
+            facingMode: options.facingMode,
42
+            rtcId: rtcTrackIdCounter
43
+        });
48 44
 
49 45
         newTracks.push(localTrack);
50 46
     });

+ 9
- 7
modules/RTC/RTCUtils.js Прегледај датотеку

@@ -628,14 +628,16 @@ function handleLocalStream(streams, resolution) {
628 628
             videoStream = streams.video;
629 629
         }
630 630
 
631
-        // Again, different choices on different types of browser.
632
-        desktopStream = streams.desktopStream || streams.desktop;
631
+        desktopStream = streams.desktop;
633 632
     }
634 633
 
635 634
     if (desktopStream) {
635
+        const { stream, sourceId } = desktopStream;
636
+
636 637
         res.push({
637
-            stream: desktopStream,
638
-            track: desktopStream.getVideoTracks()[0],
638
+            stream,
639
+            sourceId,
640
+            track: stream.getVideoTracks()[0],
639 641
             mediaType: MediaType.VIDEO,
640 642
             videoType: VideoType.DESKTOP
641 643
         });
@@ -1186,9 +1188,9 @@ class RTCUtils extends Listenable {
1186 1188
                             if (hasDesktop) {
1187 1189
                                 screenObtainer.obtainStream(
1188 1190
                                     dsOptions,
1189
-                                    desktopStream => {
1191
+                                    desktop => {
1190 1192
                                         successCallback({ audioVideo: stream,
1191
-                                            desktopStream });
1193
+                                            desktop });
1192 1194
                                     }, error => {
1193 1195
                                         self.stopMediaStream(stream);
1194 1196
 
@@ -1203,7 +1205,7 @@ class RTCUtils extends Listenable {
1203 1205
                 } else if (hasDesktop) {
1204 1206
                     screenObtainer.obtainStream(
1205 1207
                         dsOptions,
1206
-                        stream => successCallback({ desktopStream: stream }),
1208
+                        desktop => successCallback({ desktop }),
1207 1209
                         error => reject(error));
1208 1210
                 }
1209 1211
             }

+ 14
- 10
modules/RTC/ScreenObtainer.js Прегледај датотеку

@@ -121,10 +121,11 @@ const ScreenObtainer = {
121 121
                     && window.JitsiMeetScreenObtainer.openDesktopPicker) {
122 122
                     window.JitsiMeetScreenObtainer.openDesktopPicker(
123 123
                         streamId =>
124
-                            onGetStreamResponse({ streamId },
125
-                            onSuccess,
126
-                            onFailure
127
-                        ),
124
+                            onGetStreamResponse(
125
+                                { streamId },
126
+                                onSuccess,
127
+                                onFailure
128
+                            ),
128 129
                         err => onFailure(new JitsiTrackError(
129 130
                             JitsiTrackErrors.ELECTRON_DESKTOP_PICKER_ERROR,
130 131
                             err
@@ -565,18 +566,21 @@ function waitForExtensionAfterInstall(options, waitInterval, retries) {
565 566
  * @param {Function} onSuccess - callback for success.
566 567
  * @param {Function} onFailure - callback for failure.
567 568
  */
568
-function onGetStreamResponse(response, onSuccess, onFailure) {
569
-    if (response.streamId) {
569
+function onGetStreamResponse({ streamId, error }, onSuccess, onFailure) {
570
+    if (streamId) {
570 571
         gumFunction(
571 572
             [ 'desktop' ],
572
-            stream => onSuccess(stream),
573
+            stream => onSuccess({
574
+                stream,
575
+                sourceId: streamId
576
+            }),
573 577
             onFailure,
574
-            { desktopStream: response.streamId });
578
+            { desktopStream: streamId });
575 579
     } else {
576 580
         // As noted in Chrome Desktop Capture API:
577 581
         // If user didn't select any source (i.e. canceled the prompt)
578 582
         // then the callback is called with an empty streamId.
579
-        if (response.streamId === '') {
583
+        if (streamId === '') {
580 584
             onFailure(new JitsiTrackError(
581 585
                 JitsiTrackErrors.CHROME_EXTENSION_USER_CANCELED));
582 586
 
@@ -585,7 +589,7 @@ function onGetStreamResponse(response, onSuccess, onFailure) {
585 589
 
586 590
         onFailure(new JitsiTrackError(
587 591
             JitsiTrackErrors.CHROME_EXTENSION_GENERIC_ERROR,
588
-            response.error));
592
+            error));
589 593
     }
590 594
 }
591 595
 

Loading…
Откажи
Сачувај