A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
test(livekit-client): drop vendored engine tests, crypto bench
Hampus0932077e2464
diff --git a/fluxer_app/pkgs/livekit-client/src/e2ee/worker/FrameCryptor.bench.ts b/fluxer_app/pkgs/livekit-client/src/e2ee/worker/FrameCryptor.bench.tsdeleted file mode 100644index 120247a5b..000000000--- a/fluxer_app/pkgs/livekit-client/src/e2ee/worker/FrameCryptor.bench.ts+++ /dev/null@@ -1,28 +0,0 @@-// SPDX-FileCopyrightText: 2024 LiveKit, Inc.-//-// SPDX-License-Identifier: Apache-2.0-import {test} from 'vitest';-import {getEncryptedFrameLayout, isFrameServerInjected} from './FrameCryptor.ts';--const sifTrailer = Uint8Array.from([0xde, 0xad, 0xbe, 0xef]);-const shortFrame = new Uint8Array(3);-const encryptedFrame = makeEncryptedFrame();--function makeEncryptedFrame(): Uint8Array {- const frame = new Uint8Array(1500);- frame[frame.length - 2] = 12;- frame[frame.length - 1] = 0;- return frame;-}--test('FrameCryptor frame guards', async ({bench}) => {- await bench('valid encrypted frame layout', () => {- getEncryptedFrameLayout(encryptedFrame.buffer, 10);- }).run();- await bench('short encrypted frame layout rejection', () => {- getEncryptedFrameLayout(shortFrame.buffer, 10);- }).run();- await bench('short SIF trailer rejection', () => {- isFrameServerInjected(shortFrame.buffer, sifTrailer);- }).run();-});diff --git a/fluxer_app/pkgs/livekit-client/src/room/PCTransport.test.ts b/fluxer_app/pkgs/livekit-client/src/room/PCTransport.test.tsdeleted file mode 100644index a827b691b..000000000--- a/fluxer_app/pkgs/livekit-client/src/room/PCTransport.test.ts+++ /dev/null@@ -1,385 +0,0 @@-// SPDX-FileCopyrightText: 2024 LiveKit, Inc.-//-// SPDX-License-Identifier: Apache-2.0-import type {MediaDescription} from 'sdp-transform';-import {parse} from 'sdp-transform';-import {describe, expect, it} from 'vitest';-import type {TrackBitrateInfo} from './PCTransport.ts';-import {- applyVideoStartBitrate,- collectStereoMids,- conformBundledCodecFmtp,- ensureAudioNackAndStereo,- ensureOpusFmtp,- ensureOpusStereoReception,- ensureVideoDDExtension,- placeholderMidsFromTransceivers,- videoSectionCanReceiveAV1,-} from './PCTransport.ts';-import {ddExtensionURI} from './utils.ts';--function videoMedia(- trackId: string,- fmtp: Array<{payload: number; config: string}>,- rtp: Array<{payload: number; codec: string}> = [{payload: 96, codec: 'H264'}],-): MediaDescription {- return {type: 'video', msid: `stream ${trackId}`, rtp, fmtp} as unknown as MediaDescription;-}--function opusMedia(config: string, mid = '0'): MediaDescription {- return {- type: 'audio',- mid,- port: 9,- protocol: 'UDP/TLS/RTP/SAVPF',- rtp: [{payload: 109, codec: 'opus', rate: 48000, encoding: 2}],- fmtp: [{payload: 109, config}],- } as unknown as MediaDescription;-}--function offerMedia(mid: string, trackId: string): MediaDescription {- const media = opusMedia('useinbandfec=1', mid);- media.msid = `- ${trackId}`;- return media;-}--function audioBitrateInfo(mid: string | null, trackId: string, stereo: boolean): TrackBitrateInfo {- return {- transceiver: {mid, sender: {track: {id: trackId}}} as unknown as RTCRtpTransceiver,- codec: 'opus',- maxbr: 320,- stereo,- };-}--function opusConfig(media: MediaDescription): string {- return media.fmtp.find((fmtp) => fmtp.payload === 109)?.config ?? '';-}--describe('applyVideoStartBitrate', () => {- function multiPayloadScreenMedia(): MediaDescription {- return videoMedia(- 'screen-track',- [- {payload: 116, config: 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f'},- {payload: 102, config: 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f'},- {payload: 108, config: 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f'},- ],- [- {payload: 116, codec: 'H264'},- {payload: 117, codec: 'rtx'},- {payload: 102, codec: 'H264'},- {payload: 108, codec: 'H264'},- ],- );- }-- it('adds a start bitrate to a non-SVC codec section', () => {- const media = videoMedia('camera-track', [- {payload: 96, config: 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f'},- ]);- expect(applyVideoStartBitrate(media, 'camera-track', 'H264', 1000, false)).toBe(96);- expect(media.fmtp[0]?.config).toBe(- 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f;x-google-start-bitrate=900',- );- });-- it('caps camera and screen share start bitrates at their own ceilings', () => {- const camera = videoMedia('camera-track', [{payload: 96, config: 'profile-level-id=42e01f'}]);- applyVideoStartBitrate(camera, 'camera-track', 'H264', 3000, false);- expect(camera.fmtp[0]?.config).toBe('profile-level-id=42e01f;x-google-start-bitrate=1000');-- const screen = videoMedia('screen-track', [{payload: 96, config: 'profile-level-id=42e01f'}]);- applyVideoStartBitrate(screen, 'screen-track', 'H264', 6000, true);- expect(screen.fmtp[0]?.config).toBe('profile-level-id=42e01f;x-google-start-bitrate=1500');- });-- it('keeps a screen share start bitrate above the frame dropper cliff', () => {- const screen = videoMedia('screen-track', [{payload: 96, config: 'profile-level-id=42e01f'}]);- applyVideoStartBitrate(screen, 'screen-track', 'H264', 300, true);- expect(screen.fmtp[0]?.config).toBe('profile-level-id=42e01f;x-google-start-bitrate=600');- });-- it('stamps every payload type the codec is offered under, not only the lead one', () => {- const media = multiPayloadScreenMedia();- expect(applyVideoStartBitrate(media, 'screen-track', 'H264', 6000, true)).toBe(116);- for (const fmtp of media.fmtp) {- expect(fmtp.config).toContain('x-google-start-bitrate=1500');- }- expect(media.fmtp.some((fmtp) => fmtp.payload === 117)).toBe(false);- });-- it('only touches the fmtp line for the matching payload', () => {- const media = videoMedia(- 'screen-track',- [- {payload: 96, config: 'profile-level-id=42e01f'},- {payload: 98, config: 'profile-id=0'},- ],- [- {payload: 96, codec: 'H264'},- {payload: 98, codec: 'VP9'},- ],- );- applyVideoStartBitrate(media, 'screen-track', 'VP9', 1500, true);- expect(media.fmtp[0]?.config).toBe('profile-level-id=42e01f');- expect(media.fmtp[1]?.config).toBe('profile-id=0;x-google-start-bitrate=1350');- });-- it('replaces a start bitrate an earlier offer wrote instead of keeping it', () => {- const media = videoMedia('camera-track', [- {payload: 96, config: 'profile-level-id=42e01f;x-google-start-bitrate=900'},- ]);- applyVideoStartBitrate(media, 'camera-track', 'H264', 2000, false);- expect(media.fmtp[0]?.config).toBe('profile-level-id=42e01f;x-google-start-bitrate=1000');- });-- it('leaves other tracks and missing codecs alone', () => {- const media = videoMedia('camera-track', [{payload: 96, config: 'profile-level-id=42e01f'}]);- expect(applyVideoStartBitrate(media, 'other-track', 'H264', 2000, false)).toBeUndefined();- expect(applyVideoStartBitrate(media, 'camera-track', 'AV1', 2000, false)).toBe(0);- expect(media.fmtp[0]?.config).toBe('profile-level-id=42e01f');- });-});--describe('ensureOpusFmtp', () => {- it('does not force stereo on a mono publication', () => {- const media = opusMedia('maxplaybackrate=48000;stereo=0;useinbandfec=1');- ensureOpusFmtp(media, 48000, false);- const config = opusConfig(media);- expect(config).toContain('minptime=10');- expect(config).toContain('useinbandfec=1');- expect(config).toContain('usedtx=0');- expect(config).toContain('maxaveragebitrate=48000');- expect(config).not.toContain('stereo=1');- });-- it('keeps stereo for a stereo publication', () => {- const media = opusMedia('maxplaybackrate=48000;useinbandfec=1');- ensureOpusFmtp(media, 320000, true);- const config = opusConfig(media);- expect(config).toContain('stereo=1');- expect(config).toContain('sprop-stereo=1');- expect(config).toContain('maxaveragebitrate=320000');- });-- it('preserves a stereo parameter the server negotiated', () => {- const media = opusMedia('minptime=10;stereo=1');- ensureOpusFmtp(media, 48000, false);- expect(opusConfig(media)).toContain('stereo=1');- });-});--describe('ensureAudioNackAndStereo', () => {- it('only stamps stereo on the listed mids', () => {- const mono = opusMedia('useinbandfec=1', '0');- ensureAudioNackAndStereo(mono as never, ['1'], []);- expect(opusConfig(mono)).not.toContain('stereo=1');-- const stereo = opusMedia('useinbandfec=1', '1');- ensureAudioNackAndStereo(stereo as never, ['1'], []);- expect(opusConfig(stereo)).toContain('stereo=1');- expect(opusConfig(stereo)).toContain('sprop-stereo=1');- });-});--describe('ensureOpusStereoReception', () => {- it.each(['recvonly', 'sendrecv'] as const)(- 'receives stereo in a %s section without declaring stereo capture',- (direction) => {- const media = opusMedia('useinbandfec=1;stereo=0;sprop-stereo=0;maxaveragebitrate=48000');- media.direction = direction;- ensureOpusStereoReception(media);- expect(opusConfig(media)).toBe('useinbandfec=1;sprop-stereo=0;maxaveragebitrate=48000;stereo=1');- },- );-- it('uses the default sendrecv direction when no direction is present', () => {- const media = opusMedia('useinbandfec=1');- ensureOpusStereoReception(media);- expect(opusConfig(media)).toBe('useinbandfec=1;stereo=1');- });-- it.each(['sendonly', 'inactive'] as const)('preserves a %s section', (direction) => {- const media = opusMedia('useinbandfec=1;stereo=0;sprop-stereo=0');- media.direction = direction;- ensureOpusStereoReception(media);- expect(opusConfig(media)).toBe('useinbandfec=1;stereo=0;sprop-stereo=0');- });-- it('preserves rejected sections and other media or codecs', () => {- const rejected = opusMedia('useinbandfec=1');- rejected.port = 0;- ensureOpusStereoReception(rejected);- expect(opusConfig(rejected)).toBe('useinbandfec=1');- const video = videoMedia('camera', [{payload: 96, config: 'profile-level-id=42e01f'}]);- ensureOpusStereoReception(video);- expect(video.fmtp[0]?.config).toBe('profile-level-id=42e01f');- const pcm = opusMedia('useinbandfec=1');- pcm.rtp[0]!.codec = 'PCMU';- ensureOpusStereoReception(pcm);- expect(opusConfig(pcm)).toBe('useinbandfec=1');- });-});--describe('collectStereoMids', () => {- it('matches the offer media section by msid before the transceiver has a mid', () => {- const media = [offerMedia('0', 'mic-track'), offerMedia('1', 'screenshare-track')];- expect(collectStereoMids([audioBitrateInfo(null, 'screenshare-track', true)], media)).toEqual(['1']);- });-- it('stamps stereo on the first offer for a new stereo publication', () => {- const media = [offerMedia('0', 'mic-track'), offerMedia('1', 'screenshare-track')];- const stereoMids = collectStereoMids([audioBitrateInfo(null, 'screenshare-track', true)], media);- for (const m of media) {- ensureAudioNackAndStereo(m as never, stereoMids, []);- }- expect(opusConfig(media[0]!)).not.toContain('stereo=1');- expect(opusConfig(media[1]!)).toContain('stereo=1');- expect(opusConfig(media[1]!)).toContain('sprop-stereo=1');- });-- it('uses the assigned mid once renegotiation has one', () => {- const media = [offerMedia('0', 'mic-track'), offerMedia('1', 'screenshare-track')];- expect(collectStereoMids([audioBitrateInfo('1', 'screenshare-track', true)], media)).toEqual(['1']);- });-- it('leaves mono publications out', () => {- const media = [offerMedia('0', 'mic-track')];- expect(collectStereoMids([audioBitrateInfo(null, 'mic-track', false)], media)).toEqual([]);- });-});--const singlePcOffer = `v=0-o=- 0 0 IN IP4 127.0.0.1-s=--t=0 0-a=group:BUNDLE 0 1 2-m=video 9 UDP/TLS/RTP/SAVPF 96 45-c=IN IP4 0.0.0.0-a=mid:0-a=sendonly-a=msid:s cam-a=rtpmap:96 VP8/90000-a=rtpmap:45 AV1/90000-a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time-a=extmap:11 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id-m=video 9 UDP/TLS/RTP/SAVPF 96 45-c=IN IP4 0.0.0.0-a=mid:1-a=recvonly-a=rtpmap:96 VP8/90000-a=rtpmap:45 AV1/90000-a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time-m=video 9 UDP/TLS/RTP/SAVPF 96-c=IN IP4 0.0.0.0-a=mid:2-a=recvonly-a=rtpmap:96 VP8/90000-a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time`;--const sectionOf = (sdp: ReturnType<typeof parse>, mid: string) => sdp.media.find((media) => `${media.mid}` === mid)!;-const ddOf = (sdp: ReturnType<typeof parse>, mid: string) =>- sectionOf(sdp, mid).ext?.find((ext) => ext.uri === ddExtensionURI)?.value;--describe('videoSectionCanReceiveAV1', () => {- it('is true for a section we receive on that kept AV1, false otherwise', () => {- const sdp = parse(singlePcOffer);- expect(videoSectionCanReceiveAV1(sectionOf(sdp, '1'))).toBe(true);- expect(videoSectionCanReceiveAV1(sectionOf(sdp, '0'))).toBe(false);- expect(videoSectionCanReceiveAV1(sectionOf(sdp, '2'))).toBe(false);- });-});--describe('ensureVideoDDExtension', () => {- it('assigns an id above every extension in the bundle and reuses it', () => {- const sdp = parse(singlePcOffer);- expect(ensureVideoDDExtension(sectionOf(sdp, '1'), sdp, 0)).toBe(12);- expect(ddOf(sdp, '1')).toBe(12);- expect(ensureVideoDDExtension(sectionOf(sdp, '2'), sdp, 12)).toBe(12);- expect(ddOf(sdp, '2')).toBe(12);- });-- it('adopts an id the bundle already maps the extension to', () => {- const sdp = parse(singlePcOffer);- sectionOf(sdp, '0').ext!.push({value: 13, uri: ddExtensionURI});- expect(ensureVideoDDExtension(sectionOf(sdp, '1'), sdp, 7)).toBe(13);- expect(ddOf(sdp, '1')).toBe(13);- });-- it('leaves a section that already has the extension alone', () => {- const sdp = parse(`${singlePcOffer}\na=extmap:3 ${ddExtensionURI}`);- expect(ensureVideoDDExtension(sectionOf(sdp, '2'), sdp, 0)).toBe(3);- expect(sectionOf(sdp, '2').ext).toHaveLength(2);- });-});--describe('placeholderMidsFromTransceivers', () => {- function transceiver(- mid: string | null,- track: MediaStreamTrack | null,- currentDirection: RTCRtpTransceiverDirection | null,- ): RTCRtpTransceiver {- return {mid, currentDirection, sender: {track}} as unknown as RTCRtpTransceiver;- }-- it('keeps unused trackless sections that still hold an m-line', () => {- const mids = placeholderMidsFromTransceivers([- transceiver('3', null, 'inactive'),- transceiver('4', null, null),- transceiver('7', {} as MediaStreamTrack, 'sendonly'),- ]);- expect(mids).toEqual(new Set(['3', '4']));- });-- it('drops a transceiver that unpublish stopped so its recycled m-section is not fmtp-conformed', () => {- expect(placeholderMidsFromTransceivers([transceiver('7', null, 'stopped')])).toEqual(new Set());- });-- it.each(['recvonly', 'sendrecv'] as const)(- 'preserves a negotiated %s receiver without a local sender',- (direction) => {- expect(placeholderMidsFromTransceivers([transceiver('0', null, direction)])).toEqual(new Set());- },- );-- it.each(['sendonly', 'sendrecv', undefined] as const)(- 'preserves a receiver activated by a remote %s answer before currentDirection updates',- (direction) => {- const incoming = opusMedia('useinbandfec=1');- incoming.direction = direction;- expect(placeholderMidsFromTransceivers([transceiver('0', null, null)], [incoming])).toEqual(new Set());- },- );-- it('keeps inactive and rejected remote sections eligible for placeholder conformance', () => {- const inactive = opusMedia('useinbandfec=1', '0');- inactive.direction = 'inactive';- const rejected = opusMedia('useinbandfec=1', '1');- rejected.direction = 'sendonly';- rejected.port = 0;- expect(- placeholderMidsFromTransceivers(- [transceiver('0', null, 'inactive'), transceiver('1', null, null)],- [inactive, rejected],- ),- ).toEqual(new Set(['0', '1']));- });-- it('starting a stereo share preserves incoming microphone fmtp while conforming unused placeholders', () => {- const microphone = opusMedia('useinbandfec=1;maxaveragebitrate=64000', '0');- const placeholder = opusMedia('useinbandfec=1;usedtx=1', '1');- const screenShare = opusMedia('useinbandfec=1', '2');- ensureOpusFmtp(screenShare, 128000, true);- const microphoneConfig = opusConfig(microphone);- const mids = placeholderMidsFromTransceivers([- transceiver('0', null, 'recvonly'),- transceiver('1', null, 'inactive'),- transceiver('2', {} as MediaStreamTrack, 'sendonly'),- ]);- conformBundledCodecFmtp([microphone, placeholder, screenShare], (media) => mids.has(String(media.mid)));- expect(opusConfig(microphone)).toBe(microphoneConfig);- expect(opusConfig(screenShare)).toContain('stereo=1');- expect(opusConfig(placeholder)).toBe(opusConfig(screenShare));- });-});diff --git a/fluxer_app/pkgs/livekit-client/src/room/RTCEngine.test.ts b/fluxer_app/pkgs/livekit-client/src/room/RTCEngine.test.tsdeleted file mode 100644index 328cf6008..000000000--- a/fluxer_app/pkgs/livekit-client/src/room/RTCEngine.test.ts+++ /dev/null@@ -1,291 +0,0 @@-// SPDX-FileCopyrightText: 2024 LiveKit, Inc.-//-// SPDX-License-Identifier: Apache-2.0-import {describe, expect, it} from 'vitest';-import type {InternalRoomOptions} from '../options.ts';-import {EngineEvent} from './events.ts';-import RTCEngine, {selectPublisherCodecPreferences} from './RTCEngine.ts';--function codec(- mimeType: string,- sdpFmtpLine?: string,-): RTCRtpCapabilities['codecs'][number] & {- sdpFmtpLine?: string;-} {- return {- mimeType,- clockRate: 90000,- ...(sdpFmtpLine ? {sdpFmtpLine} : {}),- };-}--describe('selectPublisherCodecPreferences', () => {- const constrainedBaselineLine = 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f';- const baselineLine = 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f';- const mainLine = 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f';- const highLine = 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=64001f';-- it('offers High first, then the one profile this server always registers, then the ones it registers nowhere', () => {- const constrainedBaseline = codec('video/H264', constrainedBaselineLine);- const baseline = codec('video/H264', baselineLine);- const highProfile = codec('video/H264', highLine);- const rtx = codec('video/rtx');- const preferences = selectPublisherCodecPreferences('h264', [constrainedBaseline, rtx, baseline, highProfile]);- expect(preferences).toEqual([highProfile, constrainedBaseline, baseline, rtx]);- });-- it('never leads with Main or Baseline, which this server registers nowhere and deletes from the answer', () => {- const constrainedBaseline = codec('video/H264', constrainedBaselineLine);- const mainProfile = codec('video/H264', mainLine);- const baseline = codec('video/H264', baselineLine);- const preferences = selectPublisherCodecPreferences('h264', [mainProfile, baseline, constrainedBaseline]);- expect(preferences).toEqual([constrainedBaseline, mainProfile, baseline]);- });-- function chromiumCapabilities() {- return [- codec('video/H264', 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f'),- codec('video/H264', 'level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f'),- codec('video/H264', 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f'),- codec('video/H264', 'level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f'),- codec('video/H264', 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f'),- codec('video/H264', 'level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=4d001f'),- codec('video/H264', 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640034'),- ];- }-- it('offers High first out of the capabilities Chromium reports, so the only hardware profile this server registers wins', () => {- const preferences = selectPublisherCodecPreferences('h264', chromiumCapabilities());- expect(preferences.map((entry) => entry.sdpFmtpLine)).toEqual([- 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640034',- 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f',- 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f',- 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f',- 'level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f',- 'level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=4d001f',- 'level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f',- ]);- });-- function levelSpread() {- const constrainedBaseline = codec('video/H264', constrainedBaselineLine);- const mainProfile = codec('video/H264', mainLine);- const highProfileLevel31 = codec('video/H264', highLine);- const highProfileLevel51 = codec(- 'video/H264',- 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640033',- );- const constrainedHigh = codec(- 'video/H264',- 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640c1f',- );- return {constrainedBaseline, mainProfile, highProfileLevel31, highProfileLevel51, constrainedHigh};- }-- it('ranks High and Constrained High above Constrained Baseline, whatever level each one reports', () => {- const {constrainedBaseline, mainProfile, highProfileLevel31, highProfileLevel51, constrainedHigh} = levelSpread();- const preferences = selectPublisherCodecPreferences('h264', [- mainProfile,- highProfileLevel31,- highProfileLevel51,- constrainedHigh,- constrainedBaseline,- ]);- expect(preferences).toEqual([- highProfileLevel31,- highProfileLevel51,- constrainedHigh,- constrainedBaseline,- mainProfile,- ]);- });-- it('ranks packetization-mode=1 above packetization-mode=0, which no hardware encoder takes', () => {- const constrainedBaselineMode0 = codec(- 'video/H264',- 'level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f',- );- const constrainedBaselineMode1 = codec('video/H264', constrainedBaselineLine);- const highProfileMode0 = codec(- 'video/H264',- 'level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=640033',- );- const highProfileMode1 = codec(- 'video/H264',- 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640033',- );- const capabilities = [highProfileMode0, constrainedBaselineMode0, constrainedBaselineMode1, highProfileMode1];- const expected = [highProfileMode1, constrainedBaselineMode1, highProfileMode0, constrainedBaselineMode0];- expect(selectPublisherCodecPreferences('h264', capabilities)).toEqual(expected);- });-- it('puts the chosen codec first and keeps every other codec in browser capability order', () => {- const vp9 = codec('video/VP9');- const vp8 = codec('video/VP8');- const rtx = codec('video/rtx');- expect(selectPublisherCodecPreferences('vp9', [vp8, rtx, vp9])).toEqual([vp9, vp8, rtx]);- });-- it('keeps the other codecs so a later publication on the same connection can negotiate them', () => {- const vp9 = codec('video/VP9');- const av1 = codec('video/AV1');- const h264 = codec('video/H264', constrainedBaselineLine);- const preferences = selectPublisherCodecPreferences('vp9', [av1, h264, vp9]);- expect(preferences.map((entry) => entry.mimeType)).toEqual(['video/VP9', 'video/AV1', 'video/H264']);- });-- it('ranks the H.264 profiles it leaves behind the chosen codec', () => {- const vp8 = codec('video/VP8');- const highProfile = codec('video/H264', 'level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640033');- const constrainedBaseline = codec('video/H264', constrainedBaselineLine);- const capabilities = [vp8, highProfile, constrainedBaseline];- expect(selectPublisherCodecPreferences('vp8', capabilities)).toEqual([vp8, highProfile, constrainedBaseline]);- expect(selectPublisherCodecPreferences('vp8', capabilities, new Set(['42e0']))).toEqual([- vp8,- constrainedBaseline,- highProfile,- ]);- });-- it('returns nothing when the sender cannot encode the chosen codec', () => {- expect(selectPublisherCodecPreferences('av1', [codec('video/VP8'), codec('video/rtx')])).toEqual([]);- });-- it('only lets a profile this host encodes in hardware outrank Constrained Baseline', () => {- const constrainedBaseline = codec('video/H264', constrainedBaselineLine);- const highProfile = codec('video/H264', highLine);- const capabilities = [highProfile, constrainedBaseline];- expect(selectPublisherCodecPreferences('h264', capabilities, new Set(['42e0']))).toEqual([- constrainedBaseline,- highProfile,- ]);- expect(selectPublisherCodecPreferences('h264', capabilities, new Set(['6400', '42e0']))).toEqual([- highProfile,- constrainedBaseline,- ]);- });-- it('falls back to the static order when nothing was measured or nothing is hardware', () => {- const constrainedBaseline = codec('video/H264', constrainedBaselineLine);- const highProfile = codec('video/H264', highLine);- const capabilities = [constrainedBaseline, highProfile];- expect(selectPublisherCodecPreferences('h264', capabilities)).toEqual([highProfile, constrainedBaseline]);- expect(selectPublisherCodecPreferences('h264', capabilities, new Set())).toEqual([- highProfile,- constrainedBaseline,- ]);- });-- it('keeps packetization-mode=1 ahead of a hardware packetization-mode=0 profile', () => {- const constrainedBaselineMode1 = codec('video/H264', constrainedBaselineLine);- const highProfileMode0 = codec(- 'video/H264',- 'level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=64001f',- );- expect(- selectPublisherCodecPreferences('h264', [highProfileMode0, constrainedBaselineMode1], new Set(['6400'])),- ).toEqual([constrainedBaselineMode1, highProfileMode0]);- });-});--describe('publisher data channels before negotiation', () => {- function engineWithPublisherChannels(hasPublisherChannels: boolean) {- const engine = new RTCEngine({} as InternalRoomOptions);- const created: Array<string> = [];- const internals = engine as unknown as {- _isClosed: boolean;- pcManager: unknown;- dataChannels: {hasPublisherChannels: boolean; createPublisherChannels: () => void};- };- internals._isClosed = false;- internals.dataChannels = {- hasPublisherChannels,- createPublisherChannels: () => created.push('publisher'),- };- internals.pcManager = {- requirePublisher: () => {},- negotiate: async () => {},- publisher: {- off: () => {},- once: () => {},- getTransceivers: () => [{} as RTCRtpTransceiver],- },- };- return {engine, created};- }-- it('creates them on a renegotiation that already has transceivers', async () => {- const {engine, created} = engineWithPublisherChannels(false);- await engine.negotiate();- expect(created).toEqual(['publisher']);- });-- it('leaves the existing channels alone', async () => {- const {engine, created} = engineWithPublisherChannels(true);- await engine.negotiate();- expect(created).toEqual([]);- });-});--describe('negotiation aborts', () => {- function negotiableEngine() {- const engine = new RTCEngine({} as InternalRoomOptions);- const controllers: Array<AbortController> = [];- const internals = engine as unknown as {- _isClosed: boolean;- pcManager: unknown;- dataChannels: {hasPublisherChannels: boolean};- pendingNegotiationAborts: Set<() => void>;- };- internals._isClosed = false;- internals.dataChannels = {hasPublisherChannels: true};- internals.pcManager = {- requirePublisher: () => {},- publisher: {- off: () => {},- once: () => {},- getTransceivers: () => [{} as RTCRtpTransceiver],- },- negotiate: (abortController: AbortController) =>- new Promise<void>((_resolve, reject) => {- controllers.push(abortController);- abortController.signal.addEventListener('abort', () => reject(new Error('negotiation aborted')), {- once: true,- });- }),- };- return {engine, controllers, pendingAborts: internals.pendingNegotiationAborts};- }-- it('keeps one listener pair however many negotiations are in flight, and aborts every one', async () => {- const {engine, controllers, pendingAborts} = negotiableEngine();- const closingListeners = engine.listenerCount(EngineEvent.Closing);- const restartingListeners = engine.listenerCount(EngineEvent.Restarting);-- const pending = Array.from({length: 20}, () => engine.negotiate());- expect(engine.listenerCount(EngineEvent.Closing)).toBe(closingListeners);- expect(engine.listenerCount(EngineEvent.Restarting)).toBe(restartingListeners);- expect(pendingAborts.size).toBe(20);-- engine.emit(EngineEvent.Closing);- await expect(Promise.all(pending)).resolves.toHaveLength(20);- expect(controllers.every((controller) => controller.signal.aborted)).toBe(true);- expect(pendingAborts.size).toBe(0);- });-- it('re-arms after a restart so a later negotiation is not aborted on arrival', async () => {- const {engine, controllers, pendingAborts} = negotiableEngine();- const firstBatch = [engine.negotiate(), engine.negotiate()];- engine.emit(EngineEvent.Restarting);- await expect(Promise.all(firstBatch)).resolves.toHaveLength(2);-- const afterRestart = engine.negotiate();- expect(controllers).toHaveLength(3);- expect(controllers[2].signal.aborted).toBe(false);- expect(pendingAborts.size).toBe(1);-- engine.emit(EngineEvent.Restarting);- await expect(afterRestart).resolves.toBeUndefined();- expect(pendingAborts.size).toBe(0);- });-});diff --git a/fluxer_app/pkgs/livekit-client/src/room/Room.test.ts b/fluxer_app/pkgs/livekit-client/src/room/Room.test.tsdeleted file mode 100644index 94d9707a1..000000000--- a/fluxer_app/pkgs/livekit-client/src/room/Room.test.ts+++ /dev/null@@ -1,22 +0,0 @@-// SPDX-FileCopyrightText: 2024 LiveKit, Inc.-//-// SPDX-License-Identifier: Apache-2.0-import {describe, expect, it, vi} from 'vitest';-import type {InternalRoomOptions} from '../options.ts';-import Room from './Room.ts';-import RTCEngine from './RTCEngine.ts';--describe('Room createEngine option', () => {- it('builds the engine through the factory and hands it the merged room options', () => {- const createEngine = vi.fn((options: InternalRoomOptions) => new RTCEngine(options));- const room = new Room({createEngine, dynacast: false});- expect(createEngine).toHaveBeenCalledTimes(1);- expect(room.engine).toBe(createEngine.mock.results[0]?.value);- expect(createEngine.mock.calls[0]?.[0]).toBe(room.options);- });-- it('builds a plain RTCEngine when no factory is set', () => {- const room = new Room({dynacast: false});- expect(room.engine).toBeInstanceOf(RTCEngine);- });-});