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:
+12
-18
@@ -7,7 +7,6 @@ import { Store } from '@ngrx/store';
|
||||
import { STORAGE_KEY_USER_VOLUMES } from '../../../../core/constants';
|
||||
import { jsonStorage } from '../../../../infrastructure/persistence/json-storage.service';
|
||||
import { ScreenShareFacade } from '../../../../domains/screen-share';
|
||||
import { User } from '../../../../shared-kernel';
|
||||
import { selectAllUsers, selectCurrentUser } from '../../../../store/users/users.selectors';
|
||||
import { VoiceConnectionFacade } from '../facades/voice-connection.facade';
|
||||
|
||||
@@ -331,7 +330,7 @@ export class VoicePlaybackService {
|
||||
if (!pipeline)
|
||||
return;
|
||||
|
||||
if (this.deafened || this.captureEchoSuppressed || this.isUserMuted(peerId) || !this.isPeerInCurrentVoiceRoom(peerId)) {
|
||||
if (this.deafened || this.captureEchoSuppressed || this.isUserMuted(peerId) || !this.mayHearPeer(peerId)) {
|
||||
pipeline.gainNode.gain.value = 0;
|
||||
return;
|
||||
}
|
||||
@@ -346,22 +345,17 @@ export class VoicePlaybackService {
|
||||
this.peerPipelines.forEach((_pipeline, peerId) => this.applyGain(peerId));
|
||||
}
|
||||
|
||||
private isPeerInCurrentVoiceRoom(peerId: string): boolean {
|
||||
const localVoiceState = this.currentUser()?.voiceState;
|
||||
|
||||
if (!localVoiceState?.isConnected || !localVoiceState.roomId || !localVoiceState.serverId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const remoteVoiceState = this.findUserForPeer(peerId)?.voiceState;
|
||||
|
||||
return !!remoteVoiceState?.isConnected
|
||||
&& remoteVoiceState.roomId === localVoiceState.roomId
|
||||
&& remoteVoiceState.serverId === localVoiceState.serverId;
|
||||
}
|
||||
|
||||
private findUserForPeer(peerId: string): User | undefined {
|
||||
return this.allUsers().find((user) => user.id === peerId || user.oderId === peerId || user.peerId === peerId);
|
||||
/**
|
||||
* Whether this peer's audio may be audible.
|
||||
*
|
||||
* The roster is gossip: the signal server broadcasts `user_left` for any socket it
|
||||
* declares dead, which used to mute a peer still sitting in our channel. Playback
|
||||
* therefore asks the voice session, which weighs the roster against what the peer
|
||||
* itself reported over its data channel, and holds a stream we already receive when
|
||||
* neither confirms nor denies.
|
||||
*/
|
||||
private mayHearPeer(peerId: string): boolean {
|
||||
return this.voiceConnection.mayHearPeerVoice(peerId, this.rawRemoteStreams.has(peerId));
|
||||
}
|
||||
|
||||
private syncOutgoingVoiceRouting(): void {
|
||||
|
||||
Reference in New Issue
Block a user