Skip to content

Commit bb3aa97

Browse files
committed
Move to pion/ice@v2
Removed support for trickle ice Resolves #1274
1 parent 89d7de1 commit bb3aa97

File tree

53 files changed

+695
-839
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+695
-839
lines changed

datachannel_ortc_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,18 @@ func (s *testORTCStack) setSignal(sig *testORTCSignal, isOffer bool) error {
118118
}
119119

120120
func (s *testORTCStack) getSignal() (*testORTCSignal, error) {
121-
// Gather candidates
122-
err := s.gatherer.Gather()
123-
if err != nil {
121+
gatherFinished := make(chan struct{})
122+
s.gatherer.OnLocalCandidate(func(i *ICECandidate) {
123+
if i == nil {
124+
close(gatherFinished)
125+
}
126+
})
127+
128+
if err := s.gatherer.Gather(); err != nil {
124129
return nil, err
125130
}
126131

132+
<-gatherFinished
127133
iceCandidates, err := s.gatherer.GetLocalCandidates()
128134
if err != nil {
129135
return nil, err

examples/broadcast/main.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,22 @@ func main() {
100100
panic(err)
101101
}
102102

103+
// Create channel that is blocked until ICE Gathering is complete
104+
gatherComplete := webrtc.GatheringCompletePromise(peerConnection)
105+
103106
// Sets the LocalDescription, and starts our UDP listeners
104107
err = peerConnection.SetLocalDescription(answer)
105108
if err != nil {
106109
panic(err)
107110
}
108111

112+
// Block until ICE Gathering is complete, disabling trickle ICE
113+
// we do this because we only can exchange one signaling message
114+
// in a production application you should exchange ICE Candidates via OnICECandidate
115+
<-gatherComplete
116+
109117
// Get the LocalDescription and take it to base64 so we can paste in browser
110-
fmt.Println(signal.Encode(answer))
118+
fmt.Println(signal.Encode(*peerConnection.LocalDescription()))
111119

112120
localTrack := <-localTrackChan
113121
for {
@@ -140,13 +148,21 @@ func main() {
140148
panic(err)
141149
}
142150

151+
// Create channel that is blocked until ICE Gathering is complete
152+
gatherComplete = webrtc.GatheringCompletePromise(peerConnection)
153+
143154
// Sets the LocalDescription, and starts our UDP listeners
144155
err = peerConnection.SetLocalDescription(answer)
145156
if err != nil {
146157
panic(err)
147158
}
148159

160+
// Block until ICE Gathering is complete, disabling trickle ICE
161+
// we do this because we only can exchange one signaling message
162+
// in a production application you should exchange ICE Candidates via OnICECandidate
163+
<-gatherComplete
164+
149165
// Get the LocalDescription and take it to base64 so we can paste in browser
150-
fmt.Println(signal.Encode(answer))
166+
fmt.Println(signal.Encode(*peerConnection.LocalDescription()))
151167
}
152168
}

examples/custom-logger/main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ func main() {
6767
panic(err)
6868
}
6969

70+
// Set ICE Candidate handler. As soon as a PeerConnection has gathered a candidate
71+
// send it to the other peer
72+
answerPeerConnection.OnICECandidate(func(i *webrtc.ICECandidate) {
73+
if i != nil {
74+
if iceErr := offerPeerConnection.AddICECandidate(i.ToJSON()); iceErr != nil {
75+
panic(iceErr)
76+
}
77+
}
78+
})
79+
80+
// Set ICE Candidate handler. As soon as a PeerConnection has gathered a candidate
81+
// send it to the other peer
82+
offerPeerConnection.OnICECandidate(func(i *webrtc.ICECandidate) {
83+
if i != nil {
84+
if iceErr := answerPeerConnection.AddICECandidate(i.ToJSON()); iceErr != nil {
85+
panic(iceErr)
86+
}
87+
}
88+
})
89+
7090
// Create an offer for the other PeerConnection
7191
offer, err := offerPeerConnection.CreateOffer(nil)
7292
if err != nil {
@@ -90,6 +110,11 @@ func main() {
90110
panic(err)
91111
}
92112

113+
// Set the answerer's LocalDescription
114+
if err = answerPeerConnection.SetLocalDescription(answer); err != nil {
115+
panic(err)
116+
}
117+
93118
// SetRemoteDescription on original PeerConnection, this finishes our signaling
94119
// bother PeerConnections should be able to communicate with each other now
95120
if err = offerPeerConnection.SetRemoteDescription(answer); err != nil {

examples/data-channels-close/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,22 @@ func main() {
9797
panic(err)
9898
}
9999

100+
// Create channel that is blocked until ICE Gathering is complete
101+
gatherComplete := webrtc.GatheringCompletePromise(peerConnection)
102+
100103
// Sets the LocalDescription, and starts our UDP listeners
101104
err = peerConnection.SetLocalDescription(answer)
102105
if err != nil {
103106
panic(err)
104107
}
105108

109+
// Block until ICE Gathering is complete, disabling trickle ICE
110+
// we do this because we only can exchange one signaling message
111+
// in a production application you should exchange ICE Candidates via OnICECandidate
112+
<-gatherComplete
113+
106114
// Output the answer in base64 so we can paste it in browser
107-
fmt.Println(signal.Encode(answer))
115+
fmt.Println(signal.Encode(*peerConnection.LocalDescription()))
108116

109117
// Block forever
110118
select {}

examples/data-channels-create/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ Hit the 'Start Session' button in the browser. You should see `have-remote-offer
2323
Meanwhile text has appeared in the second text area of the jsfiddle. Copy the text and paste it into `data-channels-create` and hit ENTER.
2424
In the browser you'll now see `connected` as the connection is created. If everything worked you should see `New DataChannel data`.
2525

26-
Now you can put whatever you want in the `Message` textarea, and when you hit `Send Message` it should appear in your browser!
26+
Now you can put whatever you want in the `Message` textarea, and when you hit `Send Message` it should appear in your terminal!
2727

28-
You can also type in your terminal, and when you hit enter it will appear in your web browser.
28+
Pion WebRTC will send random messages every 5 seconds that will appear in your browser.
2929

3030
Congrats, you have used Pion WebRTC! Now start building something cool

examples/data-channels-create/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,22 @@ func main() {
6666
panic(err)
6767
}
6868

69+
// Create channel that is blocked until ICE Gathering is complete
70+
gatherComplete := webrtc.GatheringCompletePromise(peerConnection)
71+
6972
// Sets the LocalDescription, and starts our UDP listeners
7073
err = peerConnection.SetLocalDescription(offer)
7174
if err != nil {
7275
panic(err)
7376
}
7477

75-
// Output the offer in base64 so we can paste it in browser
76-
fmt.Println(signal.Encode(offer))
78+
// Block until ICE Gathering is complete, disabling trickle ICE
79+
// we do this because we only can exchange one signaling message
80+
// in a production application you should exchange ICE Candidates via OnICECandidate
81+
<-gatherComplete
82+
83+
// Output the answer in base64 so we can paste it in browser
84+
fmt.Println(signal.Encode(*peerConnection.LocalDescription()))
7785

7886
// Wait for the answer to be pasted
7987
answer := webrtc.SessionDescription{}

examples/data-channels-detach-create/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,22 @@ func main() {
7676
panic(err)
7777
}
7878

79+
// Create channel that is blocked until ICE Gathering is complete
80+
gatherComplete := webrtc.GatheringCompletePromise(peerConnection)
81+
7982
// Sets the LocalDescription, and starts our UDP listeners
8083
err = peerConnection.SetLocalDescription(offer)
8184
if err != nil {
8285
panic(err)
8386
}
8487

88+
// Block until ICE Gathering is complete, disabling trickle ICE
89+
// we do this because we only can exchange one signaling message
90+
// in a production application you should exchange ICE Candidates via OnICECandidate
91+
<-gatherComplete
92+
8593
// Output the offer in base64 so we can paste it in browser
86-
fmt.Println(signal.Encode(offer))
94+
fmt.Println(signal.Encode(*peerConnection.LocalDescription()))
8795

8896
// Wait for the answer to be pasted
8997
answer := webrtc.SessionDescription{}

examples/data-channels-detach/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,22 @@ func main() {
8585
panic(err)
8686
}
8787

88+
// Create channel that is blocked until ICE Gathering is complete
89+
gatherComplete := webrtc.GatheringCompletePromise(peerConnection)
90+
8891
// Sets the LocalDescription, and starts our UDP listeners
8992
err = peerConnection.SetLocalDescription(answer)
9093
if err != nil {
9194
panic(err)
9295
}
9396

97+
// Block until ICE Gathering is complete, disabling trickle ICE
98+
// we do this because we only can exchange one signaling message
99+
// in a production application you should exchange ICE Candidates via OnICECandidate
100+
<-gatherComplete
101+
94102
// Output the answer in base64 so we can paste it in browser
95-
fmt.Println(signal.Encode(answer))
103+
fmt.Println(signal.Encode(*peerConnection.LocalDescription()))
96104

97105
// Block forever
98106
select {}

examples/data-channels-flow-control/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ func main() {
122122
offerPC := createOfferer()
123123
answerPC := createAnswerer()
124124

125+
// Set ICE Candidate handler. As soon as a PeerConnection has gathered a candidate
126+
// send it to the other peer
127+
answerPC.OnICECandidate(func(i *webrtc.ICECandidate) {
128+
if i != nil {
129+
check(offerPC.AddICECandidate(i.ToJSON()))
130+
}
131+
})
132+
133+
// Set ICE Candidate handler. As soon as a PeerConnection has gathered a candidate
134+
// send it to the other peer
135+
offerPC.OnICECandidate(func(i *webrtc.ICECandidate) {
136+
if i != nil {
137+
check(answerPC.AddICECandidate(i.ToJSON()))
138+
}
139+
})
140+
125141
// Now, create an offer
126142
offer, err := offerPC.CreateOffer(nil)
127143
check(err)

examples/data-channels/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Copy the text that `data-channels` just emitted and copy into second text area
2424
### Hit 'Start Session' in jsfiddle
2525
Under Start Session you should see 'Checking' as it starts connecting. If everything worked you should see `New DataChannel foo 1`
2626

27-
Now you can put whatever you want in the `Message` textarea, and when you hit `Send Message` it should appear in your browser!
27+
Now you can put whatever you want in the `Message` textarea, and when you hit `Send Message` it should appear in your terminal!
2828

29-
You can also type in your terminal, and when you hit enter it will appear in your web browser.
29+
Pion WebRTC will send random messages every 5 seconds that will appear in your browser.
3030

3131
Congrats, you have used Pion WebRTC! Now start building something cool

0 commit comments

Comments
 (0)