work on player

This commit is contained in:
bkfox
2020-10-22 00:30:02 +02:00
parent c10a114393
commit 2a0d0b1758
50 changed files with 19630 additions and 2193 deletions

50
assets/public/live.js Normal file
View File

@ -0,0 +1,50 @@
import {setEcoTimeout} from 'public/utils';
export default class Live {
constructor({url,timeout=10,src=""}={}) {
this.url = url;
this.timeout = timeout;
this.src = src;
this.promise = null;
this.items = [];
}
get current() {
let items = this.logs && this.logs.items;
let item = items && items[items.length-1];
if(item)
item.src = this.src;
return item;
}
//-- data refreshing
drop() {
this.promise = null;
}
fetch() {
const promise = fetch(this.url).then(response =>
response.ok ? response.json()
: Promise.reject(response)
).then(data => {
this.items = data;
return this.items
})
this.promise = promise;
return promise;
}
refresh() {
const promise = this.fetch();
promise.then(data => {
if(promise != this.promise)
return [];
setEcoTimeout(() => this.refresh(), this.timeout*1000)
})
return promise
}
}