mirror of
https://github.com/SuperBFG7/ympd
synced 2024-09-28 14:18:40 +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() {
|
function appRoute() {
|
||||||
|
if (settingsParsed == false) {
|
||||||
|
appInitStart();
|
||||||
|
return;
|
||||||
|
}
|
||||||
var hash = decodeURI(location.hash);
|
var hash = decodeURI(location.hash);
|
||||||
var params;
|
var params;
|
||||||
if (params = hash.match(/^\#\/(\w+)\/?(\w+)?\/?(\w+)?\!((\d+)\/([^\/]+)\/(.*))$/)) {
|
if (params = hash.match(/^\#\/(\w+)\/?(\w+)?\/?(\w+)?\!((\d+)\/([^\/]+)\/(.*))$/)) {
|
||||||
@ -359,6 +363,12 @@ function appRoute() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function appInitStart() {
|
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();
|
modalAppInit.show();
|
||||||
getSettings();
|
getSettings();
|
||||||
appInitWait();
|
appInitWait();
|
||||||
@ -1049,10 +1059,6 @@ function webSocketConnect() {
|
|||||||
try {
|
try {
|
||||||
socket.onopen = function() {
|
socket.onopen = function() {
|
||||||
console.log('Websocket is connected');
|
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) {
|
socket.onmessage = function got_packet(msg) {
|
||||||
@ -1068,6 +1074,10 @@ function webSocketConnect() {
|
|||||||
switch (obj.type) {
|
switch (obj.type) {
|
||||||
case 'welcome':
|
case 'welcome':
|
||||||
websocketConnected = true;
|
websocketConnected = true;
|
||||||
|
showNotification('Connected to myMPD: ' + wsUrl, '', '', 'success');
|
||||||
|
modalConnectionError.hide();
|
||||||
|
appRoute();
|
||||||
|
sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState);
|
||||||
break;
|
break;
|
||||||
case 'update_state':
|
case 'update_state':
|
||||||
parseState(obj);
|
parseState(obj);
|
||||||
@ -1649,7 +1659,7 @@ function parseState(obj) {
|
|||||||
setCounter(obj.data.currentSongId, obj.data.totalTime, obj.data.elapsedTime);
|
setCounter(obj.data.currentSongId, obj.data.totalTime, obj.data.elapsedTime);
|
||||||
|
|
||||||
//Get current song
|
//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);
|
sendAPI({"cmd": "MPD_API_PLAYER_CURRENT_SONG"}, songChange);
|
||||||
//clear playback card if not playing
|
//clear playback card if not playing
|
||||||
if (obj.data.songPos == '-1') {
|
if (obj.data.songPos == '-1') {
|
||||||
|
Loading…
Reference in New Issue
Block a user