Last active
October 29, 2021 02:27
-
-
Save Sean-Der/841365c858559b19fda4cc5458ebbf92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/server/main.go b/server/main.go | |
index 3f5b52f..fecd6c5 100644 | |
--- a/server/main.go | |
+++ b/server/main.go | |
@@ -5,6 +5,7 @@ import ( | |
"fmt" | |
"io" | |
"log" | |
+ "net" | |
"net/http" | |
"os" | |
"sync/atomic" | |
@@ -21,6 +22,7 @@ import ( | |
var ( | |
outboundVideoTrack *webrtc.TrackLocalStaticSample | |
peerConnectionCount int64 | |
+ api *webrtc.API | |
) | |
// Generate CSV with columns of timestamp, peerConnectionCount, and cpuUsage | |
@@ -50,7 +52,7 @@ func reportBuilder() { | |
// HTTP Handler that accepts an Offer and returns an Answer | |
// adds outboundVideoTrack to PeerConnection | |
func doSignaling(w http.ResponseWriter, r *http.Request) { | |
- peerConnection, err := webrtc.NewPeerConnection(webrtc.Configuration{}) | |
+ peerConnection, err := api.NewPeerConnection(webrtc.Configuration{}) | |
if err != nil { | |
panic(err) | |
} | |
@@ -102,7 +104,30 @@ func doSignaling(w http.ResponseWriter, r *http.Request) { | |
} | |
func main() { | |
- var err error | |
+ settingEngine := webrtc.SettingEngine{} | |
+ m := &webrtc.MediaEngine{} | |
+ | |
+ if err := m.RegisterDefaultCodecs(); err != nil { | |
+ panic(err) | |
+ } | |
+ | |
+ // Enable support only for TCP ICE candidates. | |
+ settingEngine.SetNetworkTypes([]webrtc.NetworkType{ | |
+ webrtc.NetworkTypeTCP4, | |
+ webrtc.NetworkTypeTCP6, | |
+ }) | |
+ | |
+ tcpListener, err := net.ListenTCP("tcp", &net.TCPAddr{ | |
+ IP: net.IP{0, 0, 0, 0}, | |
+ Port: 8443, | |
+ }) | |
+ if err != nil { | |
+ panic(err) | |
+ } | |
+ | |
+ settingEngine.SetICETCPMux(webrtc.NewICETCPMux(nil, tcpListener, 8)) | |
+ api = webrtc.NewAPI(webrtc.WithSettingEngine(settingEngine), webrtc.WithMediaEngine(m)) | |
+ | |
outboundVideoTrack, err = webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{ | |
MimeType: "video/h264", | |
}, "pion-rtsp", "pion-rtsp") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment