allow specifying custom ENV variables using API.

This commit is contained in:
Miroslav Šedivý
2021-04-06 09:09:11 +00:00
parent c07c21752a
commit 172b211dab
3 changed files with 58 additions and 22 deletions
+6
View File
@@ -287,6 +287,12 @@ components:
example: 128
audio_pipeline:
type: string
envs:
type: object
additionalProperties:
type: string
example:
CUSTOM_ENV: custom value
RoomStats:
type: object
+1 -1
View File
@@ -84,7 +84,7 @@ docker-compose up -d
- [x] add GUI
- [x] add HTTPS support
- [x] add authentication provider for traefik
- [ ] allow specifying custom ENV variables
- [x] allow specifying custom ENV variables (TODO: FE.)
- [ ] allow mounting direcotries for persistent data
- [ ] add upgrade button
- [ ] auto pull images, that do not exist
+51 -21
View File
@@ -5,8 +5,24 @@ import (
"strconv"
"strings"
"time"
"m1k1o/neko_rooms/internal/utils"
)
var blacklistedEnvs = []string{
// ignore bunch of default envs
"DEBIAN_FRONTEND",
"DISPLAY",
"USER",
"PATH",
// ignore bunch of envs managed by neko-rooms
"NEKO_BIND",
"NEKO_EPR",
"NEKO_NAT1TO1",
"NEKO_ICELITE",
}
type RoomsConfig struct {
Connections uint16 `json:"connections"`
NekoImages []string `json:"neko_images"`
@@ -42,6 +58,8 @@ type RoomSettings struct {
AudioPipeline string `json:"audio_pipeline,omitempty"`
BroadcastPipeline string `json:"broadcast_pipeline,omitempty"`
Envs map[string]string `json:"envs"`
}
func (settings *RoomSettings) ToEnv() []string {
@@ -52,10 +70,6 @@ func (settings *RoomSettings) ToEnv() []string {
fmt.Sprintf("NEKO_MAX_FPS=%d", settings.VideoMaxFPS),
}
if settings.BroadcastPipeline != "" {
env = append(env, fmt.Sprintf("NEKO_BROADCAST_PIPELINE=%s", settings.BroadcastPipeline))
}
if settings.VideoCodec == "VP8" || settings.VideoCodec == "VP9" || settings.VideoCodec == "H264" {
env = append(env, fmt.Sprintf("NEKO_%s=true", strings.ToUpper(settings.VideoCodec)))
}
@@ -80,63 +94,79 @@ func (settings *RoomSettings) ToEnv() []string {
env = append(env, fmt.Sprintf("NEKO_AUDIO=%s", settings.AudioPipeline))
}
if settings.BroadcastPipeline != "" {
env = append(env, fmt.Sprintf("NEKO_BROADCAST_PIPELINE=%s", settings.BroadcastPipeline))
}
for key, val := range settings.Envs {
if in, _ := utils.ArrayIn(key, blacklistedEnvs); !in {
env = append(env, fmt.Sprintf("%s=%s", key, val))
}
}
return env
}
func (settings *RoomSettings) FromEnv(envs []string) error {
settings.Envs = map[string]string{}
var err error
for _, env := range envs {
r := strings.SplitAfterN(env, "=", 2)
r := strings.SplitN(env, "=", 2)
key := r[0]
val := r[1]
switch key {
case "NEKO_PASSWORD=":
case "NEKO_PASSWORD":
settings.UserPass = val
case "NEKO_PASSWORD_ADMIN=":
case "NEKO_PASSWORD_ADMIN":
settings.AdminPass = val
case "NEKO_SCREEN=":
case "NEKO_SCREEN":
settings.Screen = val
case "NEKO_MAX_FPS=":
case "NEKO_MAX_FPS":
settings.VideoMaxFPS, err = strconv.Atoi(val)
case "NEKO_BROADCAST_PIPELINE=":
case "NEKO_BROADCAST_PIPELINE":
settings.BroadcastPipeline = val
case "NEKO_VP8=":
case "NEKO_VP8":
if ok, _ := strconv.ParseBool(val); ok {
settings.VideoCodec = "VP8"
}
case "NEKO_VP9=":
case "NEKO_VP9":
if ok, _ := strconv.ParseBool(val); ok {
settings.VideoCodec = "VP9"
}
case "NEKO_H264=":
case "NEKO_H264":
if ok, _ := strconv.ParseBool(val); ok {
settings.VideoCodec = "H264"
}
case "NEKO_VIDEO_BITRATE=":
case "NEKO_VIDEO_BITRATE":
settings.VideoBitrate, err = strconv.Atoi(val)
case "NEKO_VIDEO=":
case "NEKO_VIDEO":
settings.VideoPipeline = val
case "NEKO_OPUS=":
case "NEKO_OPUS":
if ok, _ := strconv.ParseBool(val); ok {
settings.AudioCodec = "OPUS"
}
case "NEKO_G722=":
case "NEKO_G722":
if ok, _ := strconv.ParseBool(val); ok {
settings.AudioCodec = "G722"
}
case "NEKO_PCMU=":
case "NEKO_PCMU":
if ok, _ := strconv.ParseBool(val); ok {
settings.AudioCodec = "PCMU"
}
case "NEKO_PCMA=":
case "NEKO_PCMA":
if ok, _ := strconv.ParseBool(val); ok {
settings.AudioCodec = "PCMA"
}
case "NEKO_AUDIO_BITRATE=":
case "NEKO_AUDIO_BITRATE":
settings.AudioBitrate, err = strconv.Atoi(val)
case "NEKO_AUDIO=":
case "NEKO_AUDIO":
settings.AudioPipeline = val
default:
if in, _ := utils.ArrayIn(key, blacklistedEnvs); !in {
settings.Envs[key] = val
}
}
if err != nil {