forked from jiyeyuran/mediasoup-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker_settings.go
146 lines (122 loc) · 3.45 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
140
141
142
143
144
145
146
package mediasoup
import (
"fmt"
)
type WorkerSettings struct {
/**
* 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"`
/**
* Log tags for debugging. Check the meaning of each available tag in the
* Debugging documentation.
*/
LogTags []WorkerLogTag `json:"logTags,omitempty"`
/**
* Minimun RTC port for ICE, DTLS, RTP, etc. Default 10000.
*/
RtcMinPort uint16 `json:"rtcMinPort,omitempty"`
/**
* Maximum RTC port for ICE, DTLS, RTP, etc. Default 59999.
*/
RtcMaxPort uint16 `json:"rtcMaxPort,omitempty"`
/**
* Path to the DTLS public certificate file in PEM format. If unset, a
* certificate is dynamically created.
*/
DtlsCertificateFile string `json:"dtlsCertificateFile,omitempty"`
/**
* Path to the DTLS certificate private key file in PEM format. If unset, a
* certificate is dynamically created.
*/
DtlsPrivateKeyFile string `json:"dtlsPrivateKeyFile,omitempty"`
/**
* Custom application data.
*/
AppData interface{} `json:"appData,omitempty"`
/**
* Custom options.
*/
CustomOptions map[string]interface{}
}
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
}
func (w WorkerSettings) Option() Option {
return func(p *WorkerSettings) {
if len(w.LogLevel) == 0 {
w.LogLevel = WorkerLogLevel_Error
}
if w.RtcMinPort == 0 {
w.RtcMinPort = 10000
}
if w.RtcMaxPort == 0 {
w.RtcMaxPort = 59999
}
*p = w
}
}
type WorkerUpdateableSettings struct {
/**
* 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"`
/**
* Log tags for debugging. Check the meaning of each available tag in the
* Debugging documentation.
*/
LogTags []WorkerLogTag `json:"logTags,omitempty"`
}
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
}
}