1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-27 11:28:51 +02:00

Restructure configuration

This commit is contained in:
Alexandre Iooss
2020-09-22 11:42:57 +02:00
parent c799a5b613
commit 5ac336393b
11 changed files with 107 additions and 104 deletions

View File

@ -3,7 +3,7 @@
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>{{if .Path}}{{.Path}} - {{end}}{{.Cfg.Site.Name}}</title>
<title>{{if .Path}}{{.Path}} - {{end}}{{.Cfg.Name}}</title>
<link rel="stylesheet" href="static/style.css">
<link rel="shortcut icon" href="static/favicon.ico">
</head>

View File

@ -1,8 +1,8 @@
{{define "index"}}
<div style="max-width:720px;margin:0 auto; padding: 1rem">
<h1>{{.Cfg.Site.Name}}</h1>
<h1>{{.Cfg.Name}}</h1>
<p>
{{.Cfg.Site.Name}} est un service maintenu par le
{{.Cfg.Name}} est un service maintenu par le
<a href="https://crans.org/">Crans</a> permettant de diffuser
un contenu vidéo. Il a pour but d'être utilisé pour diffuser
des séminaires ou évènements.
@ -21,7 +21,7 @@
<ul>
<li>
<b>Serveur :</b>
<code>rtmps://{{.Cfg.Site.Hostname}}:1935/stream</code>,
<code>rtmps://{{.Cfg.Hostname}}:1935/stream</code>,
</li>
<li>
<b>Clé de stream :</b>
@ -41,7 +41,7 @@
<p>
Votre stream sera alors disponible sur
<code>https://{{.Cfg.Site.Hostname}}/IDENTIFIANT</code>.
<code>https://{{.Cfg.Hostname}}/IDENTIFIANT</code>.
</p>
<h3>Avec FFmpeg</h3>
@ -49,7 +49,7 @@
<code>
ffmpeg -re -i mavideo.webm -vcodec libx264 -vprofile baseline
-acodec aac -strict -2 -f flv
rtmps://{{.Cfg.Site.Hostname}}:1935/stream/IDENTIFIANT?pass=MOT_DE_PASSE
rtmps://{{.Cfg.Hostname}}:1935/stream/IDENTIFIANT?pass=MOT_DE_PASSE
</code>
</p>

View File

@ -10,7 +10,7 @@
<path fill-rule="evenodd" d="M1.5 13A1.5 1.5 0 0 0 3 14.5h8a1.5 1.5 0 0 0 1.5-1.5V9a.5.5 0 0 0-1 0v4a.5.5 0 0 1-.5.5H3a.5.5 0 0 1-.5-.5V5a.5.5 0 0 1 .5-.5h4a.5.5 0 0 0 0-1H3A1.5 1.5 0 0 0 1.5 5v8zm7-11a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-1 0V2.5H9a.5.5 0 0 1-.5-.5z"/>
<path fill-rule="evenodd" d="M14.354 1.646a.5.5 0 0 1 0 .708l-8 8a.5.5 0 0 1-.708-.708l8-8a.5.5 0 0 1 .708 0z"/>
</svg>
<code>rtmps://{{.Cfg.Site.Hostname}}:1935/play/{{.Path}}</code>
<code>rtmps://{{.Cfg.Hostname}}:1935/play/{{.Path}}</code>
<a href="#" id="chatToggle" title="Cacher/Afficher le chat">»</a>
</p>
</div>
@ -43,7 +43,7 @@ player = OvenPlayer.create("player", {
expandFullScreenUI: true,
sources: [
{
"file": "wss://{{.Cfg.Site.Hostname}}/play/{{.Path}}",
"file": "wss://{{.Cfg.Hostname}}/play/{{.Path}}",
"type": "webrtc",
"label": "WebRTC Source"
}

View File

@ -6,19 +6,27 @@ import (
"net/http"
"os"
"gitlab.crans.org/nounous/ghostream/internal/config"
"gitlab.crans.org/nounous/ghostream/internal/monitoring"
)
// Options holds web package configuration
type Options struct {
ListenAddress string
Name string
Hostname string
Favicon string
WidgetURL string
}
// Preload templates
var templates = template.Must(template.ParseGlob("web/template/*.tmpl"))
// Handle site index and viewer pages
func viewerHandler(w http.ResponseWriter, r *http.Request, cfg *config.Config) {
func viewerHandler(w http.ResponseWriter, r *http.Request, cfg *Options) {
// Data for template
data := struct {
Path string
Cfg *config.Config
Cfg *Options
}{Path: r.URL.Path[1:], Cfg: cfg}
// FIXME validation on path: https://golang.org/doc/articles/wiki/#tmp_11
@ -35,7 +43,7 @@ func viewerHandler(w http.ResponseWriter, r *http.Request, cfg *config.Config) {
}
// Auth incoming stream
func streamAuthHandler(w http.ResponseWriter, r *http.Request, cfg *config.Config) {
func streamAuthHandler(w http.ResponseWriter, r *http.Request, cfg *Options) {
// FIXME POST request only with "name" and "pass"
// if name or pass missing => 400 Malformed request
// else login in against LDAP or static users
@ -44,7 +52,7 @@ func streamAuthHandler(w http.ResponseWriter, r *http.Request, cfg *config.Confi
// Handle static files
// We do not use http.FileServer as we do not want directory listing
func staticHandler(w http.ResponseWriter, r *http.Request, cfg *config.Config) {
func staticHandler(w http.ResponseWriter, r *http.Request, cfg *Options) {
path := "./web/" + r.URL.Path
if f, err := os.Stat(path); err == nil && !f.IsDir() {
http.ServeFile(w, r, path)
@ -54,19 +62,19 @@ func staticHandler(w http.ResponseWriter, r *http.Request, cfg *config.Config) {
}
// Closure to pass configuration
func makeHandler(fn func(http.ResponseWriter, *http.Request, *config.Config), cfg *config.Config) http.HandlerFunc {
func makeHandler(fn func(http.ResponseWriter, *http.Request, *Options), cfg *Options) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
fn(w, r, cfg)
}
}
// ServeHTTP server
func ServeHTTP(cfg *config.Config) {
func ServeHTTP(cfg *Options) {
// Set up HTTP router and server
mux := http.NewServeMux()
mux.HandleFunc("/", makeHandler(viewerHandler, cfg))
mux.HandleFunc("/rtmp/auth", makeHandler(streamAuthHandler, cfg))
mux.HandleFunc("/static/", makeHandler(staticHandler, cfg))
log.Printf("Listening on http://%s/", cfg.Site.ListenAddress)
log.Fatal(http.ListenAndServe(cfg.Site.ListenAddress, mux))
log.Printf("HTTP server listening on %s", cfg.ListenAddress)
log.Fatal(http.ListenAndServe(cfg.ListenAddress, mux))
}