diff --git a/docs/ghostream.example.yml b/docs/ghostream.example.yml index 94c8235..5fdea11 100644 --- a/docs/ghostream.example.yml +++ b/docs/ghostream.example.yml @@ -45,6 +45,10 @@ web: widgetURL: https://example.com/stream_{{.Path}} viewersCounterRefreshPeriod: 20000 + # When oneStreamPerDomain is enabled, the stream name will be the domain name. + # For example, on http://example.com:8080/ the stream will always be "example.com" + oneStreamPerDomain: false + # Configure WebRTC server webrtc: # UDP port range used to stream diff --git a/main.go b/main.go index ed2681e..3c13dd3 100644 --- a/main.go +++ b/main.go @@ -52,18 +52,19 @@ func loadConfiguration() { }) viper.SetDefault("Auth.LDAP.URI", "ldap://127.0.0.1:389") viper.SetDefault("Auth.LDAP.UserDn", "cn=users,dc=example,dc=com") + viper.SetDefault("Forwarding", make(map[string][]string)) viper.SetDefault("Monitoring.ListenAddress", ":2112") viper.SetDefault("Srt.ListenAddress", ":9710") viper.SetDefault("Srt.MaxClients", 64) + viper.SetDefault("Web.Favicon", "/static/img/favicon.svg") + viper.SetDefault("Web.Hostname", "localhost") viper.SetDefault("Web.ListenAddress", ":8080") viper.SetDefault("Web.Name", "Ghostream") - viper.SetDefault("Web.Hostname", "localhost") - viper.SetDefault("Web.Favicon", "/static/img/favicon.svg") + viper.SetDefault("Web.OneStreamPerDomain", false) viper.SetDefault("Web.ViewersCounterRefreshPeriod", 20000) - viper.SetDefault("WebRTC.MinPortUDP", 10000) viper.SetDefault("WebRTC.MaxPortUDP", 10005) + viper.SetDefault("WebRTC.MinPortUDP", 10000) viper.SetDefault("WebRTC.STUNServers", []string{"stun:stun.l.google.com:19302"}) - viper.SetDefault("Forwarding", make(map[string][]string)) // Copy STUN configuration to clients viper.Set("Web.STUNServers", viper.Get("WebRTC.STUNServers")) diff --git a/web/handler.go b/web/handler.go index 66f917a..b9a61c2 100644 --- a/web/handler.go +++ b/web/handler.go @@ -5,6 +5,7 @@ import ( "encoding/json" "html/template" "log" + "net" "net/http" "github.com/markbates/pkger" @@ -45,14 +46,26 @@ func viewerPostHandler(w http.ResponseWriter, r *http.Request) { } func viewerGetHandler(w http.ResponseWriter, r *http.Request) { + // Get stream ID from URL, or from domain name + path := r.URL.Path[1:] + if cfg.OneStreamPerDomain { + host, _, err := net.SplitHostPort(r.Host) + if err != nil { + log.Printf("Failed to split host and port from %s", r.Host) + return + } + path = host + } + // Render template data := struct { Cfg *Options Path string WidgetURL string - }{Path: r.URL.Path[1:], Cfg: cfg} + }{Path: path, Cfg: cfg} + + // Compute the WidgetURL with the stream path b := &bytes.Buffer{} - // Update the WidgetURL with the stream path _ = template.Must(template.New("").Parse(cfg.WidgetURL)).Execute(b, data) data.WidgetURL = b.String() diff --git a/web/web.go b/web/web.go index f714c9a..cecae91 100644 --- a/web/web.go +++ b/web/web.go @@ -15,16 +15,15 @@ import ( // Options holds web package configuration type Options struct { + Favicon string + Hostname string ListenAddress string Name string - Hostname string - Favicon string + OneStreamPerDomain bool SRTServerPort string - WidgetURL string + STUNServers []string ViewersCounterRefreshPeriod int - - // Copied from WebRTC configuration - STUNServers []string + WidgetURL string } var (