Merge pull request 'merge frontend-improvments' (#18) from frontend-improvments into develop

Reviewed-on: #18
pull/19/head
knotteye 2021-01-08 16:18:05 -06:00
commit 2ef1c80813
2 changed files with 52 additions and 41 deletions

View File

@ -167,7 +167,7 @@ function handleLoad() {
function modifyLinks() {
for (var ls = document.links, numLinks = ls.length, i=0; i<numLinks; i++){
if(ls[i].href.indexOf(location.protocol+'//'+location.host) !== -1) {
if(ls[i].href.indexOf(location.protocol+'//'+location.host) !== -1 && ls[i].href.match(new RegExp(/\/\w+\.\w+$/)) === null) {
//should be a regular link
ls[i].setAttribute('onclick', 'return internalLink(\"'+ls[i].href.substring((location.protocol+'//'+location.host).length)+'\")');
}
@ -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);
}
}

View File

@ -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);
}
}