Files
webrtc/gathering_complete_promise.go
soolaugust 6f6de25b24 Modify all hdlr to handler for better reading
change hdlr -> handler, Hdlr -> Handler for better reading.
Since this is first commit, add myself to contributors
2020-08-17 22:04:29 -07:00

23 lines
792 B
Go

package webrtc
import (
"context"
)
// GatheringCompletePromise is a Pion specific helper function that returns a channel that is closed when gathering is complete.
// This function may be helpful in cases where you are unable to trickle your ICE Candidates.
//
// It is better to not use this function, and instead trickle candidates. If you use this function you will see longer connection startup times.
// When the call is connected you will see no impact however.
func GatheringCompletePromise(pc *PeerConnection) (gatherComplete <-chan struct{}) {
gatheringComplete, done := context.WithCancel(context.Background())
if pc.ICEGatheringState() == ICEGatheringStateComplete {
done()
} else {
pc.setGatherCompleteHandler(func() { done() })
}
return gatheringComplete.Done()
}