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.pull/18/head
parent
f703d5af7f
commit
8cb78a7dd6
|
@ -190,27 +190,32 @@ async function initPlayer(usr) {
|
||||||
shaka.polyfill.installAll();
|
shaka.polyfill.installAll();
|
||||||
shakaPolyFilled = true;
|
shakaPolyFilled = true;
|
||||||
}
|
}
|
||||||
// Create a Player instance.
|
var live = JSON.parse(await makeRequest("GET", "/api/"+usr+"/config")).live;
|
||||||
const video = document.getElementById('video');
|
if(live){
|
||||||
const player = new shaka.Player(video);
|
// Create a Player instance.
|
||||||
// Listen for error events.
|
const video = document.getElementById('video');
|
||||||
player.addEventListener('error', onErrorEvent);
|
const player = new shaka.Player(video);
|
||||||
|
// Listen for error events.
|
||||||
|
player.addEventListener('error', onErrorEvent);
|
||||||
|
|
||||||
video.addEventListener('play', () => {
|
video.addEventListener('play', () => {
|
||||||
document.getElementById('playbtn').style.visibility = 'hidden';
|
document.getElementById('playbtn').style.visibility = 'hidden';
|
||||||
});
|
});
|
||||||
video.addEventListener('pause', () => {
|
video.addEventListener('pause', () => {
|
||||||
document.getElementById('playbtn').style.visibility = 'visible';
|
document.getElementById('playbtn').style.visibility = 'visible';
|
||||||
});
|
});
|
||||||
// Try to load a manifest.
|
// Try to load a manifest.
|
||||||
// This is an asynchronous process.
|
// This is an asynchronous process.
|
||||||
try {
|
try {
|
||||||
await player.load(manifestUri);
|
await player.load(manifestUri);
|
||||||
// This runs if the asynchronous load is successful.
|
// This runs if the asynchronous load is successful.
|
||||||
console.log('The video has now been loaded!');
|
console.log('The video has now been loaded!');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// onError is executed if the asynchronous load fails.
|
// onError is executed if the asynchronous load fails.
|
||||||
onError(e);
|
onError(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setTimeout(initPlayer, 5000, usr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,31 +5,37 @@
|
||||||
shakaPolyFilled = false;
|
shakaPolyFilled = false;
|
||||||
var manifestUri = document.location.protocol+'//'+document.location.host+'/live/{{ username }}/index.mpd';
|
var manifestUri = document.location.protocol+'//'+document.location.host+'/live/{{ username }}/index.mpd';
|
||||||
async function initPlayer() {
|
async function initPlayer() {
|
||||||
|
console.log('Trying to initialize player.');
|
||||||
if(!shakaPolyFilled){
|
if(!shakaPolyFilled){
|
||||||
shaka.polyfill.installAll();
|
shaka.polyfill.installAll();
|
||||||
shakaPolyFilled = true;
|
shakaPolyFilled = true;
|
||||||
}
|
}
|
||||||
// Create a Player instance.
|
var live = JSON.parse(await makeRequest("GET", "/api/{{ username }}/config")).live;
|
||||||
const video = document.getElementById('video');
|
if(live){
|
||||||
const player = new shaka.Player(video);
|
// Create a Player instance.
|
||||||
// Listen for error events.
|
const video = document.getElementById('video');
|
||||||
player.addEventListener('error', onErrorEvent);
|
const player = new shaka.Player(video);
|
||||||
|
// Listen for error events.
|
||||||
|
player.addEventListener('error', onErrorEvent);
|
||||||
|
|
||||||
video.addEventListener('play', () => {
|
video.addEventListener('play', () => {
|
||||||
document.getElementById('playbtn').style.visibility = 'hidden';
|
document.getElementById('playbtn').style.visibility = 'hidden';
|
||||||
});
|
});
|
||||||
video.addEventListener('pause', () => {
|
video.addEventListener('pause', () => {
|
||||||
document.getElementById('playbtn').style.visibility = 'visible';
|
document.getElementById('playbtn').style.visibility = 'visible';
|
||||||
});
|
});
|
||||||
// Try to load a manifest.
|
// Try to load a manifest.
|
||||||
// This is an asynchronous process.
|
// This is an asynchronous process.
|
||||||
try {
|
try {
|
||||||
await player.load(manifestUri);
|
await player.load(manifestUri);
|
||||||
// This runs if the asynchronous load is successful.
|
// This runs if the asynchronous load is successful.
|
||||||
console.log('The video has now been loaded!');
|
console.log('The video has now been loaded!');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// onError is executed if the asynchronous load fails.
|
// onError is executed if the asynchronous load fails.
|
||||||
onError(e);
|
onError(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setTimeout(initPlayer, 5000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue