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:
+20
-1
@@ -27,7 +27,7 @@ import {
|
||||
import { Subscription } from 'rxjs';
|
||||
import { VoiceConnectionFacade } from '../facades/voice-connection.facade';
|
||||
import { DebuggingService } from '../../../../core/services/debugging.service';
|
||||
/* eslint-disable @typescript-eslint/member-ordering, @typescript-eslint/prefer-for-of, max-statements-per-line */
|
||||
/* eslint-disable @typescript-eslint/prefer-for-of, max-statements-per-line */
|
||||
|
||||
const SPEAKING_THRESHOLD = 0.015;
|
||||
const SILENT_FRAME_GRACE = 8;
|
||||
@@ -50,6 +50,8 @@ export class VoiceActivityService implements OnDestroy {
|
||||
private readonly debugging = inject(DebuggingService);
|
||||
|
||||
private readonly tracked = new Map<string, TrackedStream>();
|
||||
/** The id the local microphone is tracked under, so it can follow a device switch. */
|
||||
private localMicUserId: string | null = null;
|
||||
private animFrameId: number | null = null;
|
||||
private readonly subs: Subscription[] = [];
|
||||
private readonly _speakingMap = signal<ReadonlyMap<string, boolean>>(new Map());
|
||||
@@ -84,13 +86,30 @@ export class VoiceActivityService implements OnDestroy {
|
||||
}
|
||||
|
||||
trackLocalMic(userId: string, stream: MediaStream): void {
|
||||
this.localMicUserId = userId;
|
||||
this.trackStream(userId, stream);
|
||||
}
|
||||
|
||||
untrackLocalMic(userId: string): void {
|
||||
if (this.localMicUserId === userId) {
|
||||
this.localMicUserId = null;
|
||||
}
|
||||
|
||||
this.untrackStream(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Point the local speaking indicator at a replacement microphone stream,
|
||||
* so switching devices mid-call does not leave it watching a dead track.
|
||||
*/
|
||||
refreshLocalMicStream(stream: MediaStream): void {
|
||||
if (!this.localMicUserId) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.trackStream(this.localMicUserId, stream);
|
||||
}
|
||||
|
||||
isSpeaking(userId: string): Signal<boolean> {
|
||||
const entry = this.tracked.get(userId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user