summaryrefslogtreecommitdiff
path: root/vendor/github.com/pion/webrtc/v3/gathering_complete_promise.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/pion/webrtc/v3/gathering_complete_promise.go')
-rw-r--r--vendor/github.com/pion/webrtc/v3/gathering_complete_promise.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/github.com/pion/webrtc/v3/gathering_complete_promise.go b/vendor/github.com/pion/webrtc/v3/gathering_complete_promise.go
new file mode 100644
index 0000000..a4d52f9
--- /dev/null
+++ b/vendor/github.com/pion/webrtc/v3/gathering_complete_promise.go
@@ -0,0 +1,24 @@
+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())
+
+ // It's possible to miss the GatherComplete event since setGatherCompleteHandler is an atomic operation and the
+ // promise might have been created after the gathering is finished. Therefore, we need to check if the ICE gathering
+ // state has changed to complete so that we don't block the caller forever.
+ pc.setGatherCompleteHandler(func() { done() })
+ if pc.ICEGatheringState() == ICEGatheringStateComplete {
+ done()
+ }
+
+ return gatheringComplete.Done()
+}