Browse Source

feat(RTC): Signal video type and availability to bridge.

dev1
Jaya Allamsetty 4 years ago
parent
commit
3cd9d31b97
No account linked to committer's email address
4 changed files with 69 additions and 20 deletions
  1. 22
    18
      JitsiConference.js
  2. 13
    0
      modules/RTC/BridgeChannel.js
  3. 27
    0
      modules/RTC/RTC.js
  4. 7
    2
      service/RTC/VideoType.js

+ 22
- 18
JitsiConference.js View File

@@ -1120,10 +1120,14 @@ JitsiConference.prototype.replaceTrack = function(oldTrack, newTrack) {
1120 1120
             if (oldTrack) {
1121 1121
                 this.onLocalTrackRemoved(oldTrack);
1122 1122
             }
1123
+
1124
+            // Send 'VideoTypeMessage' on the bridge channel for the new track.
1123 1125
             if (newTrack) {
1124
-                // Now handle the addition of the newTrack at the
1125
-                // JitsiConference level
1126
+                // Now handle the addition of the newTrack at the JitsiConference level
1126 1127
                 this._setupNewTrack(newTrack);
1128
+                newTrack.isVideoTrack() && this.rtc.setVideoType(newTrack.videoType);
1129
+            } else {
1130
+                oldTrack && oldTrack.isVideoTrack() && this.rtc.setVideoType(VideoType.NONE);
1127 1131
             }
1128 1132
 
1129 1133
             return Promise.resolve();
@@ -1229,20 +1233,20 @@ JitsiConference.prototype._addLocalTrackAsUnmute = function(track) {
1229 1233
     if (this.jvbJingleSession) {
1230 1234
         addAsUnmutePromises.push(this.jvbJingleSession.addTrackAsUnmute(track));
1231 1235
     } else {
1232
-        logger.info(
1233
-            'Add local MediaStream as unmute -'
1234
-                + ' no JVB Jingle session started yet');
1236
+        logger.debug('Add local MediaStream as unmute - no JVB Jingle session started yet');
1235 1237
     }
1236 1238
 
1237 1239
     if (this.p2pJingleSession) {
1238 1240
         addAsUnmutePromises.push(this.p2pJingleSession.addTrackAsUnmute(track));
1239 1241
     } else {
1240
-        logger.info(
1241
-            'Add local MediaStream as unmute -'
1242
-                + ' no P2P Jingle session started yet');
1242
+        logger.debug('Add local MediaStream as unmute - no P2P Jingle session started yet');
1243 1243
     }
1244 1244
 
1245
-    return Promise.all(addAsUnmutePromises);
1245
+    return Promise.allSettled(addAsUnmutePromises)
1246
+        .then(() => {
1247
+            // Signal the video type to the bridge.
1248
+            track.isVideoTrack() && this.rtc.setVideoType(track.videoType);
1249
+        });
1246 1250
 };
1247 1251
 
1248 1252
 /**
@@ -1256,21 +1260,21 @@ JitsiConference.prototype._removeLocalTrackAsMute = function(track) {
1256 1260
     const removeAsMutePromises = [];
1257 1261
 
1258 1262
     if (this.jvbJingleSession) {
1259
-        removeAsMutePromises.push(
1260
-            this.jvbJingleSession.removeTrackAsMute(track));
1263
+        removeAsMutePromises.push(this.jvbJingleSession.removeTrackAsMute(track));
1261 1264
     } else {
1262
-        logger.info(
1263
-            'Remove local MediaStream - no JVB JingleSession started yet');
1265
+        logger.debug('Remove local MediaStream - no JVB JingleSession started yet');
1264 1266
     }
1265 1267
     if (this.p2pJingleSession) {
1266
-        removeAsMutePromises.push(
1267
-            this.p2pJingleSession.removeTrackAsMute(track));
1268
+        removeAsMutePromises.push(this.p2pJingleSession.removeTrackAsMute(track));
1268 1269
     } else {
1269
-        logger.info(
1270
-            'Remove local MediaStream - no P2P JingleSession started yet');
1270
+        logger.debug('Remove local MediaStream - no P2P JingleSession started yet');
1271 1271
     }
1272 1272
 
1273
-    return Promise.all(removeAsMutePromises);
1273
+    return Promise.allSettled(removeAsMutePromises)
1274
+        .then(() => {
1275
+            // Signal the video type to the bridge.
1276
+            track.isVideoTrack() && this.rtc.setVideoType(VideoType.NONE);
1277
+        });
1274 1278
 };
1275 1279
 
1276 1280
 /**

+ 13
- 0
modules/RTC/BridgeChannel.js View File

@@ -259,6 +259,19 @@ export default class BridgeChannel {
259 259
         });
260 260
     }
261 261
 
262
+    /**
263
+     * Sends a 'VideoTypeMessage' message via the bridge channel.
264
+     *
265
+     * @param {string} videoType 'camera', 'desktop' or 'none'.
266
+     */
267
+    sendVideoTypeMessage(videoType) {
268
+        logger.debug(`Sending VideoTypeMessage with video type as ${videoType}`);
269
+        this._send({
270
+            colibriClass: 'VideoTypeMessage',
271
+            videoType
272
+        });
273
+    }
274
+
262 275
     /**
263 276
      * Set events on the given RTCDataChannel or WebSocket instance.
264 277
      */

+ 27
- 0
modules/RTC/RTC.js View File

@@ -181,6 +181,9 @@ export default class RTC extends Listenable {
181 181
         this._updateAudioOutputForAudioTracks
182 182
             = this._updateAudioOutputForAudioTracks.bind(this);
183 183
 
184
+        // The default video type assumed by the bridge.
185
+        this._videoType = VideoType.CAMERA;
186
+
184 187
         // Switch audio output device on all remote audio tracks. Local audio
185 188
         // tracks handle this event by themselves.
186 189
         if (RTCUtils.isDeviceChangeAvailable('output')) {
@@ -286,6 +289,13 @@ export default class RTC extends Listenable {
286 289
                 }
287 290
             }
288 291
 
292
+            try {
293
+                this._channel.sendVideoTypeMessage(this._videoType);
294
+            } catch (error) {
295
+                GlobalOnErrorHandler.callErrorHandler(error);
296
+                logger.error(`Cannot send VideoTypeMessage ${this._videoType}`, error);
297
+            }
298
+
289 299
             this.removeListener(RTCEvents.DATA_CHANNEL_OPEN, this._channelOpenListener);
290 300
             this._channelOpenListener = null;
291 301
         };
@@ -382,6 +392,23 @@ export default class RTC extends Listenable {
382 392
         }
383 393
     }
384 394
 
395
+    /**
396
+     * Sets the video type and availability for the local video source.
397
+     *
398
+     * @param {string} videoType 'camera' for camera, 'desktop' for screenshare and
399
+     * 'none' for when local video source is muted or removed from the peerconnection.
400
+     * @returns {void}
401
+     */
402
+    setVideoType(videoType) {
403
+        if (this._videoType !== videoType) {
404
+            this._videoType = videoType;
405
+
406
+            if (this._channel && this._channel.isOpen()) {
407
+                this._channel.sendVideoTypeMessage(videoType);
408
+            }
409
+        }
410
+    }
411
+
385 412
     /**
386 413
      * Elects the participants with the given ids to be the selected
387 414
      * participants in order to always receive video for this participant (even

+ 7
- 2
service/RTC/VideoType.js View File

@@ -1,7 +1,7 @@
1 1
 /* global module */
2 2
 /**
3 3
  * Enumeration of the video types
4
- * @type {{CAMERA: string, DESKTOP: string}}
4
+ * @type {{CAMERA: string, DESKTOP: string, NONE: string}}
5 5
  */
6 6
 const VideoType = {
7 7
     /**
@@ -12,7 +12,12 @@ const VideoType = {
12 12
     /**
13 13
      * The desktop video type.
14 14
      */
15
-    DESKTOP: 'desktop'
15
+    DESKTOP: 'desktop',
16
+
17
+    /**
18
+     * No local video source.
19
+     */
20
+    NONE: 'none'
16 21
 };
17 22
 
18 23
 module.exports = VideoType;

Loading…
Cancel
Save