From da0e4fb33d0c7441810f62e9efa55bfc0f5e9c23 Mon Sep 17 00:00:00 2001 From: Oliver Lazoroski Date: Thu, 10 Oct 2024 23:58:06 +0200 Subject: [PATCH] tests for changePublishQuality --- .../src/rtc/__tests__/Publisher.test.ts | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/packages/client/src/rtc/__tests__/Publisher.test.ts b/packages/client/src/rtc/__tests__/Publisher.test.ts index 0e0ea10894..f9e8e885e1 100644 --- a/packages/client/src/rtc/__tests__/Publisher.test.ts +++ b/packages/client/src/rtc/__tests__/Publisher.test.ts @@ -17,7 +17,8 @@ vi.mock('../../StreamSfuClient', () => { }; }); -vi.mock('../codecs', () => { +vi.mock('../codecs', async () => { + const codecs = await vi.importActual('../codecs'); return { getPreferredCodecs: vi.fn((): RTCRtpCodecCapability[] => [ { @@ -27,7 +28,7 @@ vi.mock('../codecs', () => { sdpFmtpLine: 'profile-level-id=42e01f', }, ]), - isSvcCodec: vi.fn(() => false), + isSvcCodec: codecs.isSvcCodec, }; }); @@ -418,5 +419,54 @@ describe('Publisher', () => { }, ]); }); + + it('supports empty rid in SVC', async () => { + const transceiver = new RTCRtpTransceiver(); + const setParametersSpy = vi + .spyOn(transceiver.sender, 'setParameters') + .mockResolvedValue(); + const getParametersSpy = vi + .spyOn(transceiver.sender, 'getParameters') + .mockReturnValue({ + codecs: [ + // @ts-expect-error incomplete data + { mimeType: 'video/VP9' }, + ], + encodings: [ + { + rid: undefined, // empty rid + active: true, + // @ts-expect-error not in the standard lib yet + scalabilityMode: 'L3T3_KEY', + }, + ], + }); + + // inject the transceiver + publisher['transceiverRegistry'][TrackType.VIDEO] = transceiver; + + await publisher['changePublishQuality']([ + { + name: 'q', + active: true, + maxBitrate: 50, + scaleResolutionDownBy: 1, + maxFramerate: 30, + scalabilityMode: 'L1T3', + }, + ]); + + expect(getParametersSpy).toHaveBeenCalled(); + expect(setParametersSpy).toHaveBeenCalled(); + expect(setParametersSpy.mock.calls[0][0].encodings).toEqual([ + { + active: true, + maxBitrate: 50, + scaleResolutionDownBy: 1, + maxFramerate: 30, + scalabilityMode: 'L1T3', + }, + ]); + }); }); });