fix: Don't detect audio from stale webrtc connection (#2429)

- Closes: #2417
This commit is contained in:
Dermot Duffy
2026-06-30 17:45:12 -07:00
committed by dermotduffy
parent 55732ead1d
commit 9535bb8aa0
3 changed files with 43 additions and 4 deletions
+20 -1
View File
@@ -82,8 +82,12 @@ describe('hasAudio', () => {
} as unknown as RTCRtpReceiver;
};
const createMockPeerConnection = (receivers: RTCRtpReceiver[]): RTCPeerConnection => {
const createMockPeerConnection = (
receivers: RTCRtpReceiver[],
connectionState: RTCPeerConnectionState = 'connected',
): RTCPeerConnection => {
return {
connectionState,
getReceivers: () => receivers,
} as unknown as RTCPeerConnection;
};
@@ -116,6 +120,21 @@ describe('hasAudio', () => {
// With no properties set on video, mayHaveAudio returns true (generous default)
expect(hasAudio(createMockVideo(), pc, '')).toBe(true);
});
it('should ignore receivers when connection is not established', () => {
const pc = createMockPeerConnection([createMockReceiver('audio', true)], 'new');
// Stale connection with muted receiver should fall through to
// mayHaveAudio (generous default returns true)
expect(hasAudio(createMockVideo(), pc, '')).toBe(true);
});
it('should fall through to mseCodecs when connection is not established', () => {
const pc = createMockPeerConnection([createMockReceiver('audio', true)], 'new');
// Stale WebRTC connection but MSE has audio codecs
expect(hasAudio(createMockVideo(), pc, 'avc1.640029,flac')).toBe(true);
});
});
describe('MSE codec detection', () => {