2017-08-12 13:43:10 -04:00
|
|
|
|
|
|
|
|
|
|
|
var app = new Vue({
|
|
|
|
el: '#root',
|
|
|
|
data: {
|
|
|
|
config: {},
|
|
|
|
library: {},
|
|
|
|
spotify: {},
|
|
|
|
pairing: {},
|
|
|
|
pairing_req: { pin: '' },
|
2017-10-01 02:16:46 -04:00
|
|
|
libspotify: { user: '', password: '', errors: { user: '', password: '', error: '' } },
|
|
|
|
lastfm: {},
|
|
|
|
lastfm_login: { user: '', password: '', errors: { user: '', password: '', error: '' } }
|
2017-08-12 13:43:10 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
created: function () {
|
|
|
|
this.loadConfig();
|
|
|
|
this.loadLibrary();
|
|
|
|
this.loadSpotify();
|
|
|
|
this.loadPairing();
|
2017-10-01 02:16:46 -04:00
|
|
|
this.loadLastfm();
|
2017-08-12 13:43:10 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
loadConfig: function() {
|
|
|
|
axios.get('/api/config').then(response => {
|
|
|
|
this.config = response.data;
|
|
|
|
this.connect()});
|
|
|
|
},
|
|
|
|
|
|
|
|
loadLibrary: function() {
|
|
|
|
axios.get('/api/library').then(response => this.library = response.data);
|
|
|
|
},
|
|
|
|
|
|
|
|
loadSpotify: function() {
|
|
|
|
axios.get('/api/spotify').then(response => this.spotify = response.data);
|
|
|
|
},
|
|
|
|
|
|
|
|
loadPairing: function() {
|
|
|
|
axios.get('/api/pairing').then(response => this.pairing = response.data);
|
|
|
|
},
|
|
|
|
|
2017-10-01 02:16:46 -04:00
|
|
|
loadLastfm: function() {
|
|
|
|
axios.get('/api/lastfm').then(response => this.lastfm = response.data);
|
|
|
|
},
|
|
|
|
|
2017-08-12 13:43:10 -04:00
|
|
|
update: function() {
|
|
|
|
this.library.updating = true;
|
|
|
|
axios.get('/api/update').then(console.log('Library is updating'));
|
|
|
|
},
|
|
|
|
|
|
|
|
kickoffPairing: function() {
|
|
|
|
axios.post('/api/pairing', this.pairing_req).then(response => {
|
|
|
|
console.log('Kicked off pairing');
|
|
|
|
if (!this.config.websocket_port) {
|
|
|
|
this.pairing = {};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
loginLibspotify: function() {
|
|
|
|
axios.post('/api/spotify-login', this.libspotify).then(response => {
|
|
|
|
this.libspotify.user = '';
|
|
|
|
this.libspotify.password = '';
|
|
|
|
this.libspotify.errors.user = '';
|
|
|
|
this.libspotify.errors.password = '';
|
|
|
|
this.libspotify.errors.error = '';
|
|
|
|
if (!response.data.success) {
|
|
|
|
this.libspotify.errors.user = response.data.errors.user;
|
|
|
|
this.libspotify.errors.password = response.data.errors.password;
|
|
|
|
this.libspotify.errors.error = response.data.errors.error;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-10-01 02:16:46 -04:00
|
|
|
loginLastfm: function() {
|
|
|
|
axios.post('/api/lastfm-login', this.lastfm_login).then(response => {
|
|
|
|
this.lastfm_login.user = '';
|
|
|
|
this.lastfm_login.password = '';
|
|
|
|
this.lastfm_login.errors.user = '';
|
|
|
|
this.lastfm_login.errors.password = '';
|
|
|
|
this.lastfm_login.errors.error = '';
|
|
|
|
if (!response.data.success) {
|
|
|
|
this.lastfm_login.errors.user = response.data.errors.user;
|
|
|
|
this.lastfm_login.errors.password = response.data.errors.password;
|
|
|
|
this.lastfm_login.errors.error = response.data.errors.error;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
logoutLastfm: function() {
|
|
|
|
axios.get('/api/lastfm-logout', this.lastfm_login).then(response => {
|
|
|
|
if (!this.config.websocket_port) {
|
|
|
|
this.loadLastfm();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-08-12 13:43:10 -04:00
|
|
|
connect: function() {
|
|
|
|
if (this.config.websocket_port <= 0) {
|
|
|
|
console.log('Websocket disabled');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var socket = new WebSocket('ws://' + document.domain + ':' + this.config.websocket_port, 'notify');
|
|
|
|
const vm = this;
|
|
|
|
socket.onopen = function() {
|
2017-10-01 02:16:46 -04:00
|
|
|
socket.send(JSON.stringify({ notify: ['update', 'pairing', 'spotify', 'lastfm']}));
|
2017-08-12 13:43:10 -04:00
|
|
|
socket.onmessage = function(response) {
|
|
|
|
console.log(response.data); // upon message
|
|
|
|
var data = JSON.parse(response.data);
|
|
|
|
if (data.notify.includes('update')) {
|
|
|
|
vm.loadLibrary();
|
|
|
|
}
|
|
|
|
if (data.notify.includes('pairing')) {
|
|
|
|
vm.loadPairing();
|
|
|
|
}
|
|
|
|
if (data.notify.includes('spotify')) {
|
|
|
|
vm.loadSpotify();
|
|
|
|
}
|
2017-10-01 02:16:46 -04:00
|
|
|
if (data.notify.includes('lastfm')) {
|
|
|
|
vm.loadLastfm();
|
|
|
|
}
|
2017-08-12 13:43:10 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
filters: {
|
|
|
|
duration: function(seconds) {
|
|
|
|
// Display seconds as hours:minutes:seconds
|
|
|
|
|
|
|
|
var h = Math.floor(seconds / 3600);
|
|
|
|
var m = Math.floor(seconds % 3600 / 60);
|
|
|
|
var s = Math.floor(seconds % 3600 % 60);
|
|
|
|
|
|
|
|
return h + ":" + ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2);
|
|
|
|
},
|
|
|
|
|
|
|
|
join: function(array) {
|
|
|
|
return array.join(', ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|