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
5 changes: 5 additions & 0 deletions .changeset/tired-views-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Ensure that sortPresets does NOT mutate values passed in via options into Room
6 changes: 6 additions & 0 deletions src/room/participant/publishUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ describe('customSimulcastLayers', () => {
expect(sortedPresets[1].encoding.maxFramerate).toBe(15);
expect(sortedPresets[2].encoding.maxFramerate).toBe(20);
});
it('does not mutate the passed-in array', () => {
const presets = [VideoPresets.h1440, VideoPresets.h360, VideoPresets.h1080, VideoPresets.h90];
const original = [...presets];
sortPresets(presets);
expect(presets).toEqual(original);
});
});

describe('screenShareSimulcastDefaults', () => {
Expand Down
5 changes: 4 additions & 1 deletion src/room/participant/publishUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ function encodingsFromPresets(
/** @internal */
export function sortPresets(presets: Array<VideoPreset> | undefined) {
if (!presets) return;
return presets.sort((a, b) => {
// Sort a copy so we don't mutate the caller's array in place. Mutating the
// passed-in simulcast layers can cause consumers that compare options by value
// (e.g. components-react's useLiveKitRoom) to detect a spurious change.
return presets.slice().sort((a, b) => {
const { encoding: aEnc } = a;
const { encoding: bEnc } = b;

Expand Down
Loading