move createOffer to goroutine

This commit is contained in:
David Colburn
2021-06-17 22:33:26 -07:00
parent 6d6423c29d
commit 089d1d366d
2 changed files with 12 additions and 9 deletions
+9 -7
View File
@@ -93,14 +93,16 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
}
t.pc.OnICEGatheringStateChange(func(state webrtc.ICEGathererState) {
if state == webrtc.ICEGathererStateComplete {
t.lock.Lock()
defer t.lock.Unlock()
if t.restartAfterGathering {
logger.Debugw("restarting ICE after ICE gathering")
if err := t.createAndSendOffer(&webrtc.OfferOptions{ICERestart: true}); err != nil {
logger.Warnw("could not restart ICE", err)
go func() {
t.lock.Lock()
defer t.lock.Unlock()
if t.restartAfterGathering {
logger.Debugw("restarting ICE after ICE gathering")
if err := t.createAndSendOffer(&webrtc.OfferOptions{ICERestart: true}); err != nil {
logger.Warnw("could not restart ICE", err)
}
}
}
}()
}
})