This commit is contained in:
parent
9c3d441d16
commit
6e2b5084e7
@ -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
|
||||||
}
|
}
|
||||||
|
@ -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:
|
||||||
|
manager.logger.Info().Str("id", id).Msg("peer disconnected")
|
||||||
|
manager.sessions.Destroy(id)
|
||||||
case webrtc.PeerConnectionStateFailed:
|
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)
|
manager.sessions.Destroy(id)
|
||||||
break
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user