@@ -15,6 +15,7 @@ import type {
1515 RtpHeaderExtensionDirection ,
1616} from '../RtpParameters' ;
1717import type { SctpCapabilities , SctpStreamParameters } from '../SctpParameters' ;
18+ import { RemoteSdp } from './sdp/RemoteSdp' ;
1819import * as sdpCommonUtils from './sdp/commonUtils' ;
1920import * as sdpUnifiedPlanUtils from './sdp/unifiedPlanUtils' ;
2021import * as ortcUtils from './ortc/utils' ;
@@ -32,7 +33,6 @@ import type {
3233 HandlerReceiveDataChannelOptions ,
3334 HandlerReceiveDataChannelResult ,
3435} from './HandlerInterface' ;
35- import { RemoteSdp } from './sdp/RemoteSdp' ;
3636
3737const logger = new Logger ( 'Chrome74' ) ;
3838
@@ -61,7 +61,7 @@ export class Chrome74
6161 // Map of RTCTransceivers indexed by MID.
6262 private readonly _mapMidTransceiver : Map < string , RTCRtpTransceiver > =
6363 new Map ( ) ;
64- // Local stream for sending.
64+ // Default local stream for sending if no `streamId` is given in send() .
6565 private readonly _sendStream = new MediaStream ( ) ;
6666 // Whether a DataChannel m=application section has been created.
6767 private _hasDataChannelMediaSection = false ;
@@ -333,6 +333,7 @@ export class Chrome74
333333
334334 async send ( {
335335 track,
336+ streamId,
336337 encodings,
337338 codecOptions,
338339 headerExtensionOptions,
@@ -341,7 +342,12 @@ export class Chrome74
341342 this . assertNotClosed ( ) ;
342343 this . assertSendDirection ( ) ;
343344
344- logger . debug ( 'send() [kind:%s, track.id:%s]' , track . kind , track . id ) ;
345+ logger . debug (
346+ 'send() [kind:%s, track.id:%s, streamId:%s]' ,
347+ track . kind ,
348+ track . id ,
349+ streamId
350+ ) ;
345351
346352 if ( encodings && encodings . length > 1 ) {
347353 encodings . forEach ( ( encoding : RtpEncodingParameters , idx : number ) => {
@@ -484,6 +490,9 @@ export class Chrome74
484490 offerMediaObject,
485491 } ) ;
486492
493+ // Set msid.
494+ sendingRtpParameters . msid = `${ streamId ?? this . _sendStream . id } ${ track . id } ` ;
495+
487496 // Set RTP encodings by parsing the SDP offer if no encodings are given.
488497 if ( ! encodings ) {
489498 sendingRtpParameters . encodings = sdpUnifiedPlanUtils . getRtpEncodings ( {
@@ -929,11 +938,17 @@ export class Chrome74
929938
930939 mapLocalId . set ( trackId , localId ) ;
931940
941+ // We ignore MSID `trackId` when consuming and always use our computed
942+ // `trackId` which matches the `consumer.id`.
943+ const { msidStreamId } = ortcUtils . getMsidStreamIdAndTrackId (
944+ rtpParameters . msid
945+ ) ;
946+
932947 this . _remoteSdp . receive ( {
933948 mid : localId ,
934949 kind,
935950 offerRtpParameters : rtpParameters ,
936- streamId : streamId ?? rtpParameters . rtcp ! . cname ! ,
951+ streamId : streamId ?? msidStreamId ?? rtpParameters . rtcp ? .cname ?? '-' ,
937952 trackId,
938953 } ) ;
939954 }
0 commit comments