fix deadlock.

This commit is contained in:
Miroslav Šedivý
2021-09-18 00:56:03 +02:00
parent 6bd46b438e
commit 137614c087
3 changed files with 15 additions and 29 deletions

View File

@ -68,14 +68,9 @@ func (peer *WebRTCPeerCtx) Destroy() {
peer.mu.Lock()
defer peer.mu.Unlock()
if peer.connection == nil || peer.connection.ConnectionState() != webrtc.PeerConnectionStateConnected {
return
if peer.connection != nil {
err := peer.connection.Close()
peer.logger.Err(err).Msg("peer connection destroyed")
peer.connection = nil
}
// TODO: Send webrtc disconnect event via websocket.
err := peer.connection.Close()
peer.logger.Err(err).Msg("peer connection destroyed")
peer.connection = nil
}