-
Notifications
You must be signed in to change notification settings - Fork 167
/
plugins-livekit.go
73 lines (63 loc) · 2.09 KB
/
plugins-livekit.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
package rest
import (
"context"
"net/http"
"net/http/httputil"
"net/url"
"os"
"github.com/pydio/cells/v4/common"
"github.com/pydio/cells/v4/common/config"
"github.com/pydio/cells/v4/common/log"
"github.com/pydio/cells/v4/common/runtime"
"github.com/pydio/cells/v4/common/server"
"github.com/pydio/cells/v4/common/service"
)
const LiveKit = "livekit"
func init() {
if os.Getenv("CELLS_ENABLE_LIVEKIT") == "" {
return
}
config.RegisterProxy("frontend/plugin/action.livekit", config.ProxySetter(func(s config.Store, val interface{}, pa ...string) error {
if m, o := val.(map[string]interface{}); o {
if b, isBool := m[config.KeyFrontPluginEnabled].(bool); isBool {
_ = config.Set(b, "services", common.ServiceWebNamespace_+LiveKit, "enabled")
}
}
return s.Val(pa...).Set(val)
}))
runtime.Register("main", func(ctx context.Context) {
service.NewService(
service.Name(common.ServiceWebNamespace_+LiveKit),
service.Context(ctx),
service.Tag(common.ServiceTagFrontend),
service.AutoRestart(true),
service.Description("Grpc service for internal requests about frontend manifest"),
service.WithHTTP(func(ctx context.Context, mux server.HttpMux) error {
enabled := config.Get("frontend", "plugin", "action.livekit", config.KeyFrontPluginEnabled).Bool()
lkUrl := config.Get("frontend", "plugin", "action.livekit", "LK_WS_URL").String()
if !enabled || lkUrl == "" {
log.Logger(ctx).Info("Skipping Livekit plugin as not enabled")
return nil
}
u, e := url.Parse(lkUrl)
if e != nil {
return e
}
log.Logger(ctx).Info("Starting Livekit proxy")
// Setup a reverse proxy
proxy := httputil.NewSingleHostReverseProxy(u)
mux.HandleFunc("/rtc", func(writer http.ResponseWriter, request *http.Request) {
proxy.ServeHTTP(writer, request)
})
return nil
}),
service.WithHTTPStop(func(ctx context.Context, mux server.HttpMux) error {
if pp, ok := mux.(server.PatternsProvider); ok {
log.Logger(ctx).Info("Deregistering pattern /rtc on stop")
pp.DeregisterPattern("/rtc")
}
return nil
}),
)
})
}