From d092f195d169232e169d60c54a7b0bedcdc87d84 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Sat, 5 Sep 2020 20:48:55 -0700 Subject: [PATCH] Remove jsfiddle and README Just sketching ot API --- examples/broadcast/README.md | 33 ---- examples/broadcast/jsfiddle/demo.css | 4 - examples/broadcast/jsfiddle/demo.details | 5 - examples/broadcast/jsfiddle/demo.html | 21 --- examples/broadcast/jsfiddle/demo.js | 62 -------- examples/{broadcast => fanout}/main.go | 0 .../play-from-disk-renegotation/README.md | 29 ---- .../play-from-disk-renegotation/index.html | 71 --------- examples/play-from-disk-renegotation/main.go | 147 ------------------ examples/save-to-disk/README.md | 31 ---- examples/save-to-disk/jsfiddle/demo.css | 4 - examples/save-to-disk/jsfiddle/demo.details | 5 - examples/save-to-disk/jsfiddle/demo.html | 14 -- examples/save-to-disk/jsfiddle/demo.js | 38 ----- .../{simulcast => simulcast-receive}/main.go | 0 examples/simulcast/README.md | 27 ---- examples/simulcast/jsfiddle/demo.css | 4 - examples/simulcast/jsfiddle/demo.details | 5 - examples/simulcast/jsfiddle/demo.html | 18 --- examples/simulcast/jsfiddle/demo.js | 92 ----------- 20 files changed, 610 deletions(-) delete mode 100644 examples/broadcast/README.md delete mode 100644 examples/broadcast/jsfiddle/demo.css delete mode 100644 examples/broadcast/jsfiddle/demo.details delete mode 100644 examples/broadcast/jsfiddle/demo.html delete mode 100644 examples/broadcast/jsfiddle/demo.js rename examples/{broadcast => fanout}/main.go (100%) delete mode 100644 examples/play-from-disk-renegotation/README.md delete mode 100644 examples/play-from-disk-renegotation/index.html delete mode 100644 examples/play-from-disk-renegotation/main.go delete mode 100644 examples/save-to-disk/README.md delete mode 100644 examples/save-to-disk/jsfiddle/demo.css delete mode 100644 examples/save-to-disk/jsfiddle/demo.details delete mode 100644 examples/save-to-disk/jsfiddle/demo.html delete mode 100644 examples/save-to-disk/jsfiddle/demo.js rename examples/{simulcast => simulcast-receive}/main.go (100%) delete mode 100644 examples/simulcast/README.md delete mode 100644 examples/simulcast/jsfiddle/demo.css delete mode 100644 examples/simulcast/jsfiddle/demo.details delete mode 100644 examples/simulcast/jsfiddle/demo.html delete mode 100644 examples/simulcast/jsfiddle/demo.js diff --git a/examples/broadcast/README.md b/examples/broadcast/README.md deleted file mode 100644 index 2840b2a..0000000 --- a/examples/broadcast/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# broadcast -broadcast is a Pion WebRTC application that demonstrates how to broadcast a video to many peers, while only requiring the broadcaster to upload once. - -This could serve as the building block to building conferencing software, and other applications where publishers are bandwidth constrained. - -## Instructions -### Download broadcast -``` -export GO111MODULE=on -go get github.com/pion/webrtc/v3/examples/broadcast -``` - -### Open broadcast example page -[jsfiddle.net](https://jsfiddle.net/d2mt13y6/) You should see two buttons 'Publish a Broadcast' and 'Join a Broadcast' - -### Run Broadcast -#### Linux/macOS -Run `broadcast` OR run `main.go` in `github.com/pion/webrtc/examples/broadcast` - -### Start a publisher - -* Click `Publish a Broadcast` -* `curl localhost:8080/sdp -d "YOUR SDP"`. The `broadcast` application will respond with an offer, paste this into the second input field. Then press `Start Session` - -### Join the broadcast -* Click `Join a Broadcast` -* `curl localhost:8080/sdp -d "YOUR SDP"`. The `broadcast` application will respond with an offer, paste this into the second input field. Then press `Start Session` - -You can change the listening port using `-port 8011` - -You can `Join the broadcast` as many times as you want. The `broadcast` Golang application is relaying all traffic, so your browser only has to upload once. - -Congrats, you have used Pion WebRTC! Now start building something cool diff --git a/examples/broadcast/jsfiddle/demo.css b/examples/broadcast/jsfiddle/demo.css deleted file mode 100644 index 9e43d34..0000000 --- a/examples/broadcast/jsfiddle/demo.css +++ /dev/null @@ -1,4 +0,0 @@ -textarea { - width: 500px; - min-height: 75px; -} \ No newline at end of file diff --git a/examples/broadcast/jsfiddle/demo.details b/examples/broadcast/jsfiddle/demo.details deleted file mode 100644 index 1f27730..0000000 --- a/examples/broadcast/jsfiddle/demo.details +++ /dev/null @@ -1,5 +0,0 @@ ---- - name: broadcast - description: Example of a broadcast using Pion WebRTC - authors: - - Sean DuBois diff --git a/examples/broadcast/jsfiddle/demo.html b/examples/broadcast/jsfiddle/demo.html deleted file mode 100644 index dd6fed9..0000000 --- a/examples/broadcast/jsfiddle/demo.html +++ /dev/null @@ -1,21 +0,0 @@ - - -
- -Video
-
- - -
- -
- -Logs
-
diff --git a/examples/broadcast/jsfiddle/demo.js b/examples/broadcast/jsfiddle/demo.js deleted file mode 100644 index 54ba643..0000000 --- a/examples/broadcast/jsfiddle/demo.js +++ /dev/null @@ -1,62 +0,0 @@ -/* eslint-env browser */ -var log = msg => { - document.getElementById('logs').innerHTML += msg + '
' -} - -window.createSession = isPublisher => { - let pc = new RTCPeerConnection({ - iceServers: [ - { - urls: 'stun:stun.l.google.com:19302' - } - ] - }) - pc.oniceconnectionstatechange = e => log(pc.iceConnectionState) - pc.onicecandidate = event => { - if (event.candidate === null) { - document.getElementById('localSessionDescription').value = btoa(JSON.stringify(pc.localDescription)) - } - } - - if (isPublisher) { - navigator.mediaDevices.getUserMedia({ video: true, audio: false }) - .then(stream => { - pc.addStream(document.getElementById('video1').srcObject = stream) - pc.createOffer() - .then(d => pc.setLocalDescription(d)) - .catch(log) - }).catch(log) - } else { - pc.addTransceiver('video') - pc.createOffer() - .then(d => pc.setLocalDescription(d)) - .catch(log) - - pc.ontrack = function (event) { - var el = document.getElementById('video1') - el.srcObject = event.streams[0] - el.autoplay = true - el.controls = true - } - } - - window.startSession = () => { - let sd = document.getElementById('remoteSessionDescription').value - if (sd === '') { - return alert('Session Description must not be empty') - } - - try { - pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(atob(sd)))) - } catch (e) { - alert(e) - } - } - - let btns = document.getElementsByClassName('createSessionButton') - for (let i = 0; i < btns.length; i++) { - btns[i].style = 'display: none' - } - - document.getElementById('signalingContainer').style = 'display: block' -} diff --git a/examples/broadcast/main.go b/examples/fanout/main.go similarity index 100% rename from examples/broadcast/main.go rename to examples/fanout/main.go diff --git a/examples/play-from-disk-renegotation/README.md b/examples/play-from-disk-renegotation/README.md deleted file mode 100644 index 68434ad..0000000 --- a/examples/play-from-disk-renegotation/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# play-from-disk-renegotiation -play-from-disk-renegotiation demonstrates Pion WebRTC's renegotiation abilities. - -For a simpler example of playing a file from disk we also have [examples/play-from-disk](/examples/play-from-disk) - -## Instructions - -### Download play-from-disk-renegotiation -This example requires you to clone the repo since it is serving static HTML. - -``` -mkdir -p $GOPATH/src/github.com/pion -cd $GOPATH/src/github.com/pion -git clone https://github.com/pion/webrtc.git -cd webrtc/examples/play-from-disk-renegotiation -``` - -### Create IVF named `output.ivf` that contains a VP8 track -``` -ffmpeg -i $INPUT_FILE -g 30 output.ivf -``` - -### Run play-from-disk-renegotiation -The `output.ivf` you created should be in the same directory as `play-from-disk-renegotiation`. Execute `go run *.go` - -### Open the Web UI -Open [http://localhost:8080](http://localhost:8080) and you should have a `Add Track` and `Remove Track` button. Press these to add as many tracks as you want, or to remove as many as you wish. - -Congrats, you have used Pion WebRTC! Now start building something cool diff --git a/examples/play-from-disk-renegotation/index.html b/examples/play-from-disk-renegotation/index.html deleted file mode 100644 index c6ffd72..0000000 --- a/examples/play-from-disk-renegotation/index.html +++ /dev/null @@ -1,71 +0,0 @@ - - - play-from-disk-renegotation - - - -
-
- - -

Video

-

- -

Logs

-
- - - - diff --git a/examples/play-from-disk-renegotation/main.go b/examples/play-from-disk-renegotation/main.go deleted file mode 100644 index 1d144f5..0000000 --- a/examples/play-from-disk-renegotation/main.go +++ /dev/null @@ -1,147 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "math/rand" - "net/http" - "os" - "time" - - "github.com/pion/webrtc-v3-design/webrtc" - "github.com/pion/webrtc/v3/pkg/media" - "github.com/pion/webrtc/v3/pkg/media/ivfreader" -) - -var peerConnection *webrtc.PeerConnection //nolint - -// doSignaling exchanges all state of the local PeerConnection and is called -// every time a video is added or removed -func doSignaling(w http.ResponseWriter, r *http.Request) { - var offer webrtc.SessionDescription - if err := json.NewDecoder(r.Body).Decode(&offer); err != nil { - panic(err) - } - - if err := peerConnection.SetRemoteDescription(offer); err != nil { - panic(err) - } - - // Create channel that is blocked until ICE Gathering is complete - gatherComplete := webrtc.GatheringCompletePromise(peerConnection) - - answer, err := peerConnection.CreateAnswer(nil) - if err != nil { - panic(err) - } else if err = peerConnection.SetLocalDescription(answer); err != nil { - panic(err) - } - - // Block until ICE Gathering is complete, disabling trickle ICE - // we do this because we only can exchange one signaling message - // in a production application you should exchange ICE Candidates via OnICECandidate - <-gatherComplete - - response, err := json.Marshal(*peerConnection.LocalDescription()) - if err != nil { - panic(err) - } - - w.Header().Set("Content-Type", "application/json") - if _, err := w.Write(response); err != nil { - panic(err) - } -} - -// Add a single video track -func createPeerConnection(w http.ResponseWriter, r *http.Request) { - if peerConnection.ConnectionState() != webrtc.PeerConnectionStateNew { - panic(fmt.Sprintf("createPeerConnection called in non-new state (%s)", peerConnection.ConnectionState())) - } - - doSignaling(w, r) - fmt.Println("PeerConnection has been created") -} - -// Add a single video track -func addVideo(w http.ResponseWriter, r *http.Request) { - videoTrack, err := peerConnection.NewTrack(webrtc.DefaultPayloadTypeVP8, rand.Uint32(), fmt.Sprintf("video-%d", rand.Uint32()), fmt.Sprintf("video-%d", rand.Uint32())) - if err != nil { - panic(err) - } - if _, err = peerConnection.AddTrack(videoTrack); err != nil { - panic(err) - } - - go writeVideoToTrack(videoTrack) - doSignaling(w, r) - fmt.Println("Video track has been added") -} - -// Remove a single sender -func removeVideo(w http.ResponseWriter, r *http.Request) { - if senders := peerConnection.GetSenders(); len(senders) != 0 { - if err := peerConnection.RemoveTrack(senders[0]); err != nil { - panic(err) - } - } - - doSignaling(w, r) - fmt.Println("Video track has been removed") -} - -func main() { - rand.Seed(time.Now().UTC().UnixNano()) - - var err error - if peerConnection, err = webrtc.NewPeerConnection(webrtc.Configuration{}); err != nil { - panic(err) - } - - // Set the handler for ICE connection state - // This will notify you when the peer has connected/disconnected - peerConnection.OnICEConnectionStateChange(func(connectionState webrtc.ICEConnectionState) { - fmt.Printf("ICE Connection State has changed: %s\n", connectionState.String()) - }) - - http.Handle("/", http.FileServer(http.Dir("."))) - http.HandleFunc("/createPeerConnection", createPeerConnection) - http.HandleFunc("/addVideo", addVideo) - http.HandleFunc("/removeVideo", removeVideo) - - fmt.Println("Open http://localhost:8080 to access this demo") - panic(http.ListenAndServe(":8080", nil)) -} - -// Read a video file from disk and write it to a webrtc.Track -// When the video has been completely read this exits without error -//FIXED-TO-V3 Track=>webrtc.LocalRTPTrack -func writeVideoToTrack(t *webrtc.LocalRTPTrack) { - // Open a IVF file and start reading using our IVFReader - file, err := os.Open("output.ivf") - if err != nil { - panic(err) - } - - ivf, header, err := ivfreader.NewWith(file) - if err != nil { - panic(err) - } - - // Send our video file frame at a time. Pace our sending so we send it at the same speed it should be played back as. - // This isn't required since the video is timestamped, but we will such much higher loss if we send all at once. - sleepTime := time.Millisecond * time.Duration((float32(header.TimebaseNumerator)/float32(header.TimebaseDenominator))*1000) - for { - frame, _, err := ivf.ParseNextFrame() - if err != nil { - fmt.Printf("Finish writing video track: %s ", err) - return - } - - time.Sleep(sleepTime) - if err = t.WriteSample(media.Sample{Data: frame, Samples: 90000}); err != nil { - fmt.Printf("Finish writing video track: %s ", err) - return - } - } -} diff --git a/examples/save-to-disk/README.md b/examples/save-to-disk/README.md deleted file mode 100644 index 9046479..0000000 --- a/examples/save-to-disk/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# save-to-disk -save-to-disk is a simple application that shows how to record your webcam/microphone using Pion WebRTC and save VP8/Opus to disk. - -If you wish to save H264 to disk checkout out [save-to-webm](https://github.com/pion/example-webrtc-applications/tree/master/save-to-webm) - -## Instructions -### Download save-to-disk -``` -export GO111MODULE=on -go get github.com/pion/webrtc/v3/examples/save-to-disk -``` - -### Open save-to-disk example page -[jsfiddle.net](https://jsfiddle.net/b3d72av1/) you should see your Webcam, two text-areas and a 'Start Session' button - -### Run save-to-disk, with your browsers SessionDescription as stdin -In the jsfiddle the top textarea is your browser, copy that and: -#### Linux/macOS -Run `echo $BROWSER_SDP | save-to-disk` -#### Windows -1. Paste the SessionDescription into a file. -1. Run `save-to-disk < my_file` - -### Input save-to-disk's SessionDescription into your browser -Copy the text that `save-to-disk` just emitted and copy into second text area - -### Hit 'Start Session' in jsfiddle, wait, close jsfiddle, enjoy your video! -In the folder you ran `save-to-disk` you should now have a file `output-1.ivf` play with your video player of choice! -> Note: In order to correctly create the files, the remote client (JSFiddle) should be closed. The Go example will automatically close itself. - -Congrats, you have used Pion WebRTC! Now start building something cool diff --git a/examples/save-to-disk/jsfiddle/demo.css b/examples/save-to-disk/jsfiddle/demo.css deleted file mode 100644 index 9e43d34..0000000 --- a/examples/save-to-disk/jsfiddle/demo.css +++ /dev/null @@ -1,4 +0,0 @@ -textarea { - width: 500px; - min-height: 75px; -} \ No newline at end of file diff --git a/examples/save-to-disk/jsfiddle/demo.details b/examples/save-to-disk/jsfiddle/demo.details deleted file mode 100644 index 06d7349..0000000 --- a/examples/save-to-disk/jsfiddle/demo.details +++ /dev/null @@ -1,5 +0,0 @@ ---- - name: save-to-disk - description: Example of using Pion WebRTC to save video to disk in an IVF container - authors: - - Sean DuBois diff --git a/examples/save-to-disk/jsfiddle/demo.html b/examples/save-to-disk/jsfiddle/demo.html deleted file mode 100644 index cba0be0..0000000 --- a/examples/save-to-disk/jsfiddle/demo.html +++ /dev/null @@ -1,14 +0,0 @@ -Browser base64 Session Description
-
- -Golang base64 Session Description
-
-
- -
- -Video
-
- -Logs
-
diff --git a/examples/save-to-disk/jsfiddle/demo.js b/examples/save-to-disk/jsfiddle/demo.js deleted file mode 100644 index 8599c76..0000000 --- a/examples/save-to-disk/jsfiddle/demo.js +++ /dev/null @@ -1,38 +0,0 @@ -/* eslint-env browser */ - -let pc = new RTCPeerConnection({ - iceServers: [ - { - urls: 'stun:stun.l.google.com:19302' - } - ] -}) -var log = msg => { - document.getElementById('logs').innerHTML += msg + '
' -} - -navigator.mediaDevices.getUserMedia({ video: true, audio: true }) - .then(stream => { - pc.addStream(document.getElementById('video1').srcObject = stream) - pc.createOffer().then(d => pc.setLocalDescription(d)).catch(log) - }).catch(log) - -pc.oniceconnectionstatechange = e => log(pc.iceConnectionState) -pc.onicecandidate = event => { - if (event.candidate === null) { - document.getElementById('localSessionDescription').value = btoa(JSON.stringify(pc.localDescription)) - } -} - -window.startSession = () => { - let sd = document.getElementById('remoteSessionDescription').value - if (sd === '') { - return alert('Session Description must not be empty') - } - - try { - pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(atob(sd)))) - } catch (e) { - alert(e) - } -} diff --git a/examples/simulcast/main.go b/examples/simulcast-receive/main.go similarity index 100% rename from examples/simulcast/main.go rename to examples/simulcast-receive/main.go diff --git a/examples/simulcast/README.md b/examples/simulcast/README.md deleted file mode 100644 index a19ddd0..0000000 --- a/examples/simulcast/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# simulcast -demonstrates of how to handle incoming track with multiple simulcast rtp streams and show all them back. - -## Instructions -### Download simulcast -``` -go get github.com/pion/webrtc/v3/examples/simulcast -``` - -### Open simulcast example page -[jsfiddle.net](https://jsfiddle.net/rxk4bftc) you should see two text-areas and a 'Start Session' button. - -### Run simulcast, with your browsers SessionDescription as stdin -In the jsfiddle the top textarea is your browser, copy that and: -#### Linux/macOS -Run `echo $BROWSER_SDP | simulcast` -#### Windows -1. Paste the SessionDescription into a file. -1. Run `simulcast < my_file` - -### Input simulcast's SessionDescription into your browser -Copy the text that `simulcast` just emitted and copy into second text area - -### Hit 'Start Session' in jsfiddle, enjoy your video! -Your browser should send a simulcast track to Pion, and then all 3 incoming streams will be relayed back. - -Congrats, you have used Pion WebRTC! Now start building something cool diff --git a/examples/simulcast/jsfiddle/demo.css b/examples/simulcast/jsfiddle/demo.css deleted file mode 100644 index 9e43d34..0000000 --- a/examples/simulcast/jsfiddle/demo.css +++ /dev/null @@ -1,4 +0,0 @@ -textarea { - width: 500px; - min-height: 75px; -} \ No newline at end of file diff --git a/examples/simulcast/jsfiddle/demo.details b/examples/simulcast/jsfiddle/demo.details deleted file mode 100644 index eb0b725..0000000 --- a/examples/simulcast/jsfiddle/demo.details +++ /dev/null @@ -1,5 +0,0 @@ ---- - name: simulcast - description: Example of how to have Pion handle incoming track with multiple simulcast rtp streams and show all them back. - authors: - - Simone Gotti diff --git a/examples/simulcast/jsfiddle/demo.html b/examples/simulcast/jsfiddle/demo.html deleted file mode 100644 index 1377fcd..0000000 --- a/examples/simulcast/jsfiddle/demo.html +++ /dev/null @@ -1,18 +0,0 @@ - -Browser base64 Session Description
-
- -Golang base64 Session Description
-
-
- -
- -
- Browser stream
- -
- -
- Video from server
-
diff --git a/examples/simulcast/jsfiddle/demo.js b/examples/simulcast/jsfiddle/demo.js deleted file mode 100644 index e8ecc04..0000000 --- a/examples/simulcast/jsfiddle/demo.js +++ /dev/null @@ -1,92 +0,0 @@ -// Create peer conn -const pc = new RTCPeerConnection({ - iceServers: [ - { - urls: "stun:stun.l.google.com:19302", - }, - ], -}); - -pc.oniceconnectionstatechange = (e) => { - console.log("connection state change", pc.iceConnectionState); -}; -pc.onicecandidate = (event) => { - if (event.candidate === null) { - document.getElementById("localSessionDescription").value = btoa( - JSON.stringify(pc.localDescription) - ); - } -}; - -pc.onnegotiationneeded = (e) => - pc - .createOffer() - .then((d) => pc.setLocalDescription(d)) - .catch(console.error); - -pc.ontrack = (event) => { - console.log("Got track event", event); - let video = document.createElement("video"); - video.srcObject = event.streams[0]; - video.autoplay = true; - video.width = "500"; - let label = document.createElement("div"); - label.textContent = event.streams[0].id; - document.getElementById("serverVideos").appendChild(label); - document.getElementById("serverVideos").appendChild(video); -}; - -navigator.mediaDevices - .getUserMedia({ - video: { - width: { - ideal: 4096, - }, - height: { - ideal: 2160, - }, - frameRate: { - ideal: 60, - min: 10, - }, - }, - audio: false, - }) - .then((stream) => { - document.getElementById("browserVideo").srcObject = stream; - pc.addTransceiver(stream.getVideoTracks()[0], { - direction: "sendonly", - streams: [stream], - sendEncodings: [ - // for firefox order matters... first high resolution, then scaled resolutions... - { - rid: "f", - }, - { - rid: "h", - scaleResolutionDownBy: 2.0, - }, - { - rid: "q", - scaleResolutionDownBy: 4.0, - }, - ], - }); - pc.addTransceiver("video"); - pc.addTransceiver("video"); - pc.addTransceiver("video"); - }); - -window.startSession = () => { - const sd = document.getElementById("remoteSessionDescription").value; - if (sd === "") { - return alert("Session Description must not be empty"); - } - - try { - console.log("answer", JSON.parse(atob(sd))); - pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(atob(sd)))); - } catch (e) { - alert(e); - } -};