-
Notifications
You must be signed in to change notification settings - Fork 110
/
web_options.go
39 lines (32 loc) · 978 Bytes
/
web_options.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
package web
import "github.com/edaniels/gostream"
// options configures a web service.
type options struct {
// streamConfig is used to enable audio/video streaming over WebRTC.
streamConfig *gostream.StreamConfig
}
// Option configures how we set up the web service.
// Cribbed from https://github.com/grpc/grpc-go/blob/aff571cc86e6e7e740130dbbb32a9741558db805/dialoptions.go#L41
type Option interface {
apply(*options)
}
// funcOption wraps a function that modifies options into an
// implementation of the Option interface.
type funcOption struct {
f func(*options)
}
func (fdo *funcOption) apply(do *options) {
fdo.f(do)
}
func newFuncOption(f func(*options)) *funcOption {
return &funcOption{
f: f,
}
}
// WithStreamConfig returns an Option which sets the streamConfig
// used to enable audio/video streaming over WebRTC.
func WithStreamConfig(config gostream.StreamConfig) Option {
return newFuncOption(func(o *options) {
o.streamConfig = &config
})
}