From debcce192d9f5c1ba5b3dbba8a72cf865e3a08e5 Mon Sep 17 00:00:00 2001 From: Ingo Oppermann Date: Wed, 14 Jun 2023 22:30:00 +0200 Subject: [PATCH] Add the process domain to the bas path in placeholders and cleanup rules --- app/api/api.go | 100 +++++++++++++++++++++++++++++++++++-------- restream/restream.go | 4 ++ 2 files changed, 85 insertions(+), 19 deletions(-) diff --git a/app/api/api.go b/app/api/api.go index ee9921d8..4a930922 100644 --- a/app/api/api.go +++ b/app/api/api.go @@ -47,6 +47,7 @@ import ( "github.com/datarhei/core/v16/service" "github.com/datarhei/core/v16/session" "github.com/datarhei/core/v16/srt" + srturl "github.com/datarhei/core/v16/srt/url" "github.com/datarhei/core/v16/update" "github.com/caddyserver/certmagic" @@ -858,11 +859,21 @@ func (a *api) start() error { }) a.replacer.RegisterReplaceFunc("diskfs", func(params map[string]string, config *restreamapp.Config, section string) string { - return a.diskfs.Metadata("base") + path := a.diskfs.Metadata("base") + if len(config.Domain) != 0 { + path = filepath.Join(path, config.Domain) + } + + return path }, nil) a.replacer.RegisterReplaceFunc("fs:disk", func(params map[string]string, config *restreamapp.Config, section string) string { - return a.diskfs.Metadata("base") + path := a.diskfs.Metadata("base") + if len(config.Domain) != 0 { + path = filepath.Join(path, config.Domain) + } + + return path }, nil) a.replacer.RegisterReplaceFunc("memfs", func(params map[string]string, config *restreamapp.Config, section string) string { @@ -886,6 +897,10 @@ func (a *api) start() error { u.User = url.User(config.Owner) } + if len(config.Domain) != 0 { + u = u.JoinPath(config.Domain) + } + return u.String() }, nil) @@ -910,6 +925,10 @@ func (a *api) start() error { u.User = url.User(config.Owner) } + if len(config.Domain) != 0 { + u = u.JoinPath(config.Domain) + } + return u.String() }, nil) @@ -923,13 +942,21 @@ func (a *api) start() error { if len(config.Owner) == 0 { identity = a.iam.GetDefaultVerifier() } else { - identity, _ = a.iam.GetVerifier(config.Owner) + var err error = nil + identity, err = a.iam.GetVerifier(config.Owner) + if err != nil { + identity = nil + } } if identity != nil { u.User = url.UserPassword(config.Owner, identity.GetServiceBasicAuth()) } + if len(config.Domain) != 0 { + u = u.JoinPath(config.Domain) + } + return u.String() }, nil) } @@ -940,25 +967,39 @@ func (a *api) start() error { host = "localhost" } - template := "rtmp://" + host + ":" + port - if cfg.RTMP.App != "/" { - template += cfg.RTMP.App + u := &url.URL{ + Scheme: "rtmp:", + Host: host + ":" + port, + Path: "/", } - template += "/" + params["name"] + + if cfg.RTMP.App != "/" { + u = u.JoinPath(cfg.RTMP.App) + } + + if len(config.Domain) != 0 { + u = u.JoinPath(config.Domain) + } + + u = u.JoinPath(params["name"]) var identity iamidentity.Verifier = nil if len(config.Owner) == 0 { identity = a.iam.GetDefaultVerifier() } else { - identity, _ = a.iam.GetVerifier(config.Owner) + var err error = nil + identity, err = a.iam.GetVerifier(config.Owner) + if err != nil { + identity = nil + } } if identity != nil { - template += "/" + identity.GetServiceToken() + u = u.JoinPath(identity.GetServiceToken()) } - return template + return u.String() }, map[string]string{ "name": "", }) @@ -969,9 +1010,30 @@ func (a *api) start() error { host = "localhost" } - template := "srt://" + host + ":" + port + "?mode=caller&transtype=live&latency=" + params["latency"] + "&streamid=" + params["name"] + u := srturl.URL{ + Scheme: "srt:", + Host: host + ":" + port, + } + + options := url.Values{} + + options.Set("mode", "caller") + options.Set("transtype", "live") + + if len(cfg.SRT.Passphrase) != 0 { + options.Set("passphrase", cfg.SRT.Passphrase) + } + + streamid := srturl.StreamInfo{} + if section == "output" { - template += ",mode:publish" + streamid.Mode = "publish" + } + + if len(config.Domain) != 0 { + streamid.Resource = config.Domain + "/" + params["name"] + } else { + streamid.Resource = params["name"] } var identity iamidentity.Verifier = nil @@ -979,18 +1041,18 @@ func (a *api) start() error { if len(config.Owner) == 0 { identity = a.iam.GetDefaultVerifier() } else { - identity, _ = a.iam.GetVerifier(config.Owner) + var err error = nil + identity, err = a.iam.GetVerifier(config.Owner) + if err != nil { + identity = nil + } } if identity != nil { - template += ",token:" + identity.GetServiceToken() + streamid.Token = identity.GetServiceToken() } - if len(cfg.SRT.Passphrase) != 0 { - template += "&passphrase=" + url.QueryEscape(cfg.SRT.Passphrase) - } - - return template + return u.String() }, map[string]string{ "name": "", "latency": "20000", // 20 milliseconds, FFmpeg requires microseconds diff --git a/restream/restream.go b/restream/restream.go index edf0d132..eac3aab8 100644 --- a/restream/restream.go +++ b/restream/restream.go @@ -721,6 +721,10 @@ func (r *restream) setCleanup(id app.ProcessID, config *app.Config) { continue } + if len(config.Domain) != 0 { + path = filepath.Join(config.Domain, path) + } + // Support legacy names if name == "diskfs" { name = "disk"