From 0a05d197cb668e4ca44192559e931bce39961649 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Tue, 1 Nov 2022 09:54:22 -0500 Subject: [PATCH] fix: clean up unused audio objects --- src/components/Room/useRoomAudio.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/components/Room/useRoomAudio.ts b/src/components/Room/useRoomAudio.ts index ecf9ffc..b4a4ecf 100644 --- a/src/components/Room/useRoomAudio.ts +++ b/src/components/Room/useRoomAudio.ts @@ -45,6 +45,10 @@ export function useRoomAudio({ peerRoom }: UseRoomAudioConfig) { if (peer.peerId === peerId) { newPeer.audioState = audioState + + if (audioState === AudioState.STOPPED) { + deletePeerAudio(peerId) + } } return newPeer @@ -125,6 +129,12 @@ export function useRoomAudio({ peerRoom }: UseRoomAudioConfig) { setAudioStream(newSelfStream) } + const deletePeerAudio = (peerId: string) => { + const newPeerAudios = { ...peerAudios } + delete newPeerAudios[peerId] + setPeerAudios(newPeerAudios) + } + const handleAudioForNewPeer = (peerId: string) => { if (audioStream) { peerRoom.addStream(audioStream, peerId) @@ -134,6 +144,7 @@ export function useRoomAudio({ peerRoom }: UseRoomAudioConfig) { const handleAudioForLeavingPeer = (peerId: string) => { if (audioStream) { peerRoom.removeStream(audioStream, peerId) + deletePeerAudio(peerId) } }