Add sfu example with websocket

sfu example with websocket, support video and audio. easy to use

Resolves #507
This commit is contained in:
adwpc
2019-03-09 20:56:20 +08:00
committed by Sean DuBois
parent 43e0a64ba2
commit fb72f20f66
11 changed files with 611 additions and 0 deletions

47
examples/sfu-ws/main.go Normal file
View File

@@ -0,0 +1,47 @@
package main
import (
"flag"
"fmt"
"net/http"
"github.com/pions/webrtc"
)
func checkError(err error) {
if err != nil {
panic(err)
}
}
func init() {
// Generate pem file for https
genPem()
// Create a MediaEngine object to configure the supported codec
m = webrtc.MediaEngine{}
// Setup the codecs you want to use.
m.RegisterCodec(webrtc.NewRTPVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000))
m.RegisterCodec(webrtc.NewRTPOpusCodec(webrtc.DefaultPayloadTypeOpus, 48000))
// Create the API object with the MediaEngine
api = webrtc.NewAPI(webrtc.WithMediaEngine(m))
}
func main() {
port := flag.String("p", "8443", "https port")
flag.Parse()
// Websocket handle func
http.HandleFunc("/ws", room)
// Html handle func
http.HandleFunc("/", web)
// Support https, so we can test by lan
fmt.Println("Web listening :" + *port)
panic(http.ListenAndServeTLS(":"+*port, "cert.pem", "key.pem", nil))
}