Switch to shaka-player and initialize it on pageload.

Maybe todo: more testing and re-check if the stream has started after the page has already loaded
pull/8/head
knotteye 4 years ago
parent 34d6fa91df
commit 2de486da46
  1. 15
      package-lock.json
  2. 3
      package.json
  3. 14
      site/dashjs/LICENSE.md
  4. 3
      site/dashjs/dash.all.min.js
  5. 2
      site/index.html
  6. 68
      site/index.js
  7. 7
      src/http.ts
  8. 95
      templates/user.njk

15
package-lock.json generated

@ -1,6 +1,6 @@
{ {
"name": "satyr", "name": "satyr",
"version": "0.10.0", "version": "0.10.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -634,6 +634,11 @@
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
}, },
"eme-encryption-scheme-polyfill": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/eme-encryption-scheme-polyfill/-/eme-encryption-scheme-polyfill-2.0.1.tgz",
"integrity": "sha512-Wz+Ro1c0/2Wsx2RLFvTOO0m4LvYn+7cSnq3XOvRvLLBq8jbvUACH/zpU9s0/5+mQa5oaelkU69x+q0z/iWYrFA=="
},
"encodeurl": { "encodeurl": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
@ -1947,6 +1952,14 @@
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
}, },
"shaka-player": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/shaka-player/-/shaka-player-3.0.5.tgz",
"integrity": "sha512-LYq56q9DA7yTLBD1yQwZrMlJZOovb2yRmo0C3AsddL1J0ee+U4BXr1QZd5amtpBvl8fOiLgkW/12UuChMR764A==",
"requires": {
"eme-encryption-scheme-polyfill": "^2.0.1"
}
},
"signal-exit": { "signal-exit": {
"version": "3.0.3", "version": "3.0.3",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz",

@ -38,7 +38,8 @@
"socket.io": "^2.3.0", "socket.io": "^2.3.0",
"strftime": "^0.10.0", "strftime": "^0.10.0",
"ts-node": "^8.5.4", "ts-node": "^8.5.4",
"typescript": "^3.6.3" "typescript": "^3.6.3",
"shaka-player": "^3.0.5"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^12.12.67" "@types/node": "^12.12.67"

@ -1,14 +0,0 @@
# dash.js BSD License Agreement
The copyright in this software is being made available under the BSD License, included below. This software may be subject to other third party and contributor rights, including patent rights, and no such rights are granted under this license.
**Copyright (c) 2015, Dash Industry Forum.
**All rights reserved.**
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of the Dash Industry Forum nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
**THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.**

File diff suppressed because one or more lines are too long

@ -6,7 +6,7 @@
<script src="/nunjucks-slim.js"></script> <script src="/nunjucks-slim.js"></script>
<script src="/templates.js"></script> <script src="/templates.js"></script>
<script src="/dashjs/dash.all.min.js"></script> <script src="/shaka-player.compiled.js"></script>
<script> <script>
nunjucks.configure({ autoescape: true }); nunjucks.configure({ autoescape: true });

@ -82,7 +82,7 @@ async function render(path, s){
if(!config.title){document.body.innerHTML = nunjucks.render('404.njk', context); break;} if(!config.title){document.body.innerHTML = nunjucks.render('404.njk', context); break;}
document.body.innerHTML = nunjucks.render('user.njk', Object.assign({about: config.about, title: config.title, username: config.username}, context)); document.body.innerHTML = nunjucks.render('user.njk', Object.assign({about: config.about, title: config.title, username: config.username}, context));
modifyLinks(); modifyLinks();
startVideo(); initPlayer(usr);
break; break;
case (path.match(/^\/vods\/.+\/manage\/?$/) || {}).input: // /vods/:user/manage case (path.match(/^\/vods\/.+\/manage\/?$/) || {}).input: // /vods/:user/manage
var usr = path.substring(6, (path.length - 7)); var usr = path.substring(6, (path.length - 7));
@ -179,41 +179,41 @@ function internalLink(path){
return false; return false;
} }
//start dash.js function sleep(ms) {
async function startVideo(){ return new Promise(resolve => setTimeout(resolve, ms));
//var url = "/live/{{username}}/index.mpd"; }
//var player = dashjs.MediaPlayer().create();
//player.initialize(document.querySelector("#videoPlayer"), url, true);
//console.log('called startvideo');
while(true){
if(!document.querySelector('#videoPlayer'))
break;
if(window.location.pathname.substring(window.location.pathname.length - 1) !== '/'){ var shakaPolyFilled = false;
var url = "/api/"+window.location.pathname.substring(7)+"/config"; async function initPlayer(usr) {
console.log(url) var manifestUri = document.location.protocol+'//'+document.location.host+'/live/'+usr+'/index.mpd';
var xhr = JSON.parse(await makeRequest("GET", url)); if(!shakaPolyFilled){
if(xhr.live){ shaka.polyfill.installAll();
var player = dashjs.MediaPlayer().create(); shakaPolyFilled = true;
player.initialize(document.querySelector("#videoPlayer"), url, true); }
break; // Create a Player instance.
} const video = document.getElementById('video');
} const player = new shaka.Player(video);
// Listen for error events.
player.addEventListener('error', onErrorEvent);
else{ // Try to load a manifest.
var url = "/api/"+window.location.pathname.substring(7, window.location.pathname.length - 1)+"/config"; // This is an asynchronous process.
console.log(url) try {
var xhr = JSON.parse(await makeRequest("GET", url)); await player.load(manifestUri);
if(xhr.live){ // This runs if the asynchronous load is successful.
var player = dashjs.MediaPlayer().create(); console.log('The video has now been loaded!');
player.initialize(document.querySelector("#videoPlayer"), url, true); } catch (e) {
break; // onError is executed if the asynchronous load fails.
} onError(e);
} }
await sleep(60000);
}
} }
function sleep(ms) { function onErrorEvent(event) {
return new Promise(resolve => setTimeout(resolve, ms)); // Extract the shaka.util.Error object from the event.
onError(event.detail);
}
function onError(error) {
// Log the error.
console.error('Error code', error.code, 'object', error);
} }

@ -59,6 +59,13 @@ async function init(){
await initAPI(); await initAPI();
//static files if nothing else matches //static files if nothing else matches
app.use(express.static(config['http']['directory'])); app.use(express.static(config['http']['directory']));
//Fake static files
app.get('/shaka-player.compiled.js', (req, res) => {
res.sendFile(process.cwd()+'/node_modules/shaka-player/dist/shaka-player.compiled.js');
});
app.get('/shaka-player.compiled.map', (req, res) => {
res.sendFile(process.cwd()+'/node_modules/shaka-player/dist/shaka-player.compiled.map');
});
//client-side site routes //client-side site routes
if(!config['http']['server_side_render']) if(!config['http']['server_side_render'])
await initFE(); await initFE();

@ -1,47 +1,44 @@
{% extends "base.njk" %} {% extends "base.njk" %}
{% block head %} {% block head %}
<!--<script src="/videojs/video.min.js"></script> <script src="/shaka-player.compiled.js"></script>
<link rel="stylesheet" type="text/css" href="/videojs/video-js.min.css">--> <script>
<script src="/dashjs/dash.all.min.js"></script> shakaPolyFilled = false;
<script> const manifestUri = document.location.protocol+'//'+document.location.host+'/live/{{ username }}/index.mpd';
async function startVideo(){ async function initPlayer() {
//var url = "/live/{{username}}/index.mpd"; if(!shakaPolyFilled){
//var player = dashjs.MediaPlayer().create(); shaka.polyfill.installAll();
//player.initialize(document.querySelector("#videoPlayer"), url, true); shakaPolyFilled = true;
//console.log('called startvideo'); }
while(true){ // Create a Player instance.
if(!document.querySelector('#videoPlayer')) const video = document.getElementById('video');
break; const player = new shaka.Player(video);
// Listen for error events.
player.addEventListener('error', onErrorEvent);
if(window.location.pathname.substring(window.location.pathname.length - 1) !== '/'){ // Try to load a manifest.
var url = "/api/"+window.location.pathname.substring(7)+"/config"; // This is an asynchronous process.
console.log(url) try {
var xhr = JSON.parse(await makeRequest("GET", url)); await player.load(manifestUri);
if(xhr.live){ // This runs if the asynchronous load is successful.
var player = dashjs.MediaPlayer().create(); console.log('The video has now been loaded!');
player.initialize(document.querySelector("#videoPlayer"), url, true); } catch (e) {
break; // onError is executed if the asynchronous load fails.
} onError(e);
} }
}
else{ function onErrorEvent(event) {
var url = "/api/"+window.location.pathname.substring(7, window.location.pathname.length - 1)+"/config"; // Extract the shaka.util.Error object from the event.
console.log(url) onError(event.detail);
var xhr = JSON.parse(await makeRequest("GET", url));
if(xhr.live){
var player = dashjs.MediaPlayer().create();
player.initialize(document.querySelector("#videoPlayer"), url, true);
break;
}
}
await sleep(60000);
}
} }
function sleep(ms) { function onError(error) {
return new Promise(resolve => setTimeout(resolve, ms)); // Log the error.
console.error('Error code', error.code, 'object', error);
} }
</script>
document.addEventListener('DOMContentLoaded', initPlayer);
</script>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<script> <script>
@ -54,12 +51,7 @@ function newPopup(url) {
<span style="float: left;font-size: large;"><a href="/live/{{ username }}/index.mpd">{{ username }}</a> | {{ title | escape }}</b></span><span style="float: right;font-size: large;"> Links | <a href="rtmp://{{ domain }}/live/{{ username }}">Watch</a> <a href="JavaScript:newPopup('/chat?room={{ username }}');">Chat</a> <a href="/vods/{{ username }}">VODs</a></span> <span style="float: left;font-size: large;"><a href="/live/{{ username }}/index.mpd">{{ username }}</a> | {{ title | escape }}</b></span><span style="float: right;font-size: large;"> Links | <a href="rtmp://{{ domain }}/live/{{ username }}">Watch</a> <a href="JavaScript:newPopup('/chat?room={{ username }}');">Chat</a> <a href="/vods/{{ username }}">VODs</a></span>
<div id="jscontainer"> <div id="jscontainer">
<div id="jschild" style="width: 70%;height: 100%;"> <div id="jschild" style="width: 70%;height: 100%;">
<!--<video controls poster="/thumbnail.jpg" class="video-js vjs-default-skin" id="live-video" style="width:100%;height:100%;min-height: 500px;"></video>--> <video id="video" style="width:100%;height:100%;width: 950px;height: 534px;background-color: rgb(0, 0, 0);" poster="/thumbnail.jpg" autoplay onclick="this.paused ? this.play() : this.pause();"></video>
<video id="videoPlayer" style="width:100%;height:100%;width: 950px;height: 534px;background-color: rgb(0, 0, 0);" poster="/thumbnail.jpg" autoplay muted></video>
<!--this spits errors fucking constantly after it tries to reload a video that's already running.. I dunno if it's bad or causing problems so let's just push it to develop and wait for issues!-->
<!--it plays the stream without reloading the page tho lol-->
<script>startVideo()</script>
</div> </div>
<div id="jschild" class="webchat" style="width: 30%;height: 100%;position: relative;"> <div id="jschild" class="webchat" style="width: 30%;height: 100%;position: relative;">
<iframe src="/chat?room={{ username }}" frameborder="0" style="width: 100%;height: 100%; min-height: 534px;" allowfullscreen></iframe> <iframe src="/chat?room={{ username }}" frameborder="0" style="width: 100%;height: 100%; min-height: 534px;" allowfullscreen></iframe>
@ -68,21 +60,4 @@ function newPopup(url) {
</br> </br>
<noscript>The webclients for the stream and the chat require javascript, but feel free to use the direct links above!</br></br></noscript> <noscript>The webclients for the stream and the chat require javascript, but feel free to use the direct links above!</br></br></noscript>
{{ about | escape }} {{ about | escape }}
<!--<script>
window.HELP_IMPROVE_VIDEOJS = false;
var player = videojs('live-video', {
html: {
nativeCaptions: false,
},
});
player.ready(function() {
player.on("error", () => {
document.querySelector(".vjs-modal-dialog-content").textContent = "The stream is currently offline.";
});
player.src({
src: '/live/{{ username }}/index.mpd',
type: 'application/dash+xml'
});
})
</script>-->
{% endblock %} {% endblock %}