From 47f60c3548582b06097ac559fed7fd278889f7a5 Mon Sep 17 00:00:00 2001 From: Oliver Lazoroski Date: Wed, 6 Nov 2024 16:55:40 +0100 Subject: [PATCH] fix: edge case where the length of enabledLayers doesn't match with the number of encodings --- packages/client/src/rtc/Publisher.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/client/src/rtc/Publisher.ts b/packages/client/src/rtc/Publisher.ts index 8cf7e67afa..690571291a 100644 --- a/packages/client/src/rtc/Publisher.ts +++ b/packages/client/src/rtc/Publisher.ts @@ -390,12 +390,14 @@ export class Publisher { let changed = false; for (const encoder of params.encodings) { - const layer = - usesSvcCodec || enabledLayers.length === 1 - ? // for SVC, we only have one layer (q) and often rid is omitted - enabledLayers[0] - : // for non-SVC, we need to find the layer by rid (simulcast) - enabledLayers.find((l) => l.name === encoder.rid); + const layer = usesSvcCodec + ? // for SVC, we only have one layer (q) and often rid is omitted + enabledLayers[0] + : // for non-SVC, we need to find the layer by rid (simulcast) + enabledLayers.find((l) => l.name === encoder.rid) ?? + (enabledLayers.length === 1 && params.encodings.length === 1) + ? enabledLayers[0] + : undefined; // flip 'active' flag only when necessary const shouldActivate = !!layer?.active;