mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 20:52:20 +00:00
Use configuration in web server
This commit is contained in:
parent
28e3b4c753
commit
121592bee5
@ -3,7 +3,7 @@
|
|||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>{{if .Path}}{{.Path}} - {{end}}SITE_NAME</title>
|
<title>{{if .Path}}{{.Path}} - {{end}}{{.Cfg.Site.Name}}</title>
|
||||||
<link rel="stylesheet" href="static/style.css">
|
<link rel="stylesheet" href="static/style.css">
|
||||||
<link rel="shortcut icon" href="static/favicon.ico">
|
<link rel="shortcut icon" href="static/favicon.ico">
|
||||||
</head>
|
</head>
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
{{define "index"}}
|
{{define "index"}}
|
||||||
<div style="max-width:720px;margin:0 auto; padding: 1rem">
|
<div style="max-width:720px;margin:0 auto; padding: 1rem">
|
||||||
<h1>SITE_NAME</h1>
|
<h1>{{.Cfg.Site.Name}}</h1>
|
||||||
<p>
|
<p>
|
||||||
SITE_NAME est un service maintenu par le
|
{{.Cfg.Site.Name}} est un service maintenu par le
|
||||||
<a href="https://crans.org/">Crans</a> permettant de diffuser
|
<a href="https://crans.org/">Crans</a> permettant de diffuser
|
||||||
un contenu vidéo. Il a pour but d'être utilisé pour diffuser
|
un contenu vidéo. Il a pour but d'être utilisé pour diffuser
|
||||||
des séminaires ou évènements.
|
des séminaires ou évènements.
|
||||||
@ -21,7 +21,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<b>Serveur :</b>
|
<b>Serveur :</b>
|
||||||
<code>rtmps://config.SITE_HOSTNAME:1935/stream</code>,
|
<code>rtmps://{{.Cfg.Site.Hostname}}:1935/stream</code>,
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<b>Clé de stream :</b>
|
<b>Clé de stream :</b>
|
||||||
@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
<p>
|
<p>
|
||||||
Votre stream sera alors disponible sur
|
Votre stream sera alors disponible sur
|
||||||
<code>https://SITE_HOSTNAME/IDENTIFIANT</code>.
|
<code>https://{{.Cfg.Site.Hostname}}/IDENTIFIANT</code>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3>Avec FFmpeg</h3>
|
<h3>Avec FFmpeg</h3>
|
||||||
@ -49,7 +49,7 @@
|
|||||||
<code>
|
<code>
|
||||||
ffmpeg -re -i mavideo.webm -vcodec libx264 -vprofile baseline
|
ffmpeg -re -i mavideo.webm -vcodec libx264 -vprofile baseline
|
||||||
-acodec aac -strict -2 -f flv
|
-acodec aac -strict -2 -f flv
|
||||||
rtmps://SITE_HOSTNAME:1935/stream/IDENTIFIANT?pass=MOT_DE_PASSE
|
rtmps://{{.Cfg.Site.Hostname}}:1935/stream/IDENTIFIANT?pass=MOT_DE_PASSE
|
||||||
</code>
|
</code>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@ -10,14 +10,14 @@
|
|||||||
<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="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"/>
|
<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>
|
</svg>
|
||||||
<code>rtmps://SITE_HOSTNAME:1935/play/{{.path}}</code>
|
<code>rtmps://{{.Cfg.Site.Hostname}}:1935/play/{{.Path}}</code>
|
||||||
<a href="#" id="chatToggle" title="Cacher/Afficher le chat">»</a>
|
<a href="#" id="chatToggle" title="Cacher/Afficher le chat">»</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Chat -->
|
<!-- Chat -->
|
||||||
<div class="col-chat" id="chatCol">
|
<div class="col-chat" id="chatCol">
|
||||||
<iframe src="https://irc.crans.org/web/?join=stream_{{.path}}&nick=viewer&password=&realname=Viewer" title="Chat"></iframe>
|
<iframe src="https://irc.crans.org/web/?join=stream_{{.Path}}&nick=viewer&password=&realname=Viewer" title="Chat"></iframe>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ player = OvenPlayer.create("player", {
|
|||||||
expandFullScreenUI: true,
|
expandFullScreenUI: true,
|
||||||
sources: [
|
sources: [
|
||||||
{
|
{
|
||||||
"file": "wss://SITE_HOSTNAME/play/{{.path}}",
|
"file": "wss://{{.Cfg.Site.Hostname}}/play/{{.Path}}",
|
||||||
"type": "webrtc",
|
"type": "webrtc",
|
||||||
"label": "WebRTC Source"
|
"label": "WebRTC Source"
|
||||||
}
|
}
|
||||||
|
30
web/web.go
30
web/web.go
@ -13,12 +13,17 @@ import (
|
|||||||
var templates = template.Must(template.ParseGlob("web/template/*.tmpl"))
|
var templates = template.Must(template.ParseGlob("web/template/*.tmpl"))
|
||||||
|
|
||||||
// Handle site index and viewer pages
|
// Handle site index and viewer pages
|
||||||
func handlerViewer(w http.ResponseWriter, r *http.Request) {
|
func viewerHandler(w http.ResponseWriter, r *http.Request, cfg *config.Config) {
|
||||||
// Remove traling slash
|
// Data for template
|
||||||
//path := r.URL.Path[1:]
|
data := struct {
|
||||||
|
Path string
|
||||||
|
Cfg *config.Config
|
||||||
|
}{Path: r.URL.Path[1:], Cfg: cfg}
|
||||||
|
|
||||||
|
// FIXME validation on path: https://golang.org/doc/articles/wiki/#tmp_11
|
||||||
|
|
||||||
// Render template
|
// Render template
|
||||||
err := templates.ExecuteTemplate(w, "base", nil)
|
err := templates.ExecuteTemplate(w, "base", data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err.Error())
|
log.Println(err.Error())
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
@ -26,7 +31,7 @@ func handlerViewer(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Auth incoming stream
|
// Auth incoming stream
|
||||||
func handleStreamAuth(w http.ResponseWriter, r *http.Request) {
|
func streamAuthHandler(w http.ResponseWriter, r *http.Request, cfg *config.Config) {
|
||||||
// FIXME POST request only with "name" and "pass"
|
// FIXME POST request only with "name" and "pass"
|
||||||
// if name or pass missing => 400 Malformed request
|
// if name or pass missing => 400 Malformed request
|
||||||
// else login in against LDAP or static users
|
// else login in against LDAP or static users
|
||||||
@ -35,7 +40,7 @@ func handleStreamAuth(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Handle static files
|
// Handle static files
|
||||||
// We do not use http.FileServer as we do not want directory listing
|
// We do not use http.FileServer as we do not want directory listing
|
||||||
func handleStatic(w http.ResponseWriter, r *http.Request) {
|
func staticHandler(w http.ResponseWriter, r *http.Request, cfg *config.Config) {
|
||||||
path := "./web/" + r.URL.Path
|
path := "./web/" + r.URL.Path
|
||||||
if f, err := os.Stat(path); err == nil && !f.IsDir() {
|
if f, err := os.Stat(path); err == nil && !f.IsDir() {
|
||||||
http.ServeFile(w, r, path)
|
http.ServeFile(w, r, path)
|
||||||
@ -44,12 +49,19 @@ func handleStatic(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Closure to pass configuration
|
||||||
|
func makeHandler(fn func(http.ResponseWriter, *http.Request, *config.Config), cfg *config.Config) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fn(w, r, cfg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ServeHTTP server
|
// ServeHTTP server
|
||||||
func ServeHTTP(cfg *config.Config) {
|
func ServeHTTP(cfg *config.Config) {
|
||||||
// Set up HTTP router and server
|
// Set up HTTP router and server
|
||||||
http.HandleFunc("/", handlerViewer)
|
http.HandleFunc("/", makeHandler(viewerHandler, cfg))
|
||||||
http.HandleFunc("/rtmp/auth", handleStreamAuth)
|
http.HandleFunc("/rtmp/auth", makeHandler(streamAuthHandler, cfg))
|
||||||
http.HandleFunc("/static/", handleStatic)
|
http.HandleFunc("/static/", makeHandler(staticHandler, cfg))
|
||||||
log.Printf("Listening on http://%s/", cfg.Site.ListenAdress)
|
log.Printf("Listening on http://%s/", cfg.Site.ListenAdress)
|
||||||
log.Fatal(http.ListenAndServe(cfg.Site.ListenAdress, nil))
|
log.Fatal(http.ListenAndServe(cfg.Site.ListenAdress, nil))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user