From 7ceecad3551ca9302711422de75c97a8386df8b3 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 2 Oct 2020 21:13:50 +0200 Subject: [PATCH] ID is better than Id according to Golang --- docs/ghostream.example.yml | 3 ++- web/handler.go | 12 ++++++++++-- web/template/viewer.html | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/ghostream.example.yml b/docs/ghostream.example.yml index daea1de..94c8235 100644 --- a/docs/ghostream.example.yml +++ b/docs/ghostream.example.yml @@ -41,7 +41,8 @@ web: name: Demo hostname: localhost favicon: https://www.crans.org/images/favicon.ico - widgetURL: https://example.com/ + # You can optionally use {{.Path}} to customize your widget URL + widgetURL: https://example.com/stream_{{.Path}} viewersCounterRefreshPeriod: 20000 # Configure WebRTC server diff --git a/web/handler.go b/web/handler.go index 3537b01..66f917a 100644 --- a/web/handler.go +++ b/web/handler.go @@ -1,7 +1,9 @@ package web import ( + "bytes" "encoding/json" + "html/template" "log" "net/http" @@ -45,9 +47,15 @@ func viewerPostHandler(w http.ResponseWriter, r *http.Request) { func viewerGetHandler(w http.ResponseWriter, r *http.Request) { // Render template data := struct { - Path string - Cfg *Options + Cfg *Options + Path string + WidgetURL string }{Path: r.URL.Path[1:], Cfg: cfg} + b := &bytes.Buffer{} + // Update the WidgetURL with the stream path + _ = template.Must(template.New("").Parse(cfg.WidgetURL)).Execute(b, data) + data.WidgetURL = b.String() + if err := templates.ExecuteTemplate(w, "base", data); err != nil { log.Println(err.Error()) http.Error(w, "Internal Server Error", http.StatusInternalServerError) diff --git a/web/template/viewer.html b/web/template/viewer.html index dc3d938..74c3189 100644 --- a/web/template/viewer.html +++ b/web/template/viewer.html @@ -35,7 +35,7 @@
-