mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
28 lines
601 B
JavaScript
28 lines
601 B
JavaScript
var Events = can.Construct.extend({
|
|
|
|
init: function(queue, status) {
|
|
this.events = new EventSource('/api/stream')
|
|
|
|
self = this
|
|
|
|
this.events.onmessage = function(e) {
|
|
response = JSON.parse(e.data);
|
|
switch (response.type) {
|
|
case 'status':
|
|
status.attr(response.data, true);
|
|
break;
|
|
case 'queue':
|
|
queue.replace(response.data);
|
|
break;
|
|
}
|
|
}
|
|
|
|
status.bind('change', function(event, attr, how, newVal, oldVal) {
|
|
if (attr == 'song') {
|
|
queue.updatePlaying(how, newVal, oldVal);
|
|
}
|
|
});
|
|
},
|
|
|
|
});
|