Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add PlaybackBaseURL config option #4105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ type Conf struct {
// Playback
Playback bool `json:"playback"`
PlaybackAddress string `json:"playbackAddress"`
PlaybackBaseUrl string `json:"playbackBaseUrl"`
PlaybackEncryption bool `json:"playbackEncryption"`
PlaybackServerKey string `json:"playbackServerKey"`
PlaybackServerCert string `json:"playbackServerCert"`
Expand Down Expand Up @@ -350,6 +351,7 @@ func (conf *Conf) setDefaults() {

// Playback server
conf.PlaybackAddress = ":9996"
conf.PlaybackBaseUrl = ""
conf.PlaybackServerKey = "server.key"
conf.PlaybackServerCert = "server.crt"
conf.PlaybackAllowOrigin = "*"
Expand Down Expand Up @@ -641,6 +643,14 @@ func (conf *Conf) Validate(l logger.Writer) error {
conf.RTSPServerKey = *conf.ServerKey
}

// Playback

if conf.PlaybackBaseUrl != "" &&
!strings.HasPrefix(conf.PlaybackBaseUrl, "http://") &&
!strings.HasPrefix(conf.PlaybackBaseUrl, "https://") {
return fmt.Errorf("'playbackBaseUrl' must be a HTTP(S) URL")
}

// RTMP

if conf.RTMPDisable != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ func (p *Core) createResources(initial bool) error {
p.playbackServer == nil {
i := &playback.Server{
Address: p.conf.PlaybackAddress,
BaseUrl: p.conf.PlaybackBaseUrl,
Encryption: p.conf.PlaybackEncryption,
ServerKey: p.conf.PlaybackServerKey,
ServerCert: p.conf.PlaybackServerCert,
Expand Down
17 changes: 12 additions & 5 deletions internal/playback/on_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,19 @@ func (s *Server) onList(ctx *gin.Context) {
v.Add("path", pathName)
v.Add("start", entries[i].Start.Format(time.RFC3339Nano))
v.Add("duration", strconv.FormatFloat(time.Duration(entries[i].Duration).Seconds(), 'f', -1, 64))
u := &url.URL{
Scheme: scheme,
Host: ctx.Request.Host,
Path: "/get",
RawQuery: v.Encode(),

var u *url.URL
if s.BaseUrl != "" {
u, _ = url.Parse(s.BaseUrl)
u = u.JoinPath("get")
} else {
u = &url.URL{
Scheme: scheme,
Host: ctx.Request.Host,
Path: "/get",
}
}
u.RawQuery = v.Encode()
entries[i].URL = u.String()
}

Expand Down
1 change: 1 addition & 0 deletions internal/playback/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type serverAuthManager interface {
// Server is the playback server.
type Server struct {
Address string
BaseUrl string
Encryption bool
ServerKey string
ServerCert string
Expand Down