This repository has been archived by the owner on May 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.go
101 lines (90 loc) · 2.24 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"github.com/livekit/protocol/livekit"
"github.com/urfave/cli/v2"
"google.golang.org/protobuf/encoding/protojson"
"github.com/livekit/livekit-recorder/pkg/config"
"github.com/livekit/livekit-recorder/version"
)
func main() {
app := &cli.App{
Name: "livekit-recorder",
Usage: "LiveKit Recorder",
Description: "runs the recorder in standalone mode or as a service",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "service-mode",
Usage: "run recorder service",
EnvVars: []string{"SERVICE_MODE"},
},
&cli.StringFlag{
Name: "config",
Usage: "path to LiveKit recording config defaults",
},
&cli.StringFlag{
Name: "config-body",
Usage: "Default LiveKit recording config in JSON, typically passed in as an env var in a container",
EnvVars: []string{"LIVEKIT_RECORDER_CONFIG"},
},
&cli.StringFlag{
Name: "request",
Usage: "path to json StartRecordingRequest file",
},
&cli.StringFlag{
Name: "request-body",
Usage: "StartRecordingRequest json",
EnvVars: []string{"RECORDING_REQUEST"},
},
},
Action: run,
Version: version.Version,
}
if err := app.Run(os.Args); err != nil {
fmt.Println(err)
}
}
func run(c *cli.Context) error {
if c.Bool("service-mode") {
return runService(c)
}
return runRecorder(c)
}
func getConfig(c *cli.Context) (*config.Config, error) {
configFile := c.String("config")
configBody := c.String("config-body")
if configBody == "" {
if configFile != "" {
content, err := ioutil.ReadFile(configFile)
if err != nil {
return nil, err
}
configBody = string(content)
} else {
return nil, errors.New("missing config")
}
}
return config.NewConfig(configBody)
}
func getRequest(c *cli.Context) (*livekit.StartRecordingRequest, error) {
reqFile := c.String("request")
reqBody := c.String("request-body")
var content []byte
var err error
if reqBody != "" {
content = []byte(reqBody)
} else if reqFile != "" {
content, err = ioutil.ReadFile(reqFile)
if err != nil {
return nil, err
}
} else {
return nil, errors.New("missing request")
}
req := &livekit.StartRecordingRequest{}
err = protojson.Unmarshal(content, req)
return req, err
}