mirror of
https://github.com/SuperBFG7/ympd
synced 2024-09-28 06:18:13 +00:00
Fix: fetch current song if state was unknown
This commit is contained in:
parent
ede86e2cea
commit
a41fc8d22e
@ -183,6 +183,10 @@ function appGoto(a,t,v,s) {
|
||||
}
|
||||
|
||||
function appRoute() {
|
||||
if (settingsParsed == false) {
|
||||
appInitStart();
|
||||
return;
|
||||
}
|
||||
var hash = decodeURI(location.hash);
|
||||
var params;
|
||||
if (params = hash.match(/^\#\/(\w+)\/?(\w+)?\/?(\w+)?\!((\d+)\/([^\/]+)\/(.*))$/)) {
|
||||
@ -359,6 +363,12 @@ function appRoute() {
|
||||
};
|
||||
|
||||
function appInitStart() {
|
||||
document.getElementsByTagName('header')[0].classList.add('hide');
|
||||
document.getElementsByTagName('main')[0].classList.add('hide');
|
||||
document.getElementsByTagName('footer')[0].classList.add('hide');
|
||||
document.getElementById('appInitSettings').classList.add('unvisible');
|
||||
document.getElementById('appInitWebsocket').classList.add('unvisible');
|
||||
document.getElementById('appInitApply').classList.add('unvisible');
|
||||
modalAppInit.show();
|
||||
getSettings();
|
||||
appInitWait();
|
||||
@ -1049,10 +1059,6 @@ function webSocketConnect() {
|
||||
try {
|
||||
socket.onopen = function() {
|
||||
console.log('Websocket is connected');
|
||||
showNotification('Connected to myMPD: ' + wsUrl, '', '', 'success');
|
||||
modalConnectionError.hide();
|
||||
appRoute();
|
||||
sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState);
|
||||
}
|
||||
|
||||
socket.onmessage = function got_packet(msg) {
|
||||
@ -1068,6 +1074,10 @@ function webSocketConnect() {
|
||||
switch (obj.type) {
|
||||
case 'welcome':
|
||||
websocketConnected = true;
|
||||
showNotification('Connected to myMPD: ' + wsUrl, '', '', 'success');
|
||||
modalConnectionError.hide();
|
||||
appRoute();
|
||||
sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState);
|
||||
break;
|
||||
case 'update_state':
|
||||
parseState(obj);
|
||||
@ -1649,7 +1659,7 @@ function parseState(obj) {
|
||||
setCounter(obj.data.currentSongId, obj.data.totalTime, obj.data.elapsedTime);
|
||||
|
||||
//Get current song
|
||||
if (lastState && lastState.data.currentSongId != obj.data.currentSongId)
|
||||
if (!lastState || lastState.data.currentSongId != obj.data.currentSongId)
|
||||
sendAPI({"cmd": "MPD_API_PLAYER_CURRENT_SONG"}, songChange);
|
||||
//clear playback card if not playing
|
||||
if (obj.data.songPos == '-1') {
|
||||
|
Loading…
Reference in New Issue
Block a user