1
0
mirror of https://github.com/danbee/mpd-client synced 2025-03-04 08:39:09 +00:00
mpd-client/assets/js/constructs/events.js
2014-01-08 11:19:17 +00:00

25 lines
536 B
JavaScript

var Events = can.Construct.extend({
init: function(scope) {
this.events = new EventSource('/api/stream')
self = this
this.events.onmessage = function(e) {
response = JSON.parse(e.data);
switch (response.type) {
case 'status':
scope.attr('status').attr(response.data);
break;
case 'queue':
scope.attr('queueSongs', response.data);
break;
case 'time':
scope.attr('status.time', response.data);
break;
}
}
},
});