소스 검색

fix(RTC): Use a enum for media direction.

dev1
Jaya Allamsetty 3 년 전
부모
커밋
d079ee858b
5개의 변경된 파일60개의 추가작업 그리고 35개의 파일을 삭제
  1. 12
    18
      modules/RTC/TPCUtils.js
  2. 5
    4
      modules/sdp/LocalSdpMunger.js
  3. 13
    12
      modules/sdp/SDP.js
  4. 2
    1
      modules/sdp/SDPUtil.js
  5. 28
    0
      service/RTC/MediaDirection.js

+ 12
- 18
modules/RTC/TPCUtils.js 파일 보기

@@ -1,6 +1,7 @@
1 1
 import { getLogger } from 'jitsi-meet-logger';
2 2
 import transform from 'sdp-transform';
3 3
 
4
+import MediaDirection from '../../service/RTC/MediaDirection';
4 5
 import * as MediaType from '../../service/RTC/MediaType';
5 6
 import browser from '../browser';
6 7
 
@@ -9,13 +10,6 @@ const SIM_LAYER_1_RID = '1';
9 10
 const SIM_LAYER_2_RID = '2';
10 11
 const SIM_LAYER_3_RID = '3';
11 12
 
12
-const TransceiverDirection = {
13
-    INACTIVE: 'inactive',
14
-    RECVONLY: 'recvonly',
15
-    SENDONLY: 'sendonly',
16
-    SENDRECV: 'sendrecv'
17
-};
18
-
19 13
 export const SIM_LAYER_RIDS = [ SIM_LAYER_1_RID, SIM_LAYER_2_RID, SIM_LAYER_3_RID ];
20 14
 
21 15
 /**
@@ -234,7 +228,7 @@ export class TPCUtils {
234 228
             // Use pc.addTransceiver() for the initiator case when local tracks are getting added
235 229
             // to the peerconnection before a session-initiate is sent over to the peer.
236 230
             const transceiverInit = {
237
-                direction: TransceiverDirection.SENDRECV,
231
+                direction: MediaDirection.SENDRECV,
238 232
                 streams: [ localTrack.getOriginalStream() ],
239 233
                 sendEncodings: []
240 234
             };
@@ -264,7 +258,7 @@ export class TPCUtils {
264 258
         if (!transceiver) {
265 259
             return Promise.reject(new Error(`RTCRtpTransceiver for ${mediaType} not found`));
266 260
         }
267
-        logger.debug(`Adding ${localTrack} on ${this.pc}`);
261
+        logger.debug(`${this.pc} Adding ${localTrack}`);
268 262
 
269 263
         return transceiver.sender.replaceTrack(track);
270 264
     }
@@ -308,7 +302,7 @@ export class TPCUtils {
308 302
             return Promise.reject(new Error(`RTCRtpTransceiver for ${mediaType} not found`));
309 303
         }
310 304
 
311
-        logger.debug(`Removing ${localTrack} on ${this.pc}`);
305
+        logger.debug(`${this.pc} Removing ${localTrack}`);
312 306
 
313 307
         return transceiver.sender.replaceTrack(null);
314 308
     }
@@ -341,7 +335,7 @@ export class TPCUtils {
341 335
             if (!transceiver) {
342 336
                 return Promise.reject(new Error('replace track failed'));
343 337
             }
344
-            logger.debug(`Replacing ${oldTrack} with ${newTrack} on ${this.pc}`);
338
+            logger.debug(`${this.pc} Replacing ${oldTrack} with ${newTrack}`);
345 339
 
346 340
             return transceiver.sender.replaceTrack(track)
347 341
                 .then(() => {
@@ -364,7 +358,7 @@ export class TPCUtils {
364 358
                     // Change the direction on the transceiver to 'recvonly' so that a 'removetrack'
365 359
                     // is fired on the associated media stream on the remote peer.
366 360
                     if (transceiver) {
367
-                        transceiver.direction = TransceiverDirection.RECVONLY;
361
+                        transceiver.direction = MediaDirection.RECVONLY;
368 362
                     }
369 363
 
370 364
                     // Remove the old track from the list of local tracks.
@@ -380,7 +374,7 @@ export class TPCUtils {
380 374
                     // Change the direction on the transceiver back to 'sendrecv' so that a 'track'
381 375
                     // event is fired on the remote peer.
382 376
                     if (transceiver) {
383
-                        transceiver.direction = TransceiverDirection.SENDRECV;
377
+                        transceiver.direction = MediaDirection.SENDRECV;
384 378
                     }
385 379
 
386 380
                     // Avoid configuring the encodings on Chromium/Safari until simulcast is configured
@@ -397,7 +391,7 @@ export class TPCUtils {
397 391
                 });
398 392
         }
399 393
 
400
-        logger.info('TPCUtils.replaceTrack called with no new track and no old track');
394
+        logger.info(`${this.pc} TPCUtils.replaceTrack called with no new track and no old track`);
401 395
 
402 396
         return Promise.resolve();
403 397
     }
@@ -450,17 +444,17 @@ export class TPCUtils {
450 444
             .filter(t => t.receiver && t.receiver.track && t.receiver.track.kind === mediaType);
451 445
         const localTracks = this.pc.getLocalTracks(mediaType);
452 446
 
453
-        logger.info(`${active ? 'Enabling' : 'Suspending'} ${mediaType} media transfer on ${this.pc}`);
447
+        logger.info(`${this.pc} ${active ? 'Enabling' : 'Suspending'} ${mediaType} media transfer.`);
454 448
         transceivers.forEach((transceiver, idx) => {
455 449
             if (active) {
456 450
                 // The first transceiver is for the local track and only this one can be set to 'sendrecv'
457 451
                 if (idx === 0 && localTracks.length) {
458
-                    transceiver.direction = TransceiverDirection.SENDRECV;
452
+                    transceiver.direction = MediaDirection.SENDRECV;
459 453
                 } else {
460
-                    transceiver.direction = TransceiverDirection.RECVONLY;
454
+                    transceiver.direction = MediaDirection.RECVONLY;
461 455
                 }
462 456
             } else {
463
-                transceiver.direction = TransceiverDirection.INACTIVE;
457
+                transceiver.direction = MediaDirection.INACTIVE;
464 458
             }
465 459
         });
466 460
     }

+ 5
- 4
modules/sdp/LocalSdpMunger.js 파일 보기

@@ -2,6 +2,7 @@
2 2
 
3 3
 import { getLogger } from 'jitsi-meet-logger';
4 4
 
5
+import MediaDirection from '../../service/RTC/MediaDirection';
5 6
 import * as MediaType from '../../service/RTC/MediaType';
6 7
 
7 8
 import { SdpTransformWrap } from './SdpTransformUtil';
@@ -101,7 +102,7 @@ export default class LocalSdpMunger {
101 102
             // NOTE the SDP produced here goes only to Jicofo and is never set
102 103
             // as localDescription. That's why
103 104
             // TraceablePeerConnection.mediaTransferActive is ignored here.
104
-            videoMLine.direction = 'sendrecv';
105
+            videoMLine.direction = MediaDirection.SENDRECV;
105 106
 
106 107
             // Check if the recvonly has MSID
107 108
             const primarySSRC = requiredSSRCs[0];
@@ -224,14 +225,14 @@ export default class LocalSdpMunger {
224 225
 
225 226
         if (!this.tpc.isP2P
226 227
             && (!msid
227
-                || mediaSection.mLine?.direction === 'recvonly'
228
-                || mediaSection.mLine?.direction === 'inactive')) {
228
+                || mediaSection.mLine?.direction === MediaDirection.RECVONLY
229
+                || mediaSection.mLine?.direction === MediaDirection.INACTIVE)) {
229 230
             mediaSection.ssrcs = undefined;
230 231
             mediaSection.ssrcGroups = undefined;
231 232
 
232 233
         // Add the msid attribute if it is missing for p2p sources. Firefox doesn't produce a a=ssrc line
233 234
         // with msid attribute.
234
-        } else if (this.tpc.isP2P && mediaSection.mLine?.direction === 'sendrecv') {
235
+        } else if (this.tpc.isP2P && mediaSection.mLine?.direction === MediaDirection.SENDRECV) {
235 236
             const msidLine = mediaSection.mLine?.msid;
236 237
             const trackId = msidLine && msidLine.split(' ')[1];
237 238
             const sources = [ ...new Set(mediaSection.mLine?.ssrcs?.map(s => s.id)) ];

+ 13
- 12
modules/sdp/SDP.js 파일 보기

@@ -1,5 +1,6 @@
1 1
 /* global $ */
2 2
 
3
+import MediaDirection from '../../service/RTC/MediaDirection';
3 4
 import browser from '../browser';
4 5
 
5 6
 import SDPUtil from './SDPUtil';
@@ -304,16 +305,16 @@ SDP.prototype.toJingle = function(elem, thecreator) {
304 305
 
305 306
                     // eslint-disable-next-line max-depth
306 307
                     switch (extmap.direction) {
307
-                    case 'sendonly':
308
+                    case MediaDirection.SENDONLY:
308 309
                         elem.attrs({ senders: 'responder' });
309 310
                         break;
310
-                    case 'recvonly':
311
+                    case MediaDirection.RECVONLY:
311 312
                         elem.attrs({ senders: 'initiator' });
312 313
                         break;
313
-                    case 'sendrecv':
314
+                    case MediaDirection.SENDRECV:
314 315
                         elem.attrs({ senders: 'both' });
315 316
                         break;
316
-                    case 'inactive':
317
+                    case MediaDirection.INACTIVE:
317 318
                         elem.attrs({ senders: 'none' });
318 319
                         break;
319 320
                     }
@@ -330,13 +331,13 @@ SDP.prototype.toJingle = function(elem, thecreator) {
330 331
 
331 332
         const m = this.media[i];
332 333
 
333
-        if (SDPUtil.findLine(m, 'a=sendrecv', this.session)) {
334
+        if (SDPUtil.findLine(m, `a=${MediaDirection.SENDRECV}`, this.session)) {
334 335
             elem.attrs({ senders: 'both' });
335
-        } else if (SDPUtil.findLine(m, 'a=sendonly', this.session)) {
336
+        } else if (SDPUtil.findLine(m, `a=${MediaDirection.SENDONLY}`, this.session)) {
336 337
             elem.attrs({ senders: 'initiator' });
337
-        } else if (SDPUtil.findLine(m, 'a=recvonly', this.session)) {
338
+        } else if (SDPUtil.findLine(m, `a=${MediaDirection.RECVONLY}`, this.session)) {
338 339
             elem.attrs({ senders: 'responder' });
339
-        } else if (SDPUtil.findLine(m, 'a=inactive', this.session)) {
340
+        } else if (SDPUtil.findLine(m, `a=${MediaDirection.INACTIVE}`, this.session)) {
340 341
             elem.attrs({ senders: 'none' });
341 342
         }
342 343
 
@@ -631,16 +632,16 @@ SDP.prototype.jingle2media = function(content) {
631 632
 
632 633
     switch (content.attr('senders')) {
633 634
     case 'initiator':
634
-        sdp += 'a=sendonly\r\n';
635
+        sdp += `a=${MediaDirection.SENDONLY}\r\n`;
635 636
         break;
636 637
     case 'responder':
637
-        sdp += 'a=recvonly\r\n';
638
+        sdp += `a=${MediaDirection.RECVONLY}\r\n`;
638 639
         break;
639 640
     case 'none':
640
-        sdp += 'a=inactive\r\n';
641
+        sdp += `a=${MediaDirection.INACTIVE}\r\n`;
641 642
         break;
642 643
     case 'both':
643
-        sdp += 'a=sendrecv\r\n';
644
+        sdp += `a=${MediaDirection.SENDRECV}\r\n`;
644 645
         break;
645 646
     }
646 647
     sdp += `a=mid:${content.attr('name')}\r\n`;

+ 2
- 1
modules/sdp/SDPUtil.js 파일 보기

@@ -2,6 +2,7 @@ import { getLogger } from 'jitsi-meet-logger';
2 2
 const logger = getLogger(__filename);
3 3
 
4 4
 import CodecMimeType from '../../service/RTC/CodecMimeType';
5
+import MediaDirection from '../../service/RTC/MediaDirection';
5 6
 import browser from '../browser';
6 7
 import RandomUtil from '../util/RandomUtil';
7 8
 
@@ -657,7 +658,7 @@ const SDPUtil = {
657 658
             if (keepPts.length === 0) {
658 659
                 // There are no other codecs, disable the stream.
659 660
                 mLine.port = 0;
660
-                mLine.direction = 'inactive';
661
+                mLine.direction = MediaDirection.INACTIVE;
661 662
                 mLine.payloads = '*';
662 663
             } else {
663 664
                 mLine.payloads = keepPts.join(' ');

+ 28
- 0
service/RTC/MediaDirection.js 파일 보기

@@ -0,0 +1,28 @@
1
+/* global module */
2
+/**
3
+ * Enumeration of the media direction types.
4
+ * @type {{INACTIVE: string, RECVONLY: string, SENDONLY: string, SENDRECV: string}}
5
+ */
6
+const MediaDirection = {
7
+    /**
8
+     * Media is send and receive is suspended.
9
+     */
10
+    INACTIVE: 'inactive',
11
+
12
+    /**
13
+     * Media is only received from remote peer.
14
+     */
15
+    RECVONLY: 'recvonly',
16
+
17
+    /**
18
+     * Media is only sent to the remote peer.
19
+     */
20
+    SENDONLY: 'sendonly',
21
+
22
+    /**
23
+     * Media is sent and received.
24
+     */
25
+    SENDRECV: 'sendrecv'
26
+};
27
+
28
+module.exports = MediaDirection;

Loading…
취소
저장