Skip to content

Commit b67f73c

Browse files
committed
Stop Create(Offer/Answer) from setting localDesc
This deviates from the WebRTC spec, so we need to fix it. This is a massively breaking change, so we need to figure out the best way to help users with this. I also renamed our RTCPeerConnection constructor. The hope is that people will refer to the examples/backlog and see what changed. Resolves #309
1 parent 5efb6b0 commit b67f73c

File tree

17 files changed

+102
-42
lines changed

17 files changed

+102
-42
lines changed

api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func RegisterDefaultCodecs() {
8989

9090
// PeerConnection API
9191

92-
// New using the default API.
92+
// NewRTCPeerConnection using the default API.
9393
// See API.NewRTCPeerConnection for details.
94-
func New(configuration RTCConfiguration) (*RTCPeerConnection, error) {
94+
func NewRTCPeerConnection(configuration RTCConfiguration) (*RTCPeerConnection, error) {
9595
return defaultAPI.NewRTCPeerConnection(configuration)
9696
}

examples/data-channels-close/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func main() {
2727
}
2828

2929
// Create a new RTCPeerConnection
30-
peerConnection, err := webrtc.New(config)
30+
peerConnection, err := webrtc.NewRTCPeerConnection(config)
3131
util.Check(err)
3232

3333
// Set the handler for ICE connection state
@@ -90,10 +90,14 @@ func main() {
9090
err = peerConnection.SetRemoteDescription(offer)
9191
util.Check(err)
9292

93-
// Sets the LocalDescription, and starts our UDP listeners
93+
// Create answer
9494
answer, err := peerConnection.CreateAnswer(nil)
9595
util.Check(err)
9696

97+
// Sets the LocalDescription, and starts our UDP listeners
98+
err = peerConnection.SetLocalDescription(answer)
99+
util.Check(err)
100+
97101
// Output the answer in base64 so we can paste it in browser
98102
fmt.Println(util.Encode(answer))
99103

examples/data-channels-create/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323
}
2424

2525
// Create a new RTCPeerConnection
26-
peerConnection, err := webrtc.New(config)
26+
peerConnection, err := webrtc.NewRTCPeerConnection(config)
2727
util.Check(err)
2828

2929
// Create a datachannel with label 'data'
@@ -65,6 +65,10 @@ func main() {
6565
offer, err := peerConnection.CreateOffer(nil)
6666
util.Check(err)
6767

68+
// Sets the LocalDescription, and starts our UDP listeners
69+
err = peerConnection.SetLocalDescription(offer)
70+
util.Check(err)
71+
6872
// Output the offer in base64 so we can paste it in browser
6973
fmt.Println(util.Encode(offer))
7074

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func main() {
3030
}
3131

3232
// Create a new RTCPeerConnection
33-
peerConnection, err := webrtc.New(config)
33+
peerConnection, err := webrtc.NewRTCPeerConnection(config)
3434
util.Check(err)
3535

3636
// Create a datachannel with label 'data'
@@ -62,6 +62,10 @@ func main() {
6262
offer, err := peerConnection.CreateOffer(nil)
6363
util.Check(err)
6464

65+
// Sets the LocalDescription, and starts our UDP listeners
66+
err = peerConnection.SetLocalDescription(offer)
67+
util.Check(err)
68+
6569
// Output the offer in base64 so we can paste it in browser
6670
fmt.Println(util.Encode(offer))
6771

examples/data-channels-detach/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func main() {
3030
}
3131

3232
// Create a new RTCPeerConnection
33-
peerConnection, err := webrtc.New(config)
33+
peerConnection, err := webrtc.NewRTCPeerConnection(config)
3434
util.Check(err)
3535

3636
// Set the handler for ICE connection state
@@ -67,10 +67,14 @@ func main() {
6767
err = peerConnection.SetRemoteDescription(offer)
6868
util.Check(err)
6969

70-
// Sets the LocalDescription, and starts our UDP listeners
70+
// Create answer
7171
answer, err := peerConnection.CreateAnswer(nil)
7272
util.Check(err)
7373

74+
// Sets the LocalDescription, and starts our UDP listeners
75+
err = peerConnection.SetLocalDescription(answer)
76+
util.Check(err)
77+
7478
// Output the answer in base64 so we can paste it in browser
7579
fmt.Println(util.Encode(answer))
7680

examples/data-channels/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323
}
2424

2525
// Create a new RTCPeerConnection
26-
peerConnection, err := webrtc.New(config)
26+
peerConnection, err := webrtc.NewRTCPeerConnection(config)
2727
util.Check(err)
2828

2929
// Set the handler for ICE connection state
@@ -70,10 +70,14 @@ func main() {
7070
err = peerConnection.SetRemoteDescription(offer)
7171
util.Check(err)
7272

73-
// Sets the LocalDescription, and starts our UDP listeners
73+
// Create an answer
7474
answer, err := peerConnection.CreateAnswer(nil)
7575
util.Check(err)
7676

77+
// Sets the LocalDescription, and starts our UDP listeners
78+
err = peerConnection.SetLocalDescription(answer)
79+
util.Check(err)
80+
7781
// Output the answer in base64 so we can paste it in browser
7882
fmt.Println(util.Encode(answer))
7983

examples/gstreamer-receive/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func main() {
2828
}
2929

3030
// Create a new RTCPeerConnection
31-
peerConnection, err := webrtc.New(config)
31+
peerConnection, err := webrtc.NewRTCPeerConnection(config)
3232
util.Check(err)
3333

3434
// Set a handler for when a new remote track starts, this handler creates a gstreamer pipeline
@@ -70,10 +70,14 @@ func main() {
7070
err = peerConnection.SetRemoteDescription(offer)
7171
util.Check(err)
7272

73-
// Sets the LocalDescription, and starts our UDP listeners
73+
// Create an answer
7474
answer, err := peerConnection.CreateAnswer(nil)
7575
util.Check(err)
7676

77+
// Sets the LocalDescription, and starts our UDP listeners
78+
err = peerConnection.SetLocalDescription(answer)
79+
util.Check(err)
80+
7781
// Output the answer in base64 so we can paste it in browser
7882
fmt.Println(util.Encode(answer))
7983

examples/gstreamer-send-offer/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func main() {
2626
}
2727

2828
// Create a new RTCPeerConnection
29-
peerConnection, err := webrtc.New(config)
29+
peerConnection, err := webrtc.NewRTCPeerConnection(config)
3030
util.Check(err)
3131

3232
// Set the handler for ICE connection state
@@ -51,6 +51,10 @@ func main() {
5151
offer, err := peerConnection.CreateOffer(nil)
5252
util.Check(err)
5353

54+
// Sets the LocalDescription, and starts our UDP listeners
55+
err = peerConnection.SetLocalDescription(offer)
56+
util.Check(err)
57+
5458
// Output the offer in base64 so we can paste it in browser
5559
fmt.Println(util.Encode(offer))
5660

examples/gstreamer-send/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func main() {
3131
}
3232

3333
// Create a new RTCPeerConnection
34-
peerConnection, err := webrtc.New(config)
34+
peerConnection, err := webrtc.NewRTCPeerConnection(config)
3535
util.Check(err)
3636

3737
// Set the handler for ICE connection state
@@ -60,10 +60,14 @@ func main() {
6060
err = peerConnection.SetRemoteDescription(offer)
6161
util.Check(err)
6262

63-
// Sets the LocalDescription, and starts our UDP listeners
63+
// Create an answer
6464
answer, err := peerConnection.CreateAnswer(nil)
6565
util.Check(err)
6666

67+
// Sets the LocalDescription, and starts our UDP listeners
68+
err = peerConnection.SetLocalDescription(answer)
69+
util.Check(err)
70+
6771
// Output the answer in base64 so we can paste it in browser
6872
fmt.Println(util.Encode(answer))
6973

examples/janus-gateway/streaming/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main() {
4949
}
5050

5151
// Create a new RTCPeerConnection
52-
peerConnection, err := webrtc.New(config)
52+
peerConnection, err := webrtc.NewRTCPeerConnection(config)
5353
util.Check(err)
5454

5555
peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
@@ -107,6 +107,9 @@ func main() {
107107
answer, err := peerConnection.CreateAnswer(nil)
108108
util.Check(err)
109109

110+
err = peerConnection.SetLocalDescription(answer)
111+
util.Check(err)
112+
110113
// now we start
111114
_, err = handle.Message(map[string]interface{}{
112115
"request": "start",

0 commit comments

Comments
 (0)