work on streamer
This commit is contained in:
parent
d3f39c5ade
commit
cbfd1c1449
|
@ -19,6 +19,7 @@ export function getCsrf() {
|
|||
|
||||
|
||||
// TODO: move in another module for reuse
|
||||
// TODO: prevent duplicate simple fetch
|
||||
export default class Model {
|
||||
constructor(data, {url=null}={}) {
|
||||
this.commit(data);
|
||||
|
@ -100,7 +101,7 @@ export default class Model {
|
|||
return index == -1 ? null : this.data[attr][index];
|
||||
}
|
||||
|
||||
static updateList(list=[], old=[]) {
|
||||
static updateList(list=[], old=[], ...initArgs) {
|
||||
return list.reduce((items, data) => {
|
||||
const id = this.getId(data);
|
||||
let [index, obj] = [old.findIndex(o => o.id == id), null];
|
||||
|
@ -109,7 +110,7 @@ export default class Model {
|
|||
items.push(old[index]);
|
||||
}
|
||||
else
|
||||
items.push(new this(data))
|
||||
items.push(new this(data, ...initArgs))
|
||||
return items;
|
||||
}, [])
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ export class Streamer extends Model {
|
|||
if(!this.data)
|
||||
this.data = { id: data.id, playlists: [], queues: [] }
|
||||
|
||||
data.playlists = Playlist.updateList(data.playlists, this.playlists)
|
||||
data.queues = Queue.updateList(data.queues, this.queues)
|
||||
data.playlists = Playlist.updateList(data.playlists, this.playlists, {streamer: this})
|
||||
data.queues = Queue.updateList(data.queues, this.queues, {streamer: this})
|
||||
super.commit(data)
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,9 @@ export class Request extends Model {
|
|||
}
|
||||
|
||||
export class Source extends Model {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
constructor(data, {streamer=null, ...options}={}) {
|
||||
super(data, options);
|
||||
this.streamer = streamer;
|
||||
setInterval(() => this.tick(), 1000)
|
||||
}
|
||||
|
||||
|
@ -44,7 +45,6 @@ export class Source extends Model {
|
|||
String(seconds).padStart(2, '0');
|
||||
}
|
||||
|
||||
|
||||
sync() { return this.action('sync/', {method: 'POST'}, true); }
|
||||
skip() { return this.action('skip/', {method: 'POST'}, true); }
|
||||
restart() { return this.action('restart/', {method: 'POST'}, true); }
|
||||
|
@ -66,9 +66,10 @@ export class Source extends Model {
|
|||
commit(data) {
|
||||
if(data.air_time)
|
||||
data.air_time = new Date(data.air_time);
|
||||
Vue.set(this, 'remaining', data.remaining)
|
||||
|
||||
this.commitDate = Date.now()
|
||||
super.commit(data)
|
||||
Vue.set(this, 'remaining', data.remaining)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user