Fix the start video function to avoid redudant calls
parent
a5c1adfffc
commit
56c4b94a80
|
@ -3,12 +3,13 @@
|
|||
<link rel="stylesheet" type="text/css" href="/styles.css">
|
||||
<link rel="stylesheet" type="text/css" href="/local.css">
|
||||
<link rel="icon" type="image/svg" href="/logo.svg">
|
||||
|
||||
<script src="/nunjucks-slim.js"></script>
|
||||
<script src="/templates.js"></script>
|
||||
<script src="/dashjs/dash.all.min.js"></script>
|
||||
|
||||
<script>
|
||||
nunjucks.configure({ autoescape: true });
|
||||
</script>
|
||||
<script>
|
||||
//should check for and refresh login tokens on pageload..
|
||||
if(document.cookie.match(/^(.*;)?\s*X-Auth-As\s*=\s*[^;]+(.*)?$/) !== null) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
|
|
@ -80,6 +80,7 @@ async function render(path){
|
|||
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));
|
||||
modifyLinks();
|
||||
startVideo();
|
||||
break;
|
||||
case (path.match(/^\/vods\/.+\/manage\/?$/) || {}).input: // /vods/:user/manage
|
||||
var usr = path.substring(6, (path.length - 7));
|
||||
|
@ -167,4 +168,43 @@ function modifyLinks() {
|
|||
function internalLink(path){
|
||||
this.render(path);
|
||||
return false;
|
||||
}
|
||||
|
||||
//start dash.js
|
||||
async function startVideo(){
|
||||
//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') === null)
|
||||
break;
|
||||
|
||||
if(window.location.pathname.substring(window.location.pathname.length - 1) !== '/'){
|
||||
var url = "/api/"+window.location.pathname.substring(7)+"/config";
|
||||
console.log(url)
|
||||
var xhr = JSON.parse(await makeRequest("GET", url));
|
||||
if(xhr.live){
|
||||
var player = dashjs.MediaPlayer().create();
|
||||
player.initialize(document.querySelector("#videoPlayer"), url, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else{
|
||||
var url = "/api/"+window.location.pathname.substring(7, window.location.pathname.length - 1)+"/config";
|
||||
console.log(url)
|
||||
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) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
|
@ -4,12 +4,43 @@
|
|||
<link rel="stylesheet" type="text/css" href="/videojs/video-js.min.css">-->
|
||||
<script src="/dashjs/dash.all.min.js"></script>
|
||||
<script>
|
||||
function startVideo(){
|
||||
var url = "/live/{{username}}/index.mpd";
|
||||
var player = dashjs.MediaPlayer().create();
|
||||
player.initialize(document.querySelector("#videoPlayer"), url, true);
|
||||
console.log('called startvideo');
|
||||
}
|
||||
async function startVideo(){
|
||||
//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') === null)
|
||||
break;
|
||||
|
||||
if(window.location.pathname.substring(window.location.pathname.length - 1) !== '/'){
|
||||
var url = "/api/"+window.location.pathname.substring(7)+"/config";
|
||||
console.log(url)
|
||||
var xhr = JSON.parse(await makeRequest("GET", url));
|
||||
if(xhr.live){
|
||||
var player = dashjs.MediaPlayer().create();
|
||||
player.initialize(document.querySelector("#videoPlayer"), url, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
else{
|
||||
var url = "/api/"+window.location.pathname.substring(7, window.location.pathname.length - 1)+"/config";
|
||||
console.log(url)
|
||||
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) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
|
@ -28,7 +59,7 @@ function newPopup(url) {
|
|||
|
||||
<!--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>window.setInterval(startVideo, 60000)</script>
|
||||
<script>startVideo()</script>
|
||||
</div>
|
||||
<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>
|
||||
|
|
Reference in New Issue