-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (49 loc) · 1.35 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
package main
import (
"context"
"os/signal"
"syscall"
"github.com/go-gst/go-glib/glib"
"github.com/kaedwen/webrtc/pkg/common"
"github.com/kaedwen/webrtc/pkg/ring"
"github.com/kaedwen/webrtc/pkg/server"
"github.com/kaedwen/webrtc/pkg/webrtc"
"go.uber.org/zap"
)
func main() {
mainLoop := glib.NewMainLoop(glib.MainContextDefault(), true)
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
cfg := common.Config{}
cfg.MustParse()
lg, err := common.NewLogger(&cfg.Logging)
if err != nil {
panic(err)
}
if cfg.Logging.Development {
lg.Info("configuration", zap.Any("", cfg))
}
http := server.NewHttpServer(lg.With(zap.String("context", "server")), &cfg)
err = ring.NewRingHandler(ctx, lg.With(zap.String("context", "ring")), &cfg.Ring)
if err != nil {
panic(err)
}
err = webrtc.NewWebrtcHandler(ctx, lg.With(zap.String("context", "webrtc")), cfg.Stream(), http.Hndl)
if err != nil {
panic(err)
}
err = http.ListenAndServe(ctx)
if err != nil {
panic(err)
}
// Listen for the interrupt signal.
<-ctx.Done()
// Restore default behavior on the interrupt signal and notify user of shutdown.
stop()
lg.Info("shutting down gracefully, press Ctrl+C again to force")
// stop gst main loop
mainLoop.Quit()
if err := http.TearDown(); err != nil {
lg.Error("timeout", zap.Error(err))
}
}