This commit is contained in:
Marcel Battista 2021-03-01 01:07:31 +00:00
parent 9c3d441d16
commit 6e2b5084e7
2 changed files with 7 additions and 4 deletions

View File

@ -28,7 +28,7 @@ func (peer *Peer) WriteData(v interface{}) error {
} }
func (peer *Peer) Destroy() 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 { if err := peer.connection.Close(); err != nil {
return err return err
} }

View File

@ -169,17 +169,20 @@ func (manager *WebRTCManager) CreatePeer(id string, session types.Session) (stri
connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) { connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
switch state { switch state {
case webrtc.PeerConnectionStateDisconnected: case webrtc.PeerConnectionStateDisconnected:
case webrtc.PeerConnectionStateFailed:
manager.logger.Info().Str("id", id).Msg("peer disconnected") manager.logger.Info().Str("id", id).Msg("peer disconnected")
manager.sessions.Destroy(id) manager.sessions.Destroy(id)
break case webrtc.PeerConnectionStateFailed:
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)
case webrtc.PeerConnectionStateConnected: case webrtc.PeerConnectionStateConnected:
manager.logger.Info().Str("id", id).Msg("peer connected") manager.logger.Info().Str("id", id).Msg("peer connected")
if err = session.SetConnected(true); err != nil { if err = session.SetConnected(true); err != nil {
manager.logger.Warn().Err(err).Msg("unable to set connected on peer") manager.logger.Warn().Err(err).Msg("unable to set connected on peer")
manager.sessions.Destroy(id) manager.sessions.Destroy(id)
} }
break
} }
}) })