forked from pion/example-webrtc-applications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (41 loc) · 1.18 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"flag"
"fmt"
"net/http"
"github.com/pion/webrtc/v2"
"github.com/povilasv/prommod"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
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() {
if err := prometheus.Register(prommod.NewCollector("sfu_ws")); err != nil {
panic(err)
}
port := flag.String("p", "8443", "https port")
flag.Parse()
http.Handle("/metrics", promhttp.Handler())
// 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))
}