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