Skip to content

Commit

Permalink
Stop Create(Offer/Answer) from setting localDesc
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Sean-Der committed Feb 16, 2019
1 parent 5efb6b0 commit b67f73c
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 42 deletions.
4 changes: 2 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func RegisterDefaultCodecs() {

// PeerConnection API

// New using the default API.
// NewRTCPeerConnection using the default API.
// See API.NewRTCPeerConnection for details.
func New(configuration RTCConfiguration) (*RTCPeerConnection, error) {
func NewRTCPeerConnection(configuration RTCConfiguration) (*RTCPeerConnection, error) {
return defaultAPI.NewRTCPeerConnection(configuration)
}
8 changes: 6 additions & 2 deletions examples/data-channels-close/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

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

// Sets the LocalDescription, and starts our UDP listeners
// Create answer
answer, err := peerConnection.CreateAnswer(nil)
util.Check(err)

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(answer)
util.Check(err)

// Output the answer in base64 so we can paste it in browser
fmt.Println(util.Encode(answer))

Expand Down
6 changes: 5 additions & 1 deletion examples/data-channels-create/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

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

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(offer)
util.Check(err)

// Output the offer in base64 so we can paste it in browser
fmt.Println(util.Encode(offer))

Expand Down
6 changes: 5 additions & 1 deletion examples/data-channels-detach-create/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

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

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(offer)
util.Check(err)

// Output the offer in base64 so we can paste it in browser
fmt.Println(util.Encode(offer))

Expand Down
8 changes: 6 additions & 2 deletions examples/data-channels-detach/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

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

// Sets the LocalDescription, and starts our UDP listeners
// Create answer
answer, err := peerConnection.CreateAnswer(nil)
util.Check(err)

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(answer)
util.Check(err)

// Output the answer in base64 so we can paste it in browser
fmt.Println(util.Encode(answer))

Expand Down
8 changes: 6 additions & 2 deletions examples/data-channels/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

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

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

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(answer)
util.Check(err)

// Output the answer in base64 so we can paste it in browser
fmt.Println(util.Encode(answer))

Expand Down
8 changes: 6 additions & 2 deletions examples/gstreamer-receive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

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

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

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(answer)
util.Check(err)

// Output the answer in base64 so we can paste it in browser
fmt.Println(util.Encode(answer))

Expand Down
6 changes: 5 additions & 1 deletion examples/gstreamer-send-offer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

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

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(offer)
util.Check(err)

// Output the offer in base64 so we can paste it in browser
fmt.Println(util.Encode(offer))

Expand Down
8 changes: 6 additions & 2 deletions examples/gstreamer-send/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

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

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

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(answer)
util.Check(err)

// Output the answer in base64 so we can paste it in browser
fmt.Println(util.Encode(answer))

Expand Down
5 changes: 4 additions & 1 deletion examples/janus-gateway/streaming/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
Expand Down Expand Up @@ -107,6 +107,9 @@ func main() {
answer, err := peerConnection.CreateAnswer(nil)
util.Check(err)

err = peerConnection.SetLocalDescription(answer)
util.Check(err)

// now we start
_, err = handle.Message(map[string]interface{}{
"request": "start",
Expand Down
7 changes: 5 additions & 2 deletions examples/janus-gateway/video-room/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
janus "github.com/notedit/janus-go"
"github.com/pions/webrtc"
"github.com/pions/webrtc/examples/util"
"github.com/pions/webrtc/examples/util/gstreamer-src"
gst "github.com/pions/webrtc/examples/util/gstreamer-src"
"github.com/pions/webrtc/pkg/ice"
)

Expand Down Expand Up @@ -49,7 +49,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

peerConnection.OnICEConnectionStateChange(func(connectionState ice.ConnectionState) {
Expand All @@ -71,6 +71,9 @@ func main() {
offer, err := peerConnection.CreateOffer(nil)
util.Check(err)

err = peerConnection.SetLocalDescription(offer)
util.Check(err)

gateway, err := janus.Connect("ws://localhost:8188/janus")
util.Check(err)

Expand Down
8 changes: 6 additions & 2 deletions examples/pion-to-pion/answer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

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

// Sets the LocalDescription, and starts our UDP listeners
// Create answer
answer, err := peerConnection.CreateAnswer(nil)
util.Check(err)

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(answer)
util.Check(err)

// Send the answer
answerChan <- answer

Expand Down
6 changes: 5 additions & 1 deletion examples/pion-to-pion/offer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

// Create a datachannel with label 'data'
Expand Down Expand Up @@ -72,6 +72,10 @@ func main() {
offer, err := peerConnection.CreateOffer(nil)
util.Check(err)

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(offer)
util.Check(err)

// Exchange the offer for the answer
answer := mustSignalViaHTTP(offer, *addr)

Expand Down
8 changes: 6 additions & 2 deletions examples/save-to-disk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {
}

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(config)
peerConnection, err := webrtc.NewRTCPeerConnection(config)
util.Check(err)

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

// Sets the LocalDescription, and starts our UDP listeners
// Create answer
answer, err := peerConnection.CreateAnswer(nil)
util.Check(err)

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(answer)
util.Check(err)

// Output the answer in base64 so we can paste it in browser
fmt.Println(util.Encode(answer))

Expand Down
22 changes: 15 additions & 7 deletions examples/sfu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func mustReadStdin(reader *bufio.Reader) string {
return rawSd
}

func mustReadHttp(sdp chan string) string {
func mustReadHTTP(sdp chan string) string {
ret := <-sdp
return ret
}
Expand All @@ -58,7 +58,7 @@ func main() {
}()

offer := webrtc.RTCSessionDescription{}
util.Decode(mustReadHttp(sdp), &offer)
util.Decode(mustReadHTTP(sdp), &offer)
fmt.Println("")

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

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(peerConnectionConfig)
peerConnection, err := webrtc.NewRTCPeerConnection(peerConnectionConfig)
util.Check(err)

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

// Sets the LocalDescription, and starts our UDP listeners
// Create answer
answer, err := peerConnection.CreateAnswer(nil)
util.Check(err)

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(answer)
util.Check(err)

// Get the LocalDescription and take it to base64 so we can paste in browser
fmt.Println(util.Encode(answer))

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

recvOnlyOffer := webrtc.RTCSessionDescription{}
util.Decode(mustReadHttp(sdp), &recvOnlyOffer)
util.Decode(mustReadHTTP(sdp), &recvOnlyOffer)

// Create a new RTCPeerConnection
peerConnection, err := webrtc.New(peerConnectionConfig)
peerConnection, err := webrtc.NewRTCPeerConnection(peerConnectionConfig)
util.Check(err)

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

// Sets the LocalDescription, and starts our UDP listeners
// Create answer
answer, err := peerConnection.CreateAnswer(nil)
util.Check(err)

// Sets the LocalDescription, and starts our UDP listeners
err = peerConnection.SetLocalDescription(answer)
util.Check(err)

// Get the LocalDescription and take it to base64 so we can paste in browser
fmt.Println(util.Encode(answer))
}
Expand Down
Loading

0 comments on commit b67f73c

Please sign in to comment.