Skip to content
Open
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
36 changes: 15 additions & 21 deletions src/handlers/Firefox120.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,6 @@ export class Firefox120
});
}

// NOTE: Firefox fails sometimes to properly anticipate the closed media
// section that it should use, so don't reuse closed media sections.
// https://github.com/versatica/mediasoup-client/issues/104
//
// const mediaSectionIdx = this._remoteSdp.getNextMediaSectionIdx();

const transceiver = this._pc.addTransceiver(track, {
direction: 'sendonly',
streams: [this._sendStream],
Expand Down Expand Up @@ -438,8 +432,10 @@ export class Firefox120

localSdpObject = sdpTransform.parse(this._pc.localDescription!.sdp);

const offerMediaObject =
localSdpObject.media[localSdpObject.media.length - 1]!;
const idx = localSdpObject.media.findIndex((s) => s.mid == localId);
const oldMediaSection = this._remoteSdp.getMediaSection(idx);

const offerMediaObject = localSdpObject.media[idx]!;

// Set RTCP CNAME.
sendingRtpParameters.rtcp!.cname = sdpCommonUtils.getCname({
Expand Down Expand Up @@ -491,6 +487,7 @@ export class Firefox120

this._remoteSdp.send({
offerMediaObject,
reuseMid: oldMediaSection && oldMediaSection.closed ? oldMediaSection.mid : undefined,
offerRtpParameters: sendingRtpParameters,
answerRtpParameters: sendingRemoteRtpParameters,
codecOptions,
Expand Down Expand Up @@ -535,20 +532,17 @@ export class Firefox120

void transceiver.sender.replaceTrack(null);

// NOTE: Cannot use stop() the transceiver due to the the note above in
// send() method.
// try
// {
// transceiver.stop();
// }
// catch (error)
// {}

this._pc.removeTrack(transceiver.sender);
// NOTE: Cannot use closeMediaSection() due to the the note above in send()
// method.
// this._remoteSdp.closeMediaSection(transceiver.mid);
this._remoteSdp.disableMediaSection(transceiver.mid!);

const mediaSectionClosed = this._remoteSdp.closeMediaSection(
transceiver.mid!
);

if (mediaSectionClosed) {
try {
transceiver.stop();
} catch (error) {}
}

const offer = await this._pc.createOffer();

Expand Down
4 changes: 4 additions & 0 deletions src/handlers/sdp/RemoteSdp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ export class RemoteSdp {
return sdpTransform.write(this._sdpObject);
}

getMediaSection(idx: number): MediaSection | undefined {
return idx < this._mediaSections.length ? this._mediaSections[idx] : undefined;
}

private addMediaSection(newMediaSection: MediaSection): void {
if (!this._firstMid) {
this._firstMid = newMediaSection.mid;
Expand Down