Skip to content

Instantly share code, notes, and snippets.

@Sean-Der
Created August 27, 2021 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sean-Der/2175a088f8112c75cd410c8f98f34120 to your computer and use it in GitHub Desktop.
Save Sean-Der/2175a088f8112c75cd410c8f98f34120 to your computer and use it in GitHub Desktop.
commit 7b2aae677126b40d84e4cf1c1f6f8859cc1bf973
Author: Sean DuBois <sean@siobud.com>
Date: Thu Aug 26 22:02:39 2021 -0400
FireFox fix
diff --git a/src/main.go b/src/main.go
index 577a5ec..5a53567 100644
--- a/src/main.go
+++ b/src/main.go
@@ -51,51 +51,7 @@ type Display struct {
func main() {
r := mux.NewRouter()
- r.HandleFunc("/resize", func(w http.ResponseWriter, r *http.Request) {
- AllowCors(&w)
-
- reqBody, _ := ioutil.ReadAll(r.Body)
- var display Display
- json.Unmarshal(reqBody, &display)
- fmt.Println("Display for resize is ", display)
- cmd := exec.Command("sh", "scripts/windowresize.sh", display.Width, display.Height)
- _, err := cmd.Output()
- if err != nil {
- fmt.Println("Error on output", err)
- }
-
- json.NewEncoder(w).Encode("Success")
- })
-
- r.HandleFunc("/sdp", func(w http.ResponseWriter, r *http.Request) {
- AllowCors(&w)
-
- reqBody, _ := ioutil.ReadAll(r.Body)
- var sdpString struct {
- SDP string `json:"sdp"`
- }
- json.Unmarshal(reqBody, &sdpString)
-
- sdp := startWebrtc(sdpString.SDP)
- json.NewEncoder(w).Encode(sdp)
- })
-
- server := http.Server{Addr: ":8080", Handler: r}
- server.ListenAndServe()
-}
-
-func startWebrtc(sdpString string) (sdp string) {
- config := webrtc.Configuration{
- ICEServers: []webrtc.ICEServer{
- {
- URLs: []string{"stun:stun.l.google.com:19302"},
- },
- },
- }
-
- // Wait for the offer to be pasted
- offer := webrtc.SessionDescription{}
- Decode(sdpString, &offer)
+ exec.Command("sh", "scripts/windowresize.sh", "640", "480")
// Create a new RTCPeerConnection
vpx, err := vpx.NewVP8Params()
@@ -113,10 +69,7 @@ func startWebrtc(sdpString string) (sdp string) {
mediadevices.WithAudioEncoders(&opusParams),
)
- mediaEngine := webrtc.MediaEngine{}
- codecSelector.Populate(&mediaEngine)
- api := webrtc.NewAPI(webrtc.WithMediaEngine(&mediaEngine))
- peerConnection, err := api.NewPeerConnection(config)
+ peerConnection, err := webrtc.NewPeerConnection(webrtc.Configuration{})
if err != nil {
panic(err)
}
@@ -147,43 +100,63 @@ func startWebrtc(sdpString string) (sdp string) {
track.ID(), err)
})
- _, err = peerConnection.AddTransceiverFromTrack(track,
- webrtc.RtpTransceiverInit{
- Direction: webrtc.RTPTransceiverDirectionSendonly,
- },
- )
- if err != nil {
+ if _, err = peerConnection.AddTrack(track); err != nil {
panic(err)
}
}
- // Set the remote SessionDescription
- err = peerConnection.SetRemoteDescription(offer)
- if err != nil {
- panic(err)
- }
+ r.HandleFunc("/resize", func(w http.ResponseWriter, r *http.Request) {
+ AllowCors(&w)
- // Create an answer
- answer, err := peerConnection.CreateAnswer(nil)
- if err != nil {
- panic(err)
- }
+ reqBody, _ := ioutil.ReadAll(r.Body)
+ var display Display
+ json.Unmarshal(reqBody, &display)
+ fmt.Println("Display for resize is ", display)
+ cmd := exec.Command("sh", "scripts/windowresize.sh", display.Width, display.Height)
+ _, err := cmd.Output()
+ if err != nil {
+ fmt.Println("Error on output", err)
+ }
- // Create channel that is blocked until ICE Gathering is complete
- gatherComplete := webrtc.GatheringCompletePromise(peerConnection)
+ json.NewEncoder(w).Encode("Success")
+ })
- // Sets the LocalDescription, and starts our UDP listeners
- err = peerConnection.SetLocalDescription(answer)
- if err != nil {
- panic(err)
- }
+ r.HandleFunc("/offer", func(w http.ResponseWriter, r *http.Request) {
+ AllowCors(&w)
+
+ offer, err := peerConnection.CreateOffer(nil)
+ if err != nil {
+ panic(err)
+ }
+
+ gatherComplete := webrtc.GatheringCompletePromise(peerConnection)
+ if err = peerConnection.SetLocalDescription(offer); err != nil {
+ panic(err)
+ }
+ <-gatherComplete
+
+ json.NewEncoder(w).Encode(Encode(*peerConnection.LocalDescription()))
+ })
+
+ r.HandleFunc("/answer", func(w http.ResponseWriter, r *http.Request) {
+ AllowCors(&w)
+
+ reqBody, _ := ioutil.ReadAll(r.Body)
+ var sdpString struct {
+ SDP string `json:"sdp"`
+ }
+ json.Unmarshal(reqBody, &sdpString)
+
+ answer := webrtc.SessionDescription{}
+ Decode(sdpString.SDP, &answer)
- // 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
+ peerConnection.SetRemoteDescription(answer)
- return Encode(*peerConnection.LocalDescription())
+ json.NewEncoder(w).Encode("Success")
+ })
+
+ server := http.Server{Addr: ":8080", Handler: r}
+ server.ListenAndServe()
}
// Encode encodes the input in base64
diff --git a/src/webrtc b/src/webrtc
deleted file mode 100755
index 28fc8e1..0000000
Binary files a/src/webrtc and /dev/null differ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment