1
0
mirror of https://github.com/danbee/mpd-client synced 2025-03-04 08:39:09 +00:00
mpd-client/assets/js/application.js
2013-12-06 13:46:58 +00:00

36 lines
784 B
JavaScript

// Set up necessary events and startup stuff
$(document).ready(function() {
$.when(QueueSong.findAll(), Status.findOne()).then(function(queueSongs, status) {
window.mpdClient = {
status: status,
queueSongs: queueSongs,
transport: new Transport('#transport', {
status: status
}),
events: new EventSource('/api/stream'),
queue: new Queue('#queue', {
queueSongs: queueSongs,
status: status
})
};
mpdClient.events.onmessage = function(e) {
newStatus = JSON.parse(e.data);
status.attr(newStatus);
}
status.bind('change', function(event, attr, how, newVal, oldVal) {
if (attr == 'song') {
mpdClient.queueSongs.updatePlaying(oldVal, newVal);
}
});
});
});