mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
fix: ensure webrtc close is executed only once.
This commit is contained in:
parent
08a5d5abb4
commit
2ff47ac920
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
@ -567,6 +568,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, bitrate int,
|
||||
logger.Info().Interface("data_channel", dc).Msg("got remote data channel")
|
||||
})
|
||||
|
||||
var once sync.Once
|
||||
connection.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
|
||||
switch state {
|
||||
case webrtc.PeerConnectionStateConnected:
|
||||
@ -575,6 +577,8 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, bitrate int,
|
||||
webrtc.PeerConnectionStateFailed:
|
||||
connection.Close()
|
||||
case webrtc.PeerConnectionStateClosed:
|
||||
// ensure we only run this once
|
||||
once.Do(func() {
|
||||
session.SetWebRTCConnected(peer, false)
|
||||
if err = video.RemoveReceiver(videoTrack); err != nil {
|
||||
logger.Err(err).Msg("failed to remove video receiver")
|
||||
@ -582,6 +586,7 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, bitrate int,
|
||||
audioTrack.Shutdown()
|
||||
videoTrack.Shutdown()
|
||||
close(videoRtcp)
|
||||
})
|
||||
}
|
||||
|
||||
manager.metrics.SetState(session, state)
|
||||
|
Loading…
Reference in New Issue
Block a user