From cbfd1c1449bab5a11ddb2d0307d9fe195cca8349 Mon Sep 17 00:00:00 2001 From: bkfox Date: Sat, 21 Sep 2019 17:44:23 +0200 Subject: [PATCH] work on streamer --- assets/public/model.js | 5 +++-- assets/streamer/controllers.js | 13 +++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/assets/public/model.js b/assets/public/model.js index b77aef3..324c7a0 100644 --- a/assets/public/model.js +++ b/assets/public/model.js @@ -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; }, []) } diff --git a/assets/streamer/controllers.js b/assets/streamer/controllers.js index ce003a7..7e47ddf 100644 --- a/assets/streamer/controllers.js +++ b/assets/streamer/controllers.js @@ -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) } }