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
13 changes: 8 additions & 5 deletions src/Transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,13 @@ export class Transport<
return this._awaitQueue.push(async () => {
const { dataChannel, sctpStreamParameters } =
await this._handler.sendDataChannel({
ordered,
maxPacketLifeTime,
maxRetransmits,
label,
protocol,
sctpStreamParameters: {
ordered,
maxPacketLifeTime,
maxRetransmits,
label,
protocol,
},
});

// This will fill sctpStreamParameters's missing fields with default values.
Expand Down Expand Up @@ -849,6 +851,7 @@ export class Transport<
// Enqueue command.
return this._awaitQueue.push(async () => {
const { dataChannel } = await this._handler.receiveDataChannel({
maxMessageSize: this._maxSctpMessageSize!,
sctpStreamParameters: clonedSctpStreamParameters,
label,
protocol,
Expand Down
41 changes: 25 additions & 16 deletions src/handlers/Chrome111.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,27 +827,26 @@ export class Chrome111
}

async sendDataChannel({
ordered,
maxPacketLifeTime,
maxRetransmits,
label,
protocol,
sctpStreamParameters,
}: HandlerSendDataChannelOptions): Promise<HandlerSendDataChannelResult> {
this.assertNotClosed();
this.assertSendDirection();

const options = {
negotiated: true,
id: this._nextSendSctpStreamId,
ordered,
maxPacketLifeTime,
maxRetransmits,
protocol,
ordered: sctpStreamParameters.ordered,
maxPacketLifeTime: sctpStreamParameters.maxPacketLifeTime,
maxRetransmits: sctpStreamParameters.maxRetransmits,
protocol: sctpStreamParameters.protocol,
};

logger.debug('sendDataChannel() [options:%o]', options);

const dataChannel = this._pc.createDataChannel(label!, options);
const dataChannel = this._pc.createDataChannel(
sctpStreamParameters.label!,
options
);

// Increase next id.
this._nextSendSctpStreamId =
Expand Down Expand Up @@ -893,14 +892,14 @@ export class Chrome111
this._hasDataChannelMediaSection = true;
}

const sctpStreamParameters: SctpStreamParameters = {
const newSctpStreamParameters: SctpStreamParameters = {
streamId: options.id,
ordered: options.ordered,
maxPacketLifeTime: options.maxPacketLifeTime,
maxRetransmits: options.maxRetransmits,
};

return { dataChannel, sctpStreamParameters };
return { dataChannel, sctpStreamParameters: newSctpStreamParameters };
}

async receive(
Expand Down Expand Up @@ -1163,6 +1162,7 @@ export class Chrome111
}

async receiveDataChannel({
maxMessageSize,
sctpStreamParameters,
label,
protocol,
Expand Down Expand Up @@ -1207,19 +1207,28 @@ export class Chrome111

await this._pc.setRemoteDescription(offer);

const answer = await this._pc.createAnswer();
let answer = await this._pc.createAnswer();
const localSdpObject = sdpTransform.parse(answer.sdp!);
const answerMediaObject = localSdpObject.media.find(
m => m.type === 'application'
)!;

if (!this._transportReady) {
const localSdpObject = sdpTransform.parse(answer.sdp!);
answerMediaObject.maxMessageSize = maxMessageSize;

if (!this._transportReady) {
await this.setupTransport({
localDtlsRole: this._forcedLocalDtlsRole ?? 'client',
localSdpObject,
});
}

answer = {
type: 'answer',
sdp: sdpTransform.write(localSdpObject),
};

logger.debug(
'receiveDataChannel() | calling pc.setRemoteDescription() [answer:%o]',
'receiveDataChannel() | calling pc.setLocalDescription() [answer:%o]',
answer
);

Expand Down
41 changes: 25 additions & 16 deletions src/handlers/Chrome74.ts
Original file line number Diff line number Diff line change
Expand Up @@ -850,27 +850,26 @@ export class Chrome74
}

async sendDataChannel({
ordered,
maxPacketLifeTime,
maxRetransmits,
label,
protocol,
sctpStreamParameters,
}: HandlerSendDataChannelOptions): Promise<HandlerSendDataChannelResult> {
this.assertNotClosed();
this.assertSendDirection();

const options = {
negotiated: true,
id: this._nextSendSctpStreamId,
ordered,
maxPacketLifeTime,
maxRetransmits,
protocol,
ordered: sctpStreamParameters.ordered,
maxPacketLifeTime: sctpStreamParameters.maxPacketLifeTime,
maxRetransmits: sctpStreamParameters.maxRetransmits,
protocol: sctpStreamParameters.protocol,
};

logger.debug('sendDataChannel() [options:%o]', options);

const dataChannel = this._pc.createDataChannel(label!, options);
const dataChannel = this._pc.createDataChannel(
sctpStreamParameters.label!,
options
);

// Increase next id.
this._nextSendSctpStreamId =
Expand Down Expand Up @@ -916,14 +915,14 @@ export class Chrome74
this._hasDataChannelMediaSection = true;
}

const sctpStreamParameters: SctpStreamParameters = {
const newSctpStreamParameters: SctpStreamParameters = {
streamId: options.id,
ordered: options.ordered,
maxPacketLifeTime: options.maxPacketLifeTime,
maxRetransmits: options.maxRetransmits,
};

return { dataChannel, sctpStreamParameters };
return { dataChannel, sctpStreamParameters: newSctpStreamParameters };
}

async receive(
Expand Down Expand Up @@ -1169,6 +1168,7 @@ export class Chrome74
}

async receiveDataChannel({
maxMessageSize,
sctpStreamParameters,
label,
protocol,
Expand Down Expand Up @@ -1213,19 +1213,28 @@ export class Chrome74

await this._pc.setRemoteDescription(offer);

const answer = await this._pc.createAnswer();
let answer = await this._pc.createAnswer();
const localSdpObject = sdpTransform.parse(answer.sdp!);
const answerMediaObject = localSdpObject.media.find(
m => m.type === 'application'
)!;

if (!this._transportReady) {
const localSdpObject = sdpTransform.parse(answer.sdp!);
answerMediaObject.maxMessageSize = maxMessageSize;

if (!this._transportReady) {
await this.setupTransport({
localDtlsRole: this._forcedLocalDtlsRole ?? 'client',
localSdpObject,
});
}

answer = {
type: 'answer',
sdp: sdpTransform.write(localSdpObject),
};

logger.debug(
'receiveDataChannel() | calling pc.setRemoteDescription() [answer:%o]',
'receiveDataChannel() | calling pc.setLocalDescription() [answer:%o]',
answer
);

Expand Down
27 changes: 12 additions & 15 deletions src/handlers/FakeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,7 @@ export class FakeHandler
}

async sendDataChannel({
ordered,
maxPacketLifeTime,
maxRetransmits,
label,
protocol,
sctpStreamParameters,
}: HandlerSendDataChannelOptions): Promise<HandlerSendDataChannelResult> {
this.assertNotClosed();

Expand All @@ -350,21 +346,21 @@ export class FakeHandler

const dataChannel = new FakeRTCDataChannel({
id: this._nextSctpStreamId++,
ordered,
maxPacketLifeTime,
maxRetransmits,
label,
protocol,
ordered: sctpStreamParameters.ordered,
maxPacketLifeTime: sctpStreamParameters.maxPacketLifeTime,
maxRetransmits: sctpStreamParameters.maxRetransmits,
label: sctpStreamParameters.label,
protocol: sctpStreamParameters.protocol,
});

const sctpStreamParameters = {
const newSctpStreamParameters = {
streamId: this._nextSctpStreamId,
ordered: ordered,
maxPacketLifeTime: maxPacketLifeTime,
maxRetransmits: maxRetransmits,
ordered: sctpStreamParameters.ordered,
maxPacketLifeTime: sctpStreamParameters.maxPacketLifeTime,
maxRetransmits: sctpStreamParameters.maxRetransmits,
};

return { dataChannel, sctpStreamParameters };
return { dataChannel, sctpStreamParameters: newSctpStreamParameters };
}

async receive(
Expand Down Expand Up @@ -432,6 +428,7 @@ export class FakeHandler
}

async receiveDataChannel({
// maxMessageSize,
sctpStreamParameters,
label,
protocol,
Expand Down
41 changes: 25 additions & 16 deletions src/handlers/Firefox120.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,27 +798,26 @@ export class Firefox120
}

async sendDataChannel({
ordered,
maxPacketLifeTime,
maxRetransmits,
label,
protocol,
sctpStreamParameters,
}: HandlerSendDataChannelOptions): Promise<HandlerSendDataChannelResult> {
this.assertNotClosed();
this.assertSendDirection();

const options = {
negotiated: true,
id: this._nextSendSctpStreamId,
ordered,
maxPacketLifeTime,
maxRetransmits,
protocol,
ordered: sctpStreamParameters.ordered,
maxPacketLifeTime: sctpStreamParameters.maxPacketLifeTime,
maxRetransmits: sctpStreamParameters.maxRetransmits,
protocol: sctpStreamParameters.protocol,
};

logger.debug('sendDataChannel() [options:%o]', options);

const dataChannel = this._pc.createDataChannel(label!, options);
const dataChannel = this._pc.createDataChannel(
sctpStreamParameters.label!,
options
);

// Increase next id.
this._nextSendSctpStreamId =
Expand Down Expand Up @@ -861,14 +860,14 @@ export class Firefox120
this._hasDataChannelMediaSection = true;
}

const sctpStreamParameters: SctpStreamParameters = {
const newSctpStreamParameters: SctpStreamParameters = {
streamId: options.id,
ordered: options.ordered,
maxPacketLifeTime: options.maxPacketLifeTime,
maxRetransmits: options.maxRetransmits,
};

return { dataChannel, sctpStreamParameters };
return { dataChannel, sctpStreamParameters: newSctpStreamParameters };
}

async receive(
Expand Down Expand Up @@ -1127,6 +1126,7 @@ export class Firefox120
}

async receiveDataChannel({
maxMessageSize,
sctpStreamParameters,
label,
protocol,
Expand Down Expand Up @@ -1171,16 +1171,25 @@ export class Firefox120

await this._pc.setRemoteDescription(offer);

const answer = await this._pc.createAnswer();
let answer = await this._pc.createAnswer();
const localSdpObject = sdpTransform.parse(answer.sdp!);
const answerMediaObject = localSdpObject.media.find(
m => m.type === 'application'
)!;

if (!this._transportReady) {
const localSdpObject = sdpTransform.parse(answer.sdp!);
answerMediaObject.maxMessageSize = maxMessageSize;

if (!this._transportReady) {
await this.setupTransport({ localDtlsRole: 'client', localSdpObject });
}

answer = {
type: 'answer',
sdp: sdpTransform.write(localSdpObject),
};

logger.debug(
'receiveDataChannel() | calling pc.setRemoteDescription() [answer:%o]',
'receiveDataChannel() | calling pc.setLocalDescription() [answer:%o]',
answer
);

Expand Down
5 changes: 4 additions & 1 deletion src/handlers/HandlerInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,17 @@ export type HandlerReceiveResult = {
rtpReceiver?: RTCRtpReceiver;
};

export type HandlerSendDataChannelOptions = SctpStreamParameters;
export type HandlerSendDataChannelOptions = {
sctpStreamParameters: SctpStreamParameters;
};

export type HandlerSendDataChannelResult = {
dataChannel: RTCDataChannel;
sctpStreamParameters: SctpStreamParameters;
};

export type HandlerReceiveDataChannelOptions = {
maxMessageSize: number;
sctpStreamParameters: SctpStreamParameters;
label?: string;
protocol?: string;
Expand Down
Loading