Clear webrtc resources on failed connection
This commit is contained in:
@@ -151,8 +151,8 @@ func ExchangeSDP(
|
|||||||
conn.UserAgent = userAgent
|
conn.UserAgent = userAgent
|
||||||
conn.Listen(func(msg interface{}) {
|
conn.Listen(func(msg interface{}) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case streamer.EventType:
|
case pion.PeerConnectionState:
|
||||||
if msg == streamer.StateNull {
|
if msg == pion.PeerConnectionStateClosed{
|
||||||
stream.RemoveConsumer(conn)
|
stream.RemoveConsumer(conn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-3
@@ -62,17 +62,32 @@ func (c *Conn) Init() {
|
|||||||
fmt.Printf("TODO: webrtc ontrack %#v\n", remote)
|
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.Conn.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
|
||||||
c.Fire(state)
|
c.Fire(state)
|
||||||
|
|
||||||
// TODO: remove
|
// TODO: remove
|
||||||
switch state {
|
switch state {
|
||||||
case webrtc.PeerConnectionStateConnected:
|
case webrtc.PeerConnectionStateConnected:
|
||||||
c.Fire(streamer.StatePlaying)
|
c.Fire(streamer.StatePlaying) // TODO: remove
|
||||||
case webrtc.PeerConnectionStateDisconnected:
|
case webrtc.PeerConnectionStateDisconnected:
|
||||||
c.Fire(streamer.StateNull)
|
c.Fire(streamer.StateNull) // TODO: remove
|
||||||
case webrtc.PeerConnectionStateFailed:
|
// disconnect event comes earlier, than failed
|
||||||
|
// but it comes only for success connections
|
||||||
_ = c.Conn.Close()
|
_ = c.Conn.Close()
|
||||||
|
c.Conn = nil
|
||||||
|
case webrtc.PeerConnectionStateFailed:
|
||||||
|
if c.Conn != nil {
|
||||||
|
_ = c.Conn.Close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user