Fix ORTC example

README didn't describe how to get signaling into client 1

Relates to #379
This commit is contained in:
Sean DuBois
2023-09-16 14:35:01 -04:00
parent 14eb615879
commit 9eded4ee7a
5 changed files with 25 additions and 12 deletions

View File

@@ -20,7 +20,7 @@ Run `broadcast` OR run `main.go` in `github.com/pion/webrtc/examples/broadcast`
* Click `Publish a Broadcast`
* Press `Copy browser SDP to clipboard` or copy the `Browser base64 Session Description` string manually
* Run `curl localhost:8080/sdp -d "$BROWSER_OFFER"`. `$BROWSER_OFFER` is the value you copied in the last step.
* Run `curl localhost:8080 -d "$BROWSER_OFFER"`. `$BROWSER_OFFER` is the value you copied in the last step.
* The `broadcast` terminal application will respond with an answer, paste this into the second input field in your browser.
* Press `Start Session`
* The connection state will be printed in the terminal and under `logs` in the browser.
@@ -28,7 +28,7 @@ Run `broadcast` OR run `main.go` in `github.com/pion/webrtc/examples/broadcast`
### Join the broadcast
* Click `Join a Broadcast`
* Copy the string in the first input labelled `Browser base64 Session Description`
* Run `curl localhost:8080/sdp -d "$BROWSER_OFFER"`. `$BROWSER_OFFER` is the value you copied in the last step.
* Run `curl localhost:8080 -d "$BROWSER_OFFER"`. `$BROWSER_OFFER` is the value you copied in the last step.
* The `broadcast` terminal application will respond with an answer, paste this into the second input field in your browser.
* Press `Start Session`
* The connection state will be printed in the terminal and under `logs` in the browser.

View File

@@ -9,6 +9,7 @@ package main
import (
"errors"
"flag"
"fmt"
"io"
@@ -19,7 +20,10 @@ import (
)
func main() { // nolint:gocognit
sdpChan := signal.HTTPSDPServer()
port := flag.Int("port", 8080, "http server port")
flag.Parse()
sdpChan := signal.HTTPSDPServer(*port)
// Everything below is the Pion WebRTC API, thanks for using it ❤️.
offer := webrtc.SessionDescription{}

View File

@@ -4,7 +4,6 @@
package signal
import (
"flag"
"fmt"
"io/ioutil"
"net/http"
@@ -12,12 +11,9 @@ import (
)
// HTTPSDPServer starts a HTTP Server that consumes SDPs
func HTTPSDPServer() chan string {
port := flag.Int("port", 8080, "http server port")
flag.Parse()
func HTTPSDPServer(port int) chan string {
sdpChan := make(chan string)
http.HandleFunc("/sdp", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
body, _ := ioutil.ReadAll(r.Body)
fmt.Fprintf(w, "done")
sdpChan <- string(body)
@@ -25,7 +21,7 @@ func HTTPSDPServer() chan string {
go func() {
// nolint: gosec
err := http.ListenAndServe(":"+strconv.Itoa(*port), nil)
err := http.ListenAndServe(":"+strconv.Itoa(port), nil)
if err != nil {
panic(err)
}

View File

@@ -18,7 +18,13 @@ go install github.com/pion/webrtc/v4/examples/ortc@latest
## Run the second client as answerer
Run the second client. This should be launched with the message you copied in the previous step as stdin.
`echo BASE64_MESSAGE_YOU_COPIED | ortc`
`echo $BASE64_MESSAGE_YOU_COPIED | ortc`
This will emit another base64 message. Copy this new message.
## Send base64 message to first client via CURL
* Run `curl localhost:8080 -d "BASE64_MESSAGE_YOU_COPIED"`. `BASE64_MESSAGE_YOU_COPIED` is the value you copied in the last step.
### Enjoy
If everything worked you will see `Data channel 'Foo'-'' open.` in each terminal.

View File

@@ -18,6 +18,7 @@ import (
func main() {
isOffer := flag.Bool("offer", false, "Act as the offerer if set")
port := flag.Int("port", 8080, "http server port")
flag.Parse()
// Everything below is the Pion WebRTC (ORTC) API! Thanks for using it ❤️.
@@ -103,7 +104,13 @@ func main() {
// Exchange the information
fmt.Println(signal.Encode(s))
remoteSignal := Signal{}
signal.Decode(signal.MustReadStdin(), &remoteSignal)
if *isOffer {
signalingChan := signal.HTTPSDPServer(*port)
signal.Decode(<-signalingChan, &remoteSignal)
} else {
signal.Decode(signal.MustReadStdin(), &remoteSignal)
}
iceRole := webrtc.ICERoleControlled
if *isOffer {