From 8cb78a7dd6cb1adf67a5660016d4c1c5434c5876 Mon Sep 17 00:00:00 2001 From: knotteye Date: Fri, 8 Jan 2021 16:13:21 -0600 Subject: [PATCH] Add code for re-checking if a user has gone live since loading the page Also exempt static files from link rewriting in the SPA There may be more in here.. It's been a long break halfway through this commit. --- site/index.js | 45 +++++++++++++++++++++++++-------------------- templates/user.njk | 46 ++++++++++++++++++++++++++-------------------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/site/index.js b/site/index.js index 61694cc..3cb75d7 100644 --- a/site/index.js +++ b/site/index.js @@ -190,27 +190,32 @@ async function initPlayer(usr) { shaka.polyfill.installAll(); shakaPolyFilled = true; } - // Create a Player instance. - const video = document.getElementById('video'); - const player = new shaka.Player(video); - // Listen for error events. - player.addEventListener('error', onErrorEvent); + var live = JSON.parse(await makeRequest("GET", "/api/"+usr+"/config")).live; + if(live){ + // Create a Player instance. + const video = document.getElementById('video'); + const player = new shaka.Player(video); + // Listen for error events. + player.addEventListener('error', onErrorEvent); - video.addEventListener('play', () => { - document.getElementById('playbtn').style.visibility = 'hidden'; - }); - video.addEventListener('pause', () => { - document.getElementById('playbtn').style.visibility = 'visible'; - }); - // Try to load a manifest. - // This is an asynchronous process. - try { - await player.load(manifestUri); - // This runs if the asynchronous load is successful. - console.log('The video has now been loaded!'); - } catch (e) { - // onError is executed if the asynchronous load fails. - onError(e); + video.addEventListener('play', () => { + document.getElementById('playbtn').style.visibility = 'hidden'; + }); + video.addEventListener('pause', () => { + document.getElementById('playbtn').style.visibility = 'visible'; + }); + // Try to load a manifest. + // This is an asynchronous process. + try { + await player.load(manifestUri); + // This runs if the asynchronous load is successful. + console.log('The video has now been loaded!'); + } catch (e) { + // onError is executed if the asynchronous load fails. + onError(e); + } + } else { + setTimeout(initPlayer, 5000, usr); } } diff --git a/templates/user.njk b/templates/user.njk index fd7f479..f6fc56c 100644 --- a/templates/user.njk +++ b/templates/user.njk @@ -5,31 +5,37 @@ shakaPolyFilled = false; var manifestUri = document.location.protocol+'//'+document.location.host+'/live/{{ username }}/index.mpd'; async function initPlayer() { + console.log('Trying to initialize player.'); if(!shakaPolyFilled){ shaka.polyfill.installAll(); shakaPolyFilled = true; } - // Create a Player instance. - const video = document.getElementById('video'); - const player = new shaka.Player(video); - // Listen for error events. - player.addEventListener('error', onErrorEvent); + var live = JSON.parse(await makeRequest("GET", "/api/{{ username }}/config")).live; + if(live){ + // Create a Player instance. + const video = document.getElementById('video'); + const player = new shaka.Player(video); + // Listen for error events. + player.addEventListener('error', onErrorEvent); - video.addEventListener('play', () => { - document.getElementById('playbtn').style.visibility = 'hidden'; - }); - video.addEventListener('pause', () => { - document.getElementById('playbtn').style.visibility = 'visible'; - }); - // Try to load a manifest. - // This is an asynchronous process. - try { - await player.load(manifestUri); - // This runs if the asynchronous load is successful. - console.log('The video has now been loaded!'); - } catch (e) { - // onError is executed if the asynchronous load fails. - onError(e); + video.addEventListener('play', () => { + document.getElementById('playbtn').style.visibility = 'hidden'; + }); + video.addEventListener('pause', () => { + document.getElementById('playbtn').style.visibility = 'visible'; + }); + // Try to load a manifest. + // This is an asynchronous process. + try { + await player.load(manifestUri); + // This runs if the asynchronous load is successful. + console.log('The video has now been loaded!'); + } catch (e) { + // onError is executed if the asynchronous load fails. + onError(e); + } + } else { + setTimeout(initPlayer, 5000); } }