Add audio layer toggles and reduce item emit volume
This commit is contained in:
@@ -4,6 +4,7 @@ import type { RemoteUser } from '../network/protocol';
|
||||
export type PeerRuntime = SpatialPeerRuntime & {
|
||||
id: string;
|
||||
pc: RTCPeerConnection;
|
||||
remoteStream?: MediaStream;
|
||||
};
|
||||
|
||||
type SendSignal = (targetId: string, payload: { sdp?: RTCSessionDescriptionInit; ice?: RTCIceCandidateInit }) => void;
|
||||
@@ -57,7 +58,12 @@ export class PeerManager {
|
||||
};
|
||||
|
||||
pc.ontrack = async (event) => {
|
||||
await this.audio.attachRemoteStream(peer, event.streams[0], this.outputDeviceId);
|
||||
peer.remoteStream = event.streams[0];
|
||||
if (this.audio.isVoiceLayerEnabled()) {
|
||||
await this.audio.attachRemoteStream(peer, event.streams[0], this.outputDeviceId);
|
||||
} else {
|
||||
this.audio.cleanupPeerAudio(peer);
|
||||
}
|
||||
};
|
||||
|
||||
if (isInitiator) {
|
||||
@@ -150,6 +156,19 @@ export class PeerManager {
|
||||
}
|
||||
}
|
||||
|
||||
suspendRemoteAudio(): void {
|
||||
for (const peer of this.peers.values()) {
|
||||
this.audio.cleanupPeerAudio(peer);
|
||||
}
|
||||
}
|
||||
|
||||
async resumeRemoteAudio(): Promise<void> {
|
||||
for (const peer of this.peers.values()) {
|
||||
if (!peer.remoteStream) continue;
|
||||
await this.audio.attachRemoteStream(peer, peer.remoteStream, this.outputDeviceId);
|
||||
}
|
||||
}
|
||||
|
||||
private tuneOpus(desc: RTCSessionDescriptionInit): RTCSessionDescriptionInit {
|
||||
if (!desc.sdp) return desc;
|
||||
const lines = desc.sdp.split('\r\n');
|
||||
|
||||
Reference in New Issue
Block a user