fix(voice): route media on evidence and switch devices without dropping the call
Outgoing voice was gated on the observer's roster copy of the remote user's voice state, which is signaling gossip. The signal server broadcasts `user_left` for any socket it declares dead, so a suspended laptop or a flaky hop wiped that copy and the observer detached its microphone from a peer that never left the channel - a silent member with no way back through the UI. `decideVoicePathRouting` now closes a path only on positive evidence: we left voice, the peer itself reported another channel or none, or the connection is gone. Missing gossip holds an established path instead. Opening still needs confirmation, so a guess never starts sending; the same rule gates playback, camera video, and the microphone a new connection puts in its first offer. Peers are also asked for their voice state when a connection or data channel comes up, so a rebuilt path re-confirms itself. Alongside it, the microphone can be switched mid-call: capture moves to a device service and rules, the live track is swapped with `replaceTrack` so the session is never renegotiated, and the speaking indicator follows the new stream.
This commit is contained in:
+30
-2
@@ -13,10 +13,12 @@ import { VoiceConnectionFacade } from '../facades/voice-connection.facade';
|
||||
import { VoicePlaybackService } from './voice-playback.service';
|
||||
|
||||
let audioContextCount = 0;
|
||||
let createdGainNodes: { gain: { value: number } }[] = [];
|
||||
|
||||
describe('VoicePlaybackService', () => {
|
||||
beforeEach(() => {
|
||||
audioContextCount = 0;
|
||||
createdGainNodes = [];
|
||||
installAudioDomMocks();
|
||||
installLocalStorageMock();
|
||||
});
|
||||
@@ -94,6 +96,27 @@ describe('VoicePlaybackService', () => {
|
||||
expect(audioContextCount).toBe(1);
|
||||
expect(context.service.getUserVolume('peer-1')).toBe(100);
|
||||
});
|
||||
|
||||
// The roster is gossip. A peer we already receive audio from stays audible unless the
|
||||
// voice session has positive evidence it left, otherwise a dropped socket silences a
|
||||
// member who never went anywhere.
|
||||
it('keeps a peer audible while the voice session holds the path open', () => {
|
||||
const context = createServiceContext({ isVoiceConnected: true });
|
||||
|
||||
context.service.handleRemoteStream('peer-1', createMockAudioStream(['track-a']), connectedOptions());
|
||||
|
||||
expect(context.voiceConnection.mayHearPeerVoice).toHaveBeenCalledWith('peer-1', true);
|
||||
expect(createdGainNodes.at(-1)?.gain.value).toBe(1);
|
||||
});
|
||||
|
||||
it('mutes a peer the voice session reports as gone from our channel', () => {
|
||||
const context = createServiceContext({ isVoiceConnected: true });
|
||||
|
||||
context.voiceConnection.mayHearPeerVoice.mockReturnValue(false);
|
||||
context.service.handleRemoteStream('peer-1', createMockAudioStream(['track-a']), connectedOptions());
|
||||
|
||||
expect(createdGainNodes.at(-1)?.gain.value).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
interface ServiceContext {
|
||||
@@ -106,6 +129,7 @@ interface ServiceContext {
|
||||
getRemoteVoiceStream: ReturnType<typeof vi.fn>;
|
||||
getConnectedPeers: ReturnType<typeof vi.fn>;
|
||||
syncOutgoingVoiceRouting: ReturnType<typeof vi.fn>;
|
||||
mayHearPeerVoice: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
remoteStream$: Subject<{ peerId: string; stream: MediaStream }>;
|
||||
}
|
||||
@@ -119,7 +143,8 @@ function createServiceContext(options: { isVoiceConnected?: boolean } = {}): Ser
|
||||
onPeerDisconnected: new Subject<string>(),
|
||||
getRemoteVoiceStream: vi.fn(() => null),
|
||||
getConnectedPeers: vi.fn(() => []),
|
||||
syncOutgoingVoiceRouting: vi.fn()
|
||||
syncOutgoingVoiceRouting: vi.fn(),
|
||||
mayHearPeerVoice: vi.fn(() => true)
|
||||
};
|
||||
const screenShare = {
|
||||
isScreenShareRemotePlaybackSuppressed: signal(false),
|
||||
@@ -237,10 +262,13 @@ function installAudioDomMocks(): void {
|
||||
}
|
||||
|
||||
createGain() {
|
||||
return {
|
||||
const gainNode = {
|
||||
gain: { value: 0 },
|
||||
connect: vi.fn()
|
||||
};
|
||||
|
||||
createdGainNodes.push(gainNode);
|
||||
return gainNode;
|
||||
}
|
||||
|
||||
createMediaStreamSource() {
|
||||
|
||||
Reference in New Issue
Block a user