1
0
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:
Alexandre Iooss
2020-10-04 17:56:03 +02:00
parent 10312667d8
commit 6cf24cfb85
4 changed files with 29 additions and 12 deletions

View File

@ -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()

View File

@ -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 (