Add oneStreamPerDomain mode

This commit is contained in:
Alexandre Iooss 2020-10-04 17:56:03 +02:00
parent 10312667d8
commit 6cf24cfb85
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
4 changed files with 29 additions and 12 deletions

View File

@ -45,6 +45,10 @@ web:
widgetURL: https://example.com/stream_{{.Path}} widgetURL: https://example.com/stream_{{.Path}}
viewersCounterRefreshPeriod: 20000 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 # Configure WebRTC server
webrtc: webrtc:
# UDP port range used to stream # UDP port range used to stream

View File

@ -52,18 +52,19 @@ func loadConfiguration() {
}) })
viper.SetDefault("Auth.LDAP.URI", "ldap://127.0.0.1:389") viper.SetDefault("Auth.LDAP.URI", "ldap://127.0.0.1:389")
viper.SetDefault("Auth.LDAP.UserDn", "cn=users,dc=example,dc=com") 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("Monitoring.ListenAddress", ":2112")
viper.SetDefault("Srt.ListenAddress", ":9710") viper.SetDefault("Srt.ListenAddress", ":9710")
viper.SetDefault("Srt.MaxClients", 64) 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.ListenAddress", ":8080")
viper.SetDefault("Web.Name", "Ghostream") viper.SetDefault("Web.Name", "Ghostream")
viper.SetDefault("Web.Hostname", "localhost") viper.SetDefault("Web.OneStreamPerDomain", false)
viper.SetDefault("Web.Favicon", "/static/img/favicon.svg")
viper.SetDefault("Web.ViewersCounterRefreshPeriod", 20000) viper.SetDefault("Web.ViewersCounterRefreshPeriod", 20000)
viper.SetDefault("WebRTC.MinPortUDP", 10000)
viper.SetDefault("WebRTC.MaxPortUDP", 10005) viper.SetDefault("WebRTC.MaxPortUDP", 10005)
viper.SetDefault("WebRTC.MinPortUDP", 10000)
viper.SetDefault("WebRTC.STUNServers", []string{"stun:stun.l.google.com:19302"}) viper.SetDefault("WebRTC.STUNServers", []string{"stun:stun.l.google.com:19302"})
viper.SetDefault("Forwarding", make(map[string][]string))
// Copy STUN configuration to clients // Copy STUN configuration to clients
viper.Set("Web.STUNServers", viper.Get("WebRTC.STUNServers")) viper.Set("Web.STUNServers", viper.Get("WebRTC.STUNServers"))

View File

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"html/template" "html/template"
"log" "log"
"net"
"net/http" "net/http"
"github.com/markbates/pkger" "github.com/markbates/pkger"
@ -45,14 +46,26 @@ func viewerPostHandler(w http.ResponseWriter, r *http.Request) {
} }
func viewerGetHandler(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 // Render template
data := struct { data := struct {
Cfg *Options Cfg *Options
Path string Path string
WidgetURL string WidgetURL string
}{Path: r.URL.Path[1:], Cfg: cfg} }{Path: path, Cfg: cfg}
// Compute the WidgetURL with the stream path
b := &bytes.Buffer{} b := &bytes.Buffer{}
// Update the WidgetURL with the stream path
_ = template.Must(template.New("").Parse(cfg.WidgetURL)).Execute(b, data) _ = template.Must(template.New("").Parse(cfg.WidgetURL)).Execute(b, data)
data.WidgetURL = b.String() data.WidgetURL = b.String()

View File

@ -15,16 +15,15 @@ import (
// Options holds web package configuration // Options holds web package configuration
type Options struct { type Options struct {
Favicon string
Hostname string
ListenAddress string ListenAddress string
Name string Name string
Hostname string OneStreamPerDomain bool
Favicon string
SRTServerPort string SRTServerPort string
WidgetURL string STUNServers []string
ViewersCounterRefreshPeriod int ViewersCounterRefreshPeriod int
WidgetURL string
// Copied from WebRTC configuration
STUNServers []string
} }
var ( var (