diff --git a/htdocs/js/mympd.js b/htdocs/js/mympd.js
index 26768ed..64d2e42 100644
--- a/htdocs/js/mympd.js
+++ b/htdocs/js/mympd.js
@@ -1,6 +1,6 @@
"use strict";
/* myMPD
- (c) 2018 Juergen Mang
+ (c) 2018-2019 Juergen Mang
This project's homepage is: https://github.com/jcorporation/mympd
myMPD ist fork of:
@@ -33,8 +33,8 @@ var settingsLock = false;
var settingsParsed = 'false';
var settingsNew = {};
var settings = {};
-var alertTimeout;
-var progressTimer;
+var alertTimeout = null;
+var progressTimer = null;
var deferredPrompt;
var dragEl;
var playlistEl;
@@ -99,7 +99,6 @@ domCache.badgeQueueItems = document.getElementById('badgeQueueItems');
domCache.searchstr = document.getElementById('searchstr');
domCache.searchCrumb = document.getElementById('searchCrumb');
-var modalConnectionError = new Modal(document.getElementById('modalConnectionError'), { backdrop: 'static', keyboard: false});
var modalSettings = new Modal(document.getElementById('modalSettings'));
var modalAbout = new Modal(document.getElementById('modalAbout'));
var modalSavequeue = new Modal(document.getElementById('modalSaveQueue'));
@@ -1116,15 +1115,22 @@ function webSocketConnect() {
case 'welcome':
websocketConnected = true;
showNotification('Connected to myMPD: ' + wsUrl, '', '', 'success');
- modalConnectionError.hide();
+ toggleAlert('alertMympdState', false, '');
appRoute();
sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState);
break;
case 'update_state':
parseState(obj);
break;
- case 'disconnected':
- showNotification('Lost connection to myMPD: ' + wsUrl, '', '', 'danger');
+ case 'mpd_disconnected':
+ //showNotification('Connection to MPD failed', '', '', 'danger');
+ toggleAlert('alertMpdState', true, 'Connection to MPD failed.');
+ if (progressTimer)
+ clearTimeout(progressTimer);
+ break;
+ case 'mpd_connected':
+ showNotification('Connected to MPD', '', '', 'success');
+ toggleAlert('alertMpdState', false, '');
break;
case 'update_queue':
if (app.current.app === 'Queue')
@@ -1165,7 +1171,9 @@ function webSocketConnect() {
console.log('Websocket is disconnected');
if (appInited == true) {
//Show modal only if websocket was already connected before
- modalConnectionError.show();
+ toggleAlert('alertMympdState', true, 'Websocket connection failed.');
+ if (progressTimer)
+ clearTimeout(progressTimer);
}
else {
showAppInitAlert('Websocket connection failed.');
@@ -1176,6 +1184,7 @@ function webSocketConnect() {
}
websocketTimer = setTimeout(function() {
console.log('Reconnecting websocket');
+ toggleAlert('alertMympdState', true, 'Websocket connection failed. Trying to reconnect ');
webSocketConnect();
}, 3000);
}
@@ -1196,7 +1205,6 @@ function getWsUrl() {
protocol = 'ws://';
var wsUrl = protocol + hostname + (port != '' ? ':' + port : '') + '/ws';
- document.getElementById('wsUrl').innerText = wsUrl;
return wsUrl;
}
@@ -3095,6 +3103,18 @@ function saveQueue() {
}
}
+function toggleAlert(alertBox, state, msg) {
+ var mpdState = document.getElementById(alertBox);
+ if (state == false) {
+ mpdState.innerHTML = '';
+ mpdState.classList.add('hide');
+ }
+ else {
+ mpdState.innerHTML = msg;
+ mpdState.classList.remove('hide');
+ }
+}
+
function showNotification(notificationTitle,notificationText,notificationHtml,notificationType) {
if (settings.notificationWeb == true) {
var notification = new Notification(notificationTitle, {icon: 'assets/favicon.ico', body: notificationText});
diff --git a/src/list.c b/src/list.c
index 0478a12..c50c3a7 100644
--- a/src/list.c
+++ b/src/list.c
@@ -134,8 +134,9 @@ int list_replace(struct list *l, int pos, const char *data, int value) {
current->value = value;
current->data = realloc(current->data, strlen(data) + 1);
- if (current->data)
+ if (current->data) {
strcpy(current->data, data);
+ }
return 0;
}
diff --git a/src/mpd_client.c b/src/mpd_client.c
index 623c001..8d329e1 100644
--- a/src/mpd_client.c
+++ b/src/mpd_client.c
@@ -1131,8 +1131,8 @@ static void mpd_client_idle(t_config *config, t_mpd_state *mpd_state) {
LOG_INFO() printf("MPD Connecting to %s:%ld\n", config->mpdhost, config->mpdport);
mpd_state->conn = mpd_connection_new(config->mpdhost, config->mpdport, mpd_state->timeout);
if (mpd_state->conn == NULL) {
- printf("MPD connection failed.");
- len = snprintf(buffer, MAX_SIZE, "{\"type\": \"disconnected\"}");
+ printf("ERROR: MPD connection failed.");
+ len = snprintf(buffer, MAX_SIZE, "{\"type\": \"mpd_disconnected\"}");
mpd_client_notify(buffer, len);
mpd_state->conn_state = MPD_FAILURE;
mpd_connection_free(mpd_state->conn);
@@ -1142,7 +1142,7 @@ static void mpd_client_idle(t_config *config, t_mpd_state *mpd_state) {
}
if (mpd_connection_get_error(mpd_state->conn) != MPD_ERROR_SUCCESS) {
- printf("MPD connection: %s\n", mpd_connection_get_error_message(mpd_state->conn));
+ printf("ERROR: MPD connection: %s\n", mpd_connection_get_error_message(mpd_state->conn));
len = snprintf(buffer, MAX_SIZE, "{\"type\": \"error\", \"data\": \"%s\"}", mpd_connection_get_error_message(mpd_state->conn));
mpd_client_notify(buffer, len);
mpd_state->conn_state = MPD_FAILURE;
@@ -1151,7 +1151,7 @@ static void mpd_client_idle(t_config *config, t_mpd_state *mpd_state) {
}
if (config->mpdpass && !mpd_run_password(mpd_state->conn, config->mpdpass)) {
- printf("MPD connection: %s\n", mpd_connection_get_error_message(mpd_state->conn));
+ printf("ERROR: MPD connection: %s\n", mpd_connection_get_error_message(mpd_state->conn));
len = snprintf(buffer, MAX_SIZE, "{\"type\": \"error\", \"data\": \"%s\"}", mpd_connection_get_error_message(mpd_state->conn));
mpd_client_notify(buffer, len);
mpd_state->conn_state = MPD_FAILURE;
@@ -1160,6 +1160,8 @@ static void mpd_client_idle(t_config *config, t_mpd_state *mpd_state) {
LOG_INFO() printf("MPD connected.\n");
mpd_connection_set_timeout(mpd_state->conn, mpd_state->timeout);
+ len = snprintf(buffer, MAX_SIZE, "{\"type\": \"mpd_connected\"}");
+ mpd_client_notify(buffer, len);
mpd_state->conn_state = MPD_CONNECTED;
mpd_client_mpd_features(config, mpd_state);
mpd_client_smartpls_update_all(config, mpd_state);
@@ -1169,8 +1171,8 @@ static void mpd_client_idle(t_config *config, t_mpd_state *mpd_state) {
break;
case MPD_FAILURE:
- printf("MPD connection failed.\n");
- len = snprintf(buffer, MAX_SIZE, "{\"type\": \"disconnected\"}");
+ LOG_INFO() printf("MPD connection failed.\n");
+ len = snprintf(buffer, MAX_SIZE, "{\"type\": \"mpd_disconnected\"}");
mpd_client_notify(buffer, len);
// fall through
case MPD_DISCONNECT: