Skip to content

Commit

Permalink
Use GatheringCompletePromise in examples/webrtc
Browse files Browse the repository at this point in the history
pion/webrtc@v3 enables trickle ICE by default now. Use provided helper
to block until ICE is finished gathering. For a production application
setting OnICECandidate is recommended.
  • Loading branch information
wawesomeNOGUI authored and Sean-Der committed Jan 12, 2021
1 parent ca4116b commit a359005
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion examples/webrtc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,23 @@ func main() {
panic(err)
}

// Create channel that is blocked until ICE Gathering is complete
gatherComplete := webrtc.GatheringCompletePromise(peerConnection)

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(answer)
if err != nil {
panic(err)
}

// Block until ICE Gathering is complete, disabling trickle ICE
// we do this because we only can exchange one signaling message
// in a production application you should exchange ICE Candidates via OnICECandidate
<-gatherComplete

// Output the answer in base64 so we can paste it in browser
fmt.Println(signal.Encode(answer))
fmt.Println(signal.Encode(*peerConnection.LocalDescription()))

// Block forever
select {}
}

0 comments on commit a359005

Please sign in to comment.