-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
70 lines (60 loc) · 1.38 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"log"
"net/http"
"os"
"github.com/hoernschen/goat/handler/signaling"
"github.com/urfave/cli"
)
var keyPath = "./ssl.key"
var certPath = "./ssl.crt"
var htmlPath = "./html/"
func main() {
app := cli.NewApp()
app.Name = "Goat"
app.Usage = "A WebRTC Server"
app.Commands = []cli.Command{
{
Name: "signaling",
Aliases: []string{"s"},
Usage: "Sets up a Media Router",
Action: func(c *cli.Context) error {
log.Println("Start Signaling Server")
go signaling.Run()
return nil
},
},
{
Name: "router",
Aliases: []string{"r"},
Usage: "Sets up a Media Router",
Flags: []cli.Flag{
cli.StringFlag{
Name: "type",
Value: "sfu",
},
},
Action: func(c *cli.Context) error {
routerType := c.String("type")
if routerType == "sfu" {
log.Println("Start Media Router")
go signaling.RunMediaRouter()
}
return nil
},
},
}
appErr := app.Run(os.Args)
if appErr != nil {
log.Fatal(appErr)
}
router := NewRouter()
router.PathPrefix("/").Handler(http.FileServer(http.Dir(htmlPath)))
httpErr := http.ListenAndServeTLS(":443", certPath, keyPath, router)
if httpErr != nil {
log.Fatal(httpErr)
}
go http.ListenAndServe(":80", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "https://"+r.Host+r.URL.String(), http.StatusMovedPermanently)
}))
}