Merge branch 'stream' into 'newinfra'

Stream

See merge request nounous/ansible!80
certbot_on_virtu
erdnaxe 2020-08-27 10:36:21 +02:00
commit fff25e9b8c
10 changed files with 264 additions and 0 deletions

View File

@ -0,0 +1,4 @@
---
glob_nginx_rtmp:
uri: stream.crans.org

View File

@ -48,6 +48,7 @@ nginx:
# - {from: grafana.crans.org, to: "10.231.136.102:3000"}
# - {from: webirc.crans.org, to: "10.231.136.1:9000"}
- {from: framadate.crans.org, to: 172.16.10.109}
- {from: stream.crans.org, to: 172.16.10.118}
# - {from: mailman.crans.org, to: 10.231.136.180}
#
# # Zamok

4
hosts
View File

@ -25,6 +25,9 @@
# [test_vm]
# re2o-test.adm.crans.org
[nginx_rtmp]
fluxx.adm.crans.org
[reverseproxy]
hodaur.adm.crans.org
frontdaur.adm.crans.org
@ -81,6 +84,7 @@ gitlab-ci.adm.crans.org
hodaur.adm.crans.org
monitoring.adm.crans.org
boeing.adm.crans.org
fluxx.adm.crans.org
[ovh_physical]
sputnik.adm.crans.org

View File

@ -0,0 +1,7 @@
#!/usr/bin/env ansible-playbook
---
- hosts: nginx_rtmp
vars:
nginx_rtmp: "{{ glob_nginx_rtmp | default({}) | combine(loc_nginx_rtmp | default({})) }}"
roles:
- nginx-rtmp

View File

@ -0,0 +1,129 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Crans Stream</title>
<link href="lib/bootstrap4/css/bootstrap.min.css" rel="stylesheet">
<link href="//unpkg.com/video.js@7/dist/video-js.min.css" rel="stylesheet">
<style>
body, html {
height: 100%;
}
.video-js .vjs-big-play-button {
display: none;
}
</style>
</head>
<body class="bg-dark">
<div class="container h-100 p-3">
<div class="row align-items-center h-100">
<div class="col-12">
<video id="my-video" class="video-js embed-responsive shadow-lg rounded-sm"></video>
<p class="text-right text-white">
<a class="text-white text-decoration-none" href="#" id="linkStream">Ouvrir le flux dans une application externe</a>
<a class="text-white text-decoration-none" href="#aboutModal" data-toggle="modal">À propos</a>
</p>
</div>
</div>
</div>
<div class="modal fade" id="aboutModal" tabindex="-1">
<div class="modal-dialog-centered modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="exampleModalLabel">À propos</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>Crans Stream 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.</p>
<h4>Comment je diffuse ?</h4>
<p>Pour diffuser un contenu vous devez être adhérent Crans et être sur le campus de Cachan.</p>
<h5>Avec Open Broadcaster Software</h5>
<p>
<a href="https://obsproject.com/">Open Broadcaster Software (OBS)</a>
est une solution libre et open source de diffusion vidéo.
Pour diffuser sur cette plateforme, allez dans l'onglet « Stream (flux) » des paramètres :
</p>
<ul>
<li><b>Serveur :</b> <code>rtmp://stream.adm.crans.org/live</code>,</li>
<li><b>Clé de stream :</b> votre identifiant.</li>
</ul>
<h5>Avec FFmpeg</h5>
<p>
<code>
ffmpeg -re -i mavideo.webm -vcodec libx264 -vprofile baseline
-acodec aac -strict -2 -f flv
rtmp://stream.adm.crans.org/live/identifiant
</code>
</p>
<h4>Mentions légales</h4>
<p>
Le service de diffusion vidéo du Crans est un service d'hébergement
au sens de l'article 6, I, 2e de la loi 2004-575 du 21 juin 2004.
Conformément aux dispositions de l'article 6, II du même,
l'association Crans conserve les données de nature à permettre
l'identification des auteurs du contenu diffusé.
Ce service est hébergé par l'association Crans, au
61 Avenue du Président Wilson, 94235 Cachan Cedex, France.
</p>
<p>
<b>En cas de réclamation sur le contenu diffusé</b> de type
<code>https://stream.crans.org/identifiant</code>,
l'auteur peut être contacté par courrier à l'adresse
<code>identifiant@crans.org</code>.
La loi vous autorise à contacter directement l'hébergeur à
l'adresse suivante :
<pre>Association Crans - ENS Paris-Saclay<br/>Notification de Contenus Illicites<br/>61, Avenue du Président Wilson<br/>94235 Cachan Cedex<br/>France</pre>
Vous pouvez également envoyer directement vos réclamations par
courrier électronique à l'adresse <code>bureau[at]crans.org</code>.
</p>
</div>
</div>
</div>
</div>
<script src="lib/jquery/jquery.min.js"></script>
<script src="lib/bootstrap4/js/bootstrap.min.js"></script>
<script src="//unpkg.com/video.js@7/dist/video.min.js"></script>
<script>
// Get current stream
let streamId = window.location.pathname.split("/").pop()
if (streamId.length === 0) {
streamId = "crans" // default on crans account
}
const streamUrl = `/hls/${streamId}.m3u8`
document.getElementById("linkStream").href = streamUrl
// If stream exists, then load
const player = videojs('my-video', {
controls: true,
autoplay: true,
preload: 'auto',
muted: true,
fluid: true,
aspectRatio: '16:9'
})
fetch(streamUrl, {
method: 'HEAD',
cache: 'no-cache'
}).then((response) => {
if (response.ok) {
// Stream exists, load!
player.src({
type: 'application/x-mpegURL',
src: streamUrl
});
} else {
// Stream does not exist, alert!
player.poster('/no-stream.jpg')
}
});
</script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

View File

@ -0,0 +1,7 @@
---
- name: restart nginx
service:
name: nginx
state: restarted
become: true

View File

@ -0,0 +1,54 @@
---
- name: Install nginx with rtmp module
apt:
name:
- nginx-full
- libnginx-mod-rtmp
- libjs-bootstrap4
register: apt_result
retries: 3
until: apt_result is succeeded
become: yes
- name: Copy module and site configuration files
template:
src: "{{ item }}.j2"
dest: "/etc/{{ item }}"
loop:
- nginx/modules-available/60-rtmp.conf
- nginx/sites-available/stream
notify: restart nginx
- name: Enable NGINX site
file:
src: /etc/nginx/sites-available/stream
dest: /etc/nginx/sites-enabled/stream
state: link
notify: restart nginx
- name: Enable RTMP module
file:
src: /etc/nginx/modules-available/60-rtmp.conf
dest: /etc/nginx/modules-enabled/60-rtmp.conf
state: link
notify: restart nginx
- name: Create site folder
file:
path: /var/www/stream/hls
state: directory
- name: Copy index.html and assets
copy:
src: "{{ item }}"
dest: "/var/www/stream/{{ item }}"
loop:
- index.html
- no-stream.jpg
- name: Link javascript libs
file:
src: /usr/share/javascript
dest: /var/www/stream/lib
state: link

View File

@ -0,0 +1,18 @@
{{ ansible_header | comment }}
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
hls on;
hls_path /var/www/stream/hls/;
hls_fragment 3;
hls_playlist_length 20;
record off;
}
}
}

View File

@ -0,0 +1,40 @@
{{ ansible_header | comment }}
server {
listen 80;
listen [::]:80;
server_name {{ nginx_rtmp.uri }};
root /var/www/stream;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /hls {
# Disable cache
add_header Cache-Control no-cache;
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
}
}