From c54703d7d758644f8c830c17ee307b4f3ec56a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Fri, 12 Feb 2021 21:48:47 +0100 Subject: [PATCH] destroy WS and WebRTC peers before assigning. --- internal/session/session.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/session/session.go b/internal/session/session.go index 8b667a15..ba6c6f3e 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -118,6 +118,12 @@ func (session *SessionCtx) GetState() types.MemberState { // --- func (session *SessionCtx) SetWebSocketPeer(websocket_peer types.WebSocketPeer) { + if session.websocket_peer != nil { + if err := session.websocket_peer.Destroy(); err != nil { + session.logger.Warn().Err(err).Msgf("websocket destroy has failed") + } + } + session.websocket_peer = websocket_peer } @@ -176,6 +182,12 @@ func (session *SessionCtx) Disconnect(reason string) error { // --- func (session *SessionCtx) SetWebRTCPeer(webrtc_peer types.WebRTCPeer) { + if session.webrtc_peer != nil { + if err := session.webrtc_peer.Destroy(); err != nil { + session.logger.Warn().Err(err).Msgf("webrtc destroy has failed") + } + } + session.webrtc_peer = webrtc_peer }