Skip to content

Commit 40210b7

Browse files
committed
Upgrade to pion/webrtc@v3
Resolves #26
1 parent 4881624 commit 40210b7

File tree

7 files changed

+118
-79
lines changed

7 files changed

+118
-79
lines changed

client.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/kr/pty"
1212
"github.com/maxmcd/webtty/pkg/sd"
1313
"github.com/mitchellh/colorstring"
14-
"github.com/pion/webrtc/v2"
14+
"github.com/pion/webrtc/v3"
1515
"golang.org/x/crypto/ssh/terminal"
1616
)
1717

@@ -133,14 +133,20 @@ func (cs *clientSession) run() (err error) {
133133
return
134134
}
135135

136+
// Create channel that is blocked until ICE Gathering is complete
137+
gatherComplete := webrtc.GatheringCompletePromise(cs.pc)
138+
136139
err = cs.pc.SetLocalDescription(answer)
137140
if err != nil {
138141
log.Println(err)
139142
return
140143
}
141144

145+
// Block until ICE Gathering is complete
146+
<-gatherComplete
147+
142148
answerSd := sd.SessionDescription{
143-
Sdp: answer.SDP,
149+
Sdp: cs.pc.LocalDescription().SDP,
144150
Key: cs.offer.Key,
145151
Nonce: cs.offer.Nonce,
146152
}

client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/kr/pty"
12-
"github.com/pion/webrtc/v2"
12+
"github.com/pion/webrtc/v3"
1313
"golang.org/x/crypto/ssh/terminal"
1414
)
1515

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ require (
66
github.com/btcsuite/btcutil v0.0.0-20190316010144-3ac1210f4b38
77
github.com/kr/pty v1.1.4
88
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
9-
github.com/pion/webrtc/v2 v2.1.18
10-
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413
9+
github.com/pion/webrtc/v3 v3.0.1
10+
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
1111
)

go.sum

Lines changed: 90 additions & 70 deletions
Large diffs are not rendered by default.

host.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/kr/pty"
1515
"github.com/maxmcd/webtty/pkg/sd"
1616
"github.com/mitchellh/colorstring"
17-
"github.com/pion/webrtc/v2"
17+
"github.com/pion/webrtc/v3"
1818
)
1919

2020
type hostSession struct {
@@ -180,21 +180,34 @@ func (hs *hostSession) mustReadStdin() (string, error) {
180180
func (hs *hostSession) createOffer() (err error) {
181181
hs.pc.OnDataChannel(hs.onDataChannel())
182182

183+
// Create unused DataChannel, the offer doesn't implictly have
184+
// any media sections otherwise
185+
if _, err = hs.pc.CreateDataChannel("offerer-channel", nil); err != nil {
186+
log.Println(err)
187+
return
188+
}
189+
183190
// Create an offer to send to the browser
184191
offer, err := hs.pc.CreateOffer(nil)
185192
if err != nil {
186193
log.Println(err)
187194
return
188195
}
189196

197+
// Create channel that is blocked until ICE Gathering is complete
198+
gatherComplete := webrtc.GatheringCompletePromise(hs.pc)
199+
190200
err = hs.pc.SetLocalDescription(offer)
191201
if err != nil {
192202
log.Println(err)
193203
return
194204
}
195205

206+
// Block until ICE Gathering is complete
207+
<-gatherComplete
208+
196209
hs.offer = sd.SessionDescription{
197-
Sdp: offer.SDP,
210+
Sdp: hs.pc.LocalDescription().SDP,
198211
}
199212
if hs.oneWay {
200213
hs.offer.GenKeys()

host_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"testing"
99

1010
"github.com/kr/pty"
11-
"github.com/pion/webrtc/v2"
11+
"github.com/pion/webrtc/v3"
1212
)
1313

1414
func TestHosttDataChannelOnMessage(t *testing.T) {

session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"os"
66

77
"github.com/maxmcd/webtty/pkg/sd"
8-
"github.com/pion/webrtc/v2"
8+
"github.com/pion/webrtc/v3"
99
"golang.org/x/crypto/ssh/terminal"
1010
)
1111

0 commit comments

Comments
 (0)