-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathworker_settings.go
139 lines (112 loc) · 4.34 KB
/
worker_settings.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package mediasoup
import (
"fmt"
)
type WorkerSettings struct {
// WorkerBin is the absolute path of worker binary. The default value is read
// in order from the following values: environment variable MEDIASOUP_WORKER_BIN,
// /usr/local/lib/node_modules/mediasoup/worker/out/Release/mediasoup-worker.
// To facilitate testing, it allows the use of the following pattern:
// valgrind --tool=memcheck --leak-check=full ./mediasoup-worker
WorkerBin string
// WorkerVersion is the version of mediasoup-worker. In order to communicate with
// mediasoup-worker, you must set this value correctly. If it is empty, mediasoup-go
// will try to detect the worker version.
WorkerVersion string
// LogLevel is logging level for logs generated by the media worker subprocesses
// (check the Debugging documentation). Valid values are 'debug', 'warn', 'error' and
// 'none'. Default 'error'.
LogLevel WorkerLogLevel `json:"logLevel,omitempty"`
// LogTags are log tags for debugging. Check the meaning of each available tag in the
// Debugging documentation.
LogTags []WorkerLogTag `json:"logTags,omitempty"`
// RtcMinPort is the minimum RTC port for ICE, DTLS, RTP, etc. Default 10000.
RtcMinPort uint16 `json:"rtcMinPort,omitempty"`
// RtcMaxPort is maximum RTC port for ICE, DTLS, RTP, etc. Default 59999.
RtcMaxPort uint16 `json:"rtcMaxPort,omitempty"`
// DtlsCertificateFile is the path to the DTLS public certificate file in PEM format.
// If unset, a certificate is dynamically created.
DtlsCertificateFile string `json:"dtlsCertificateFile,omitempty"`
// DtlsPrivateKeyFile is the path to the DTLS certificate private key file in PEM format.
// If unset, a certificate is dynamically created.
DtlsPrivateKeyFile string `json:"dtlsPrivateKeyFile,omitempty"`
// AppData is custom application data.
AppData interface{} `json:"appData,omitempty"`
// CustomOptions will be passed to mediasoup-worker command line such as
// --key1=value1 --key2=value2.
CustomOptions map[string]interface{}
}
// args returns the arguments passed to mediasoup-worker command line.
func (w WorkerSettings) Args() []string {
args := []string{fmt.Sprintf("--logLevel=%s", w.LogLevel)}
for _, logTag := range w.LogTags {
args = append(args, fmt.Sprintf("--logTags=%s", logTag))
}
args = append(args, fmt.Sprintf("--rtcMinPort=%d", w.RtcMinPort))
args = append(args, fmt.Sprintf("--rtcMaxPort=%d", w.RtcMaxPort))
if len(w.DtlsCertificateFile) > 0 && len(w.DtlsPrivateKeyFile) > 0 {
args = append(args,
"--dtlsCertificateFile="+w.DtlsCertificateFile,
"--dtlsPrivateKeyFile="+w.DtlsPrivateKeyFile,
)
}
for key, value := range w.CustomOptions {
args = append(args, fmt.Sprintf("--%s=%v", key, value))
}
return args
}
// WorkerUpdatableSettings is an object with fields which can be updated during
// mediasoup-worker is running.
type WorkerUpdatableSettings struct {
// LogLevel is logging level for logs generated by the media worker subprocesses (check
// the Debugging documentation). Valid values are 'debug', 'warn', 'error' and
// 'none'. Default 'error'.
LogLevel WorkerLogLevel `json:"logLevel,omitempty"`
// LogTags are log tags for debugging. Check the meaning of each available tag in the
// Debugging documentation.
LogTags []WorkerLogTag `json:"logTags,omitempty"`
}
func WithWorkerBin(workerBin string) Option {
return func(o *WorkerSettings) {
o.WorkerBin = workerBin
}
}
func WithWorkerVersion(workerVersion string) Option {
return func(o *WorkerSettings) {
o.WorkerVersion = workerVersion
}
}
func WithLogLevel(logLevel WorkerLogLevel) Option {
return func(o *WorkerSettings) {
o.LogLevel = logLevel
}
}
func WithLogTags(logTags []WorkerLogTag) Option {
return func(o *WorkerSettings) {
o.LogTags = logTags
}
}
func WithRtcMinPort(rtcMinPort uint16) Option {
return func(o *WorkerSettings) {
o.RtcMinPort = rtcMinPort
}
}
func WithRtcMaxPort(rtcMaxPort uint16) Option {
return func(o *WorkerSettings) {
o.RtcMaxPort = rtcMaxPort
}
}
func WithDtlsCert(dtlsCertificateFile, dtlsPrivateKeyFile string) Option {
return func(o *WorkerSettings) {
o.DtlsCertificateFile = dtlsCertificateFile
o.DtlsPrivateKeyFile = dtlsPrivateKeyFile
}
}
func WithCustomOption(key string, value interface{}) Option {
return func(o *WorkerSettings) {
if o.CustomOptions == nil {
o.CustomOptions = make(map[string]interface{})
}
o.CustomOptions[key] = value
}
}