Skip to content

Commit ad9c101

Browse files
authored
Ensure mid is always interpreted as string (#1641)
1 parent 5c4718c commit ad9c101

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"livekit-client": patch
3+
---
4+
5+
Ensure mid is always interpreted as string

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"@size-limit/webpack": "^11.2.0",
8484
"@trivago/prettier-plugin-sort-imports": "^5.0.0",
8585
"@types/events": "^3.0.3",
86-
"@types/sdp-transform": "2.4.10",
86+
"@types/sdp-transform": "2.15.0",
8787
"@types/ua-parser-js": "0.7.39",
8888
"@typescript-eslint/eslint-plugin": "7.18.0",
8989
"@typescript-eslint/parser": "7.18.0",

pnpm-lock.yaml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/room/PCTransport.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,11 @@ export default class PCTransport extends EventEmitter {
165165
} else if (sd.type === 'answer') {
166166
const sdpParsed = parse(sd.sdp ?? '');
167167
sdpParsed.media.forEach((media) => {
168+
const mid = getMidString(media.mid!);
168169
if (media.type === 'audio') {
169170
// mung sdp for opus bitrate settings
170171
this.trackBitrates.some((trackbr): boolean => {
171-
if (!trackbr.transceiver || media.mid != trackbr.transceiver.mid) {
172+
if (!trackbr.transceiver || mid != trackbr.transceiver.mid) {
172173
return false;
173174
}
174175

@@ -593,6 +594,9 @@ function ensureAudioNackAndStereo(
593594
stereoMids: string[],
594595
nackMids: string[],
595596
) {
597+
// sdp-transform types don't include number however the parser outputs mids as numbers in some cases
598+
const mid = getMidString(media.mid!);
599+
596600
// found opus codec to add nack fb
597601
let opusPayload = 0;
598602
media.rtp.some((rtp): boolean => {
@@ -610,7 +614,7 @@ function ensureAudioNackAndStereo(
610614
}
611615

612616
if (
613-
nackMids.includes(media.mid!) &&
617+
nackMids.includes(mid) &&
614618
!media.rtcpFb.some((fb) => fb.payload === opusPayload && fb.type === 'nack')
615619
) {
616620
media.rtcpFb.push({
@@ -619,7 +623,7 @@ function ensureAudioNackAndStereo(
619623
});
620624
}
621625

622-
if (stereoMids.includes(media.mid!)) {
626+
if (stereoMids.includes(mid)) {
623627
media.fmtp.some((fmtp): boolean => {
624628
if (fmtp.payload === opusPayload) {
625629
if (!fmtp.config.includes('stereo=1')) {
@@ -642,6 +646,7 @@ function extractStereoAndNackAudioFromOffer(offer: RTCSessionDescriptionInit): {
642646
const sdpParsed = parse(offer.sdp ?? '');
643647
let opusPayload = 0;
644648
sdpParsed.media.forEach((media) => {
649+
const mid = getMidString(media.mid!);
645650
if (media.type === 'audio') {
646651
media.rtp.some((rtp): boolean => {
647652
if (rtp.codec === 'opus') {
@@ -652,13 +657,13 @@ function extractStereoAndNackAudioFromOffer(offer: RTCSessionDescriptionInit): {
652657
});
653658

654659
if (media.rtcpFb?.some((fb) => fb.payload === opusPayload && fb.type === 'nack')) {
655-
nackMids.push(media.mid!);
660+
nackMids.push(mid);
656661
}
657662

658663
media.fmtp.some((fmtp): boolean => {
659664
if (fmtp.payload === opusPayload) {
660665
if (fmtp.config.includes('sprop-stereo=1')) {
661-
stereoMids.push(media.mid!);
666+
stereoMids.push(mid);
662667
}
663668
return true;
664669
}
@@ -682,3 +687,7 @@ function ensureIPAddrMatchVersion(media: MediaDescription) {
682687
}
683688
}
684689
}
690+
691+
function getMidString(mid: string | number) {
692+
return typeof mid === 'number' ? mid.toFixed(0) : mid;
693+
}

0 commit comments

Comments
 (0)