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

+2-2
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

+6-2
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

+5-1
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

+5-1
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

+6-2
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

+6-2
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

+6-2
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

+5-1
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

+6-2
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

+4-1
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",

examples/janus-gateway/video-room/main.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
janus "github.com/notedit/janus-go"
88
"github.com/pions/webrtc"
99
"github.com/pions/webrtc/examples/util"
10-
"github.com/pions/webrtc/examples/util/gstreamer-src"
10+
gst "github.com/pions/webrtc/examples/util/gstreamer-src"
1111
"github.com/pions/webrtc/pkg/ice"
1212
)
1313

@@ -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) {
@@ -71,6 +71,9 @@ func main() {
7171
offer, err := peerConnection.CreateOffer(nil)
7272
util.Check(err)
7373

74+
err = peerConnection.SetLocalDescription(offer)
75+
util.Check(err)
76+
7477
gateway, err := janus.Connect("ws://localhost:8188/janus")
7578
util.Check(err)
7679

examples/pion-to-pion/answer/main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
}
3030

3131
// Create a new RTCPeerConnection
32-
peerConnection, err := webrtc.New(config)
32+
peerConnection, err := webrtc.NewRTCPeerConnection(config)
3333
util.Check(err)
3434

3535
// Set the handler for ICE connection state
@@ -77,10 +77,14 @@ func main() {
7777
err = peerConnection.SetRemoteDescription(offer)
7878
util.Check(err)
7979

80-
// Sets the LocalDescription, and starts our UDP listeners
80+
// Create answer
8181
answer, err := peerConnection.CreateAnswer(nil)
8282
util.Check(err)
8383

84+
// Sets the LocalDescription, and starts our UDP listeners
85+
err = peerConnection.SetLocalDescription(answer)
86+
util.Check(err)
87+
8488
// Send the answer
8589
answerChan <- answer
8690

examples/pion-to-pion/offer/main.go

+5-1
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'
@@ -72,6 +72,10 @@ func main() {
7272
offer, err := peerConnection.CreateOffer(nil)
7373
util.Check(err)
7474

75+
// Sets the LocalDescription, and starts our UDP listeners
76+
err = peerConnection.SetLocalDescription(offer)
77+
util.Check(err)
78+
7579
// Exchange the offer for the answer
7680
answer := mustSignalViaHTTP(offer, *addr)
7781

examples/save-to-disk/main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
}
3030

3131
// Create a new RTCPeerConnection
32-
peerConnection, err := webrtc.New(config)
32+
peerConnection, err := webrtc.NewRTCPeerConnection(config)
3333
util.Check(err)
3434

3535
// Set a handler for when a new remote track starts, this handler saves buffers to disk as
@@ -73,10 +73,14 @@ func main() {
7373
err = peerConnection.SetRemoteDescription(offer)
7474
util.Check(err)
7575

76-
// Sets the LocalDescription, and starts our UDP listeners
76+
// Create answer
7777
answer, err := peerConnection.CreateAnswer(nil)
7878
util.Check(err)
7979

80+
// Sets the LocalDescription, and starts our UDP listeners
81+
err = peerConnection.SetLocalDescription(answer)
82+
util.Check(err)
83+
8084
// Output the answer in base64 so we can paste it in browser
8185
fmt.Println(util.Encode(answer))
8286

examples/sfu/main.go

+15-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func mustReadStdin(reader *bufio.Reader) string {
3232
return rawSd
3333
}
3434

35-
func mustReadHttp(sdp chan string) string {
35+
func mustReadHTTP(sdp chan string) string {
3636
ret := <-sdp
3737
return ret
3838
}
@@ -58,7 +58,7 @@ func main() {
5858
}()
5959

6060
offer := webrtc.RTCSessionDescription{}
61-
util.Decode(mustReadHttp(sdp), &offer)
61+
util.Decode(mustReadHTTP(sdp), &offer)
6262
fmt.Println("")
6363

6464
/* Everything below is the pion-WebRTC API, thanks for using it! */
@@ -67,7 +67,7 @@ func main() {
6767
webrtc.RegisterCodec(webrtc.NewRTCRtpVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000))
6868

6969
// Create a new RTCPeerConnection
70-
peerConnection, err := webrtc.New(peerConnectionConfig)
70+
peerConnection, err := webrtc.NewRTCPeerConnection(peerConnectionConfig)
7171
util.Check(err)
7272

7373
inboundSSRC := make(chan uint32)
@@ -111,10 +111,14 @@ func main() {
111111
// Set the remote SessionDescription
112112
util.Check(peerConnection.SetRemoteDescription(offer))
113113

114-
// Sets the LocalDescription, and starts our UDP listeners
114+
// Create answer
115115
answer, err := peerConnection.CreateAnswer(nil)
116116
util.Check(err)
117117

118+
// Sets the LocalDescription, and starts our UDP listeners
119+
err = peerConnection.SetLocalDescription(answer)
120+
util.Check(err)
121+
118122
// Get the LocalDescription and take it to base64 so we can paste in browser
119123
fmt.Println(util.Encode(answer))
120124

@@ -125,10 +129,10 @@ func main() {
125129
fmt.Println("Curl an base64 SDP to start sendonly peer connection")
126130

127131
recvOnlyOffer := webrtc.RTCSessionDescription{}
128-
util.Decode(mustReadHttp(sdp), &recvOnlyOffer)
132+
util.Decode(mustReadHTTP(sdp), &recvOnlyOffer)
129133

130134
// Create a new RTCPeerConnection
131-
peerConnection, err := webrtc.New(peerConnectionConfig)
135+
peerConnection, err := webrtc.NewRTCPeerConnection(peerConnectionConfig)
132136
util.Check(err)
133137

134138
// Create a single VP8 Track to send videa
@@ -146,10 +150,14 @@ func main() {
146150
err = peerConnection.SetRemoteDescription(recvOnlyOffer)
147151
util.Check(err)
148152

149-
// Sets the LocalDescription, and starts our UDP listeners
153+
// Create answer
150154
answer, err := peerConnection.CreateAnswer(nil)
151155
util.Check(err)
152156

157+
// Sets the LocalDescription, and starts our UDP listeners
158+
err = peerConnection.SetLocalDescription(answer)
159+
util.Check(err)
160+
153161
// Get the LocalDescription and take it to base64 so we can paste in browser
154162
fmt.Println(util.Encode(answer))
155163
}

0 commit comments

Comments
 (0)