Clear webrtc resources on failed connection

This commit is contained in:
Alexey Khit
2022-08-27 15:57:47 +03:00
parent a006394e5f
commit 38a18cab62
2 changed files with 20 additions and 5 deletions
+2 -2
View File
@@ -151,8 +151,8 @@ func ExchangeSDP(
conn.UserAgent = userAgent
conn.Listen(func(msg interface{}) {
switch msg := msg.(type) {
case streamer.EventType:
if msg == streamer.StateNull {
case pion.PeerConnectionState:
if msg == pion.PeerConnectionStateClosed{
stream.RemoveConsumer(conn)
}
}
+18 -3
View File
@@ -62,17 +62,32 @@ func (c *Conn) Init() {
fmt.Printf("TODO: webrtc ontrack %#v\n", remote)
})
// OK connection:
// 15:01:46 ICE connection state changed: checking
// 15:01:46 peer connection state changed: connected
// 15:01:54 peer connection state changed: disconnected
// 15:02:20 peer connection state changed: failed
//
// Fail connection:
// 14:53:08 ICE connection state changed: checking
// 14:53:39 peer connection state changed: failed
c.Conn.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
c.Fire(state)
// TODO: remove
switch state {
case webrtc.PeerConnectionStateConnected:
c.Fire(streamer.StatePlaying)
c.Fire(streamer.StatePlaying) // TODO: remove
case webrtc.PeerConnectionStateDisconnected:
c.Fire(streamer.StateNull)
case webrtc.PeerConnectionStateFailed:
c.Fire(streamer.StateNull) // TODO: remove
// disconnect event comes earlier, than failed
// but it comes only for success connections
_ = c.Conn.Close()
c.Conn = nil
case webrtc.PeerConnectionStateFailed:
if c.Conn != nil {
_ = c.Conn.Close()
}
}
})
}