mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2025-06-27 19:12:07 +02:00
Add oneStreamPerDomain mode
This commit is contained in:
@ -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()
|
||||
|
||||
|
11
web/web.go
11
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 (
|
||||
|
Reference in New Issue
Block a user