mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
32 lines
591 B
JavaScript
32 lines
591 B
JavaScript
var Server = can.Construct.extend({
|
|
|
|
init: function() {
|
|
this.eventSource = new EventSource('/api/stream')
|
|
},
|
|
|
|
onMessage: function(callback) {
|
|
this.eventSource.addEventListener('message', function(event) {
|
|
var response = JSON.parse(event.data);
|
|
callback(response);
|
|
});
|
|
},
|
|
|
|
sendCommand: function(command) {
|
|
can.ajax({
|
|
url: '/api/control/' + command,
|
|
type: 'PUT'
|
|
});
|
|
},
|
|
|
|
playSong: function(pos) {
|
|
can.ajax({
|
|
url: '/api/control/play',
|
|
data: { pos: pos },
|
|
type: 'PUT'
|
|
});
|
|
}
|
|
|
|
});
|
|
|
|
window.server = new Server();
|