Delay adding tracks until connection is complete.

This avoids losing packets at the beginning of a connection.
This commit is contained in:
Juliusz Chroboczek committed 2020-10-06 04:18:46 +02:00
1 parent aa65164edd
commit 0eb1593bb8
1 file changed
+14 -2
+14 -2
View File
@@ -520,9 +520,21 @@ func gotAnswer(c *webClient, id string, answer webrtc.SessionDescription) error
log.Printf("ICE: %v", err)
}
for _, t := range down.tracks {
t.remote.AddLocal(t)
add := func() {
down.pc.OnConnectionStateChange(nil)
for _, t := range down.tracks {
t.remote.AddLocal(t)
}
}
down.pc.OnConnectionStateChange(func(state webrtc.PeerConnectionState) {
if state == webrtc.PeerConnectionStateConnected {
add()
}
})
if down.pc.ConnectionState() == webrtc.PeerConnectionStateConnected {
add()
}
return nil
}