make ice connection callback synchronous

This commit is contained in:
Sukun 2024-03-13 17:03:51 +05:30
parent 0b447fd06d
commit 46bc73031d

View File

@ -497,7 +497,12 @@ func (pc *PeerConnection) onConnectionStateChange(cs PeerConnectionState) {
pc.connectionState.Store(cs)
pc.log.Infof("peer connection state changed: %s", cs)
if handler, ok := pc.onConnectionStateChangeHandler.Load().(func(PeerConnectionState)); ok && handler != nil {
go handler(cs)
ch := make(chan struct{})
go func() {
handler(cs)
close(ch)
}()
<-ch
}
}