diff --git a/server/internal/webrtc/peer.go b/server/internal/webrtc/peer.go index 9ca5797..b8d1133 100644 --- a/server/internal/webrtc/peer.go +++ b/server/internal/webrtc/peer.go @@ -28,7 +28,7 @@ func (peer *Peer) WriteData(v interface{}) error { } func (peer *Peer) Destroy() error { - if peer.connection != nil && peer.connection.ConnectionState() == webrtc.PeerConnectionStateConnected { + if peer.connection != nil && peer.connection.ConnectionState() != webrtc.PeerConnectionStateClosed { if err := peer.connection.Close(); err != nil { return err } diff --git a/server/internal/webrtc/webrtc.go b/server/internal/webrtc/webrtc.go index 209dc13..e6a862d 100644 --- a/server/internal/webrtc/webrtc.go +++ b/server/internal/webrtc/webrtc.go @@ -169,17 +169,20 @@ func (manager *WebRTCManager) CreatePeer(id string, session types.Session) (stri connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) { switch state { case webrtc.PeerConnectionStateDisconnected: + manager.logger.Info().Str("id", id).Msg("peer disconnected") + manager.sessions.Destroy(id) case webrtc.PeerConnectionStateFailed: - manager.logger.Info().Str("id", id).Msg("peer disconnected") + manager.logger.Info().Str("id", id).Msg("peer failed") + manager.sessions.Destroy(id) + case webrtc.PeerConnectionStateClosed: + manager.logger.Info().Str("id", id).Msg("peer closed") manager.sessions.Destroy(id) - break case webrtc.PeerConnectionStateConnected: manager.logger.Info().Str("id", id).Msg("peer connected") if err = session.SetConnected(true); err != nil { manager.logger.Warn().Err(err).Msg("unable to set connected on peer") manager.sessions.Destroy(id) } - break } })