From 4670b5187c9688da140e5353845c4898dac28caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Thu, 3 Dec 2020 16:45:41 +0100 Subject: [PATCH] Disconnect WebRTC on socket disconnect. --- internal/session/session.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/session/session.go b/internal/session/session.go index 615f5a3a..78b01da5 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -113,13 +113,19 @@ func (session *SessionCtx) SetWebSocketPeer(websocket_peer types.WebSocketPeer) } func (session *SessionCtx) SetWebSocketConnected(connected bool) { + session.websocket_connected = connected + if connected { - session.websocket_connected = true session.manager.emmiter.Emit("connected", session) - } else { - session.websocket_connected = false - session.manager.emmiter.Emit("disconnected", session) - session.websocket_peer = nil + return + } + + session.manager.emmiter.Emit("disconnected", session) + session.websocket_peer = nil + + // TODO: Refactor. Only if is WebRTC active. + if err := session.webrtc_peer.Destroy(); err != nil { + session.logger.Warn().Err(err).Msgf("webrtc destroy has failed") } }