Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import type { AppData } from './types';
const logger = new Logger('Consumer');

export type ConsumerOptions<ConsumerAppData extends AppData = AppData> = {
id?: string;
producerId?: string;
kind?: 'audio' | 'video';
id: string;
producerId: string;
kind: 'audio' | 'video';
rtpParameters: RtpParameters;
streamId?: string;
onRtpReceiver?: OnRtpReceiverCallback;
Expand Down
4 changes: 2 additions & 2 deletions src/DataConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const logger = new Logger('DataConsumer');

export type DataConsumerOptions<DataConsumerAppData extends AppData = AppData> =
{
id?: string;
dataProducerId?: string;
id: string;
dataProducerId: string;
sctpStreamParameters: SctpStreamParameters;
label?: string;
protocol?: string;
Expand Down
1 change: 1 addition & 0 deletions src/Producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const logger = new Logger('Producer');

export type ProducerOptions<ProducerAppData extends AppData = AppData> = {
track?: MediaStreamTrack;
streamId?: string;
encodings?: RtpEncodingParameters[];
codecOptions?: ProducerCodecOptions;
headerExtensionOptions?: ProducerHeaderExtensionOptions;
Expand Down
6 changes: 6 additions & 0 deletions src/RtpParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ export type RtpParameters = {
* Parameters used for RTCP.
*/
rtcp?: RtcpParameters;
/**
* MSID (WebRTC MediaStream Identification).
*
* @see https://datatracker.ietf.org/doc/html/rfc8830
*/
msid?: string;
};

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ export class Transport<
*/
async produce<ProducerAppData extends AppData = AppData>({
track,
streamId,
encodings,
codecOptions,
headerExtensionOptions,
Expand Down Expand Up @@ -587,6 +588,7 @@ export class Transport<
const { localId, rtpParameters, rtpSender } =
await this._handler.send({
track,
streamId,
encodings: normalizedEncodings,
codecOptions,
headerExtensionOptions,
Expand Down Expand Up @@ -902,8 +904,8 @@ export class Transport<
task.consumerOptions;

optionsList.push({
trackId: id!,
kind: kind!,
trackId: id,
kind: kind,
rtpParameters,
streamId,
onRtpReceiver,
Expand All @@ -920,9 +922,9 @@ export class Transport<
task.consumerOptions;
const { localId, rtpReceiver, track } = result;
const consumer: Consumer<ConsumerAppData> = new Consumer({
id: id!,
id,
localId,
producerId: producerId!,
producerId,
rtpReceiver,
track,
rtpParameters,
Expand Down
23 changes: 19 additions & 4 deletions src/handlers/Chrome111.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
RtpHeaderExtensionDirection,
} from '../RtpParameters';
import type { SctpCapabilities, SctpStreamParameters } from '../SctpParameters';
import { RemoteSdp } from './sdp/RemoteSdp';
import * as sdpCommonUtils from './sdp/commonUtils';
import * as sdpUnifiedPlanUtils from './sdp/unifiedPlanUtils';
import * as ortcUtils from './ortc/utils';
Expand All @@ -31,7 +32,6 @@ import type {
HandlerReceiveDataChannelOptions,
HandlerReceiveDataChannelResult,
} from './HandlerInterface';
import { RemoteSdp } from './sdp/RemoteSdp';

const logger = new Logger('Chrome111');

Expand Down Expand Up @@ -60,7 +60,7 @@ export class Chrome111
// Map of RTCTransceivers indexed by MID.
private readonly _mapMidTransceiver: Map<string, RTCRtpTransceiver> =
new Map();
// Local stream for sending.
// Default local stream for sending if no `streamId` is given in send().
private readonly _sendStream = new MediaStream();
// Whether a DataChannel m=application section has been created.
private _hasDataChannelMediaSection = false;
Expand Down Expand Up @@ -336,6 +336,7 @@ export class Chrome111

async send({
track,
streamId,
encodings,
codecOptions,
headerExtensionOptions,
Expand All @@ -345,7 +346,12 @@ export class Chrome111
this.assertNotClosed();
this.assertSendDirection();

logger.debug('send() [kind:%s, track.id:%s]', track.kind, track.id);
logger.debug(
'send() [kind:%s, track.id:%s, streamId:%s]',
track.kind,
track.id,
streamId
);

if (encodings && encodings.length > 1) {
// Set rid and verify scalabilityMode in each encoding.
Expand Down Expand Up @@ -481,6 +487,9 @@ export class Chrome111
offerMediaObject,
});

// Set msid.
sendingRtpParameters.msid = `${streamId ?? this._sendStream.id} ${track.id}`;

// Set RTP encodings by parsing the SDP offer if no encodings are given.
if (!encodings) {
sendingRtpParameters.encodings = sdpUnifiedPlanUtils.getRtpEncodings({
Expand Down Expand Up @@ -905,11 +914,17 @@ export class Chrome111

mapLocalId.set(trackId, localId);

// We ignore MSID `trackId` when consuming and always use our computed
// `trackId` which matches the `consumer.id`.
const { msidStreamId } = ortcUtils.getMsidStreamIdAndTrackId(
rtpParameters.msid
);

this._remoteSdp.receive({
mid: localId,
kind,
offerRtpParameters: rtpParameters,
streamId: streamId ?? rtpParameters.rtcp!.cname!,
streamId: streamId ?? msidStreamId ?? rtpParameters.rtcp?.cname ?? '-',
trackId,
});
}
Expand Down
23 changes: 19 additions & 4 deletions src/handlers/Chrome74.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
RtpHeaderExtensionDirection,
} from '../RtpParameters';
import type { SctpCapabilities, SctpStreamParameters } from '../SctpParameters';
import { RemoteSdp } from './sdp/RemoteSdp';
import * as sdpCommonUtils from './sdp/commonUtils';
import * as sdpUnifiedPlanUtils from './sdp/unifiedPlanUtils';
import * as ortcUtils from './ortc/utils';
Expand All @@ -32,7 +33,6 @@ import type {
HandlerReceiveDataChannelOptions,
HandlerReceiveDataChannelResult,
} from './HandlerInterface';
import { RemoteSdp } from './sdp/RemoteSdp';

const logger = new Logger('Chrome74');

Expand Down Expand Up @@ -61,7 +61,7 @@ export class Chrome74
// Map of RTCTransceivers indexed by MID.
private readonly _mapMidTransceiver: Map<string, RTCRtpTransceiver> =
new Map();
// Local stream for sending.
// Default local stream for sending if no `streamId` is given in send().
private readonly _sendStream = new MediaStream();
// Whether a DataChannel m=application section has been created.
private _hasDataChannelMediaSection = false;
Expand Down Expand Up @@ -333,6 +333,7 @@ export class Chrome74

async send({
track,
streamId,
encodings,
codecOptions,
headerExtensionOptions,
Expand All @@ -341,7 +342,12 @@ export class Chrome74
this.assertNotClosed();
this.assertSendDirection();

logger.debug('send() [kind:%s, track.id:%s]', track.kind, track.id);
logger.debug(
'send() [kind:%s, track.id:%s, streamId:%s]',
track.kind,
track.id,
streamId
);

if (encodings && encodings.length > 1) {
encodings.forEach((encoding: RtpEncodingParameters, idx: number) => {
Expand Down Expand Up @@ -484,6 +490,9 @@ export class Chrome74
offerMediaObject,
});

// Set msid.
sendingRtpParameters.msid = `${streamId ?? this._sendStream.id} ${track.id}`;

// Set RTP encodings by parsing the SDP offer if no encodings are given.
if (!encodings) {
sendingRtpParameters.encodings = sdpUnifiedPlanUtils.getRtpEncodings({
Expand Down Expand Up @@ -929,11 +938,17 @@ export class Chrome74

mapLocalId.set(trackId, localId);

// We ignore MSID `trackId` when consuming and always use our computed
// `trackId` which matches the `consumer.id`.
const { msidStreamId } = ortcUtils.getMsidStreamIdAndTrackId(
rtpParameters.msid
);

this._remoteSdp.receive({
mid: localId,
kind,
offerRtpParameters: rtpParameters,
streamId: streamId ?? rtpParameters.rtcp!.cname!,
streamId: streamId ?? msidStreamId ?? rtpParameters.rtcp?.cname ?? '-',
trackId,
});
}
Expand Down
23 changes: 15 additions & 8 deletions src/handlers/FakeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import type {
ExtendedRtpCapabilities,
} from '../RtpParameters';
import type { SctpCapabilities } from '../SctpParameters';
import { FakeEventTarget } from './fakeEvents/FakeEventTarget';
import {
FakeEventListener,
FakeAddEventListenerOptions,
FakeEventListenerOptions,
} from './fakeEvents/FakeEventListener';
import { FakeEvent } from './fakeEvents/FakeEvent';
import type {
HandlerFactory,
HandlerInterface,
Expand All @@ -33,13 +40,6 @@ import type {
HandlerReceiveDataChannelOptions,
HandlerReceiveDataChannelResult,
} from './HandlerInterface';
import { FakeEventTarget } from './fakeEvents/FakeEventTarget';
import {
FakeEventListener,
FakeAddEventListenerOptions,
FakeEventListenerOptions,
} from './fakeEvents/FakeEventListener';
import { FakeEvent } from './fakeEvents/FakeEvent';

const logger = new Logger('FakeHandler');

Expand All @@ -65,6 +65,8 @@ export class FakeHandler
) => ExtendedRtpCapabilities;
// Local RTCP CNAME.
private _cname = `CNAME-${utils.generateRandomNumber()}`;
// Default sending MediaStream id.
private _defaultSendStreamId = `${utils.generateRandomNumber()}`;
// Got transport local and remote parameters.
private _transportReady = false;
// Next localId.
Expand Down Expand Up @@ -179,7 +181,7 @@ export class FakeHandler

async send(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
{ track, encodings, codecOptions, codec }: HandlerSendOptions
{ track, streamId, encodings, codecOptions, codec }: HandlerSendOptions
): Promise<HandlerSendResult> {
this.assertNotClosed();

Expand Down Expand Up @@ -214,6 +216,8 @@ export class FakeHandler

sendingRtpParameters.mid = `mid-${utils.generateRandomNumber()}`;

sendingRtpParameters.msid = `${streamId ?? '-'} ${track.id}`;

if (!encodings) {
encodings = [{}];
}
Expand All @@ -235,6 +239,9 @@ export class FakeHandler
mux: true,
};

// Set msid.
sendingRtpParameters.msid = `${streamId ?? this._defaultSendStreamId} ${track.id}`;

const localId = this._nextLocalId++;

this._tracks.set(localId, track);
Expand Down
24 changes: 20 additions & 4 deletions src/handlers/Firefox120.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import type {
ExtendedRtpCapabilities,
} from '../RtpParameters';
import type { SctpCapabilities, SctpStreamParameters } from '../SctpParameters';
import { RemoteSdp } from './sdp/RemoteSdp';
import * as sdpCommonUtils from './sdp/commonUtils';
import * as sdpUnifiedPlanUtils from './sdp/unifiedPlanUtils';
import * as ortcUtils from './ortc/utils';
import type {
HandlerFactory,
HandlerInterface,
Expand All @@ -29,7 +31,6 @@ import type {
HandlerReceiveDataChannelOptions,
HandlerReceiveDataChannelResult,
} from './HandlerInterface';
import { RemoteSdp } from './sdp/RemoteSdp';

const logger = new Logger('Firefox120');

Expand All @@ -55,7 +56,7 @@ export class Firefox120
// Map of RTCTransceivers indexed by MID.
private readonly _mapMidTransceiver: Map<string, RTCRtpTransceiver> =
new Map();
// Local stream for sending.
// Default local stream for sending if no `streamId` is given in send().
private readonly _sendStream = new MediaStream();
// Whether a DataChannel m=application section has been created.
private _hasDataChannelMediaSection = false;
Expand Down Expand Up @@ -336,6 +337,7 @@ export class Firefox120

async send({
track,
streamId,
encodings,
codecOptions,
codec,
Expand All @@ -344,7 +346,12 @@ export class Firefox120
this.assertNotClosed();
this.assertSendDirection();

logger.debug('send() [kind:%s, track.id:%s]', track.kind, track.id);
logger.debug(
'send() [kind:%s, track.id:%s, streamId:%s]',
track.kind,
track.id,
streamId
);

if (encodings && encodings.length > 1) {
encodings.forEach((encoding: RtpEncodingParameters, idx: number) => {
Expand Down Expand Up @@ -435,6 +442,9 @@ export class Firefox120
offerMediaObject,
});

// Set msid.
sendingRtpParameters.msid = `${streamId ?? this._sendStream.id} ${track.id}`;

// Set RTP encodings by parsing the SDP offer if no encodings are given.
if (!encodings) {
sendingRtpParameters.encodings = sdpUnifiedPlanUtils.getRtpEncodings({
Expand Down Expand Up @@ -873,11 +883,17 @@ export class Firefox120

mapLocalId.set(trackId, localId);

// We ignore MSID `trackId` when consuming and always use our computed
// `trackId` which matches the `consumer.id`.
const { msidStreamId } = ortcUtils.getMsidStreamIdAndTrackId(
rtpParameters.msid
);

this._remoteSdp.receive({
mid: localId,
kind,
offerRtpParameters: rtpParameters,
streamId: streamId ?? rtpParameters.rtcp!.cname!,
streamId: streamId ?? msidStreamId ?? rtpParameters.rtcp?.cname ?? '-',
trackId,
});
}
Expand Down
Loading