fix: Broken voice states and connectivity drops
This commit is contained in:
@@ -75,6 +75,12 @@ export class VoiceActivityService implements OnDestroy {
|
||||
this.untrackStream(peerId);
|
||||
})
|
||||
);
|
||||
|
||||
this.subs.push(
|
||||
this.voiceConnection.onVoiceConnected.subscribe(() => {
|
||||
this.ensureAllRemoteStreamsTracked();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
trackLocalMic(userId: string, stream: MediaStream): void {
|
||||
@@ -124,6 +130,10 @@ export class VoiceActivityService implements OnDestroy {
|
||||
}
|
||||
|
||||
const ctx = new AudioContext();
|
||||
|
||||
if (ctx.state === 'suspended')
|
||||
void ctx.resume();
|
||||
|
||||
const analyser = ctx.createAnalyser();
|
||||
const sources = audioTracks.map((track) => ctx.createMediaStreamSource(new MediaStream([track])));
|
||||
|
||||
@@ -166,6 +176,18 @@ export class VoiceActivityService implements OnDestroy {
|
||||
this.stopPolling();
|
||||
}
|
||||
|
||||
private ensureAllRemoteStreamsTracked(): void {
|
||||
const peers = this.voiceConnection.getConnectedPeers();
|
||||
|
||||
for (const peerId of peers) {
|
||||
const stream = this.voiceConnection.getRemoteVoiceStream(peerId);
|
||||
|
||||
if (stream) {
|
||||
this.trackStream(peerId, stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ensurePolling(): void {
|
||||
if (this.animFrameId !== null)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user