mirror of https://github.com/SuperBFG7/ympd
Feat: add mpd disconnected alert
This commit is contained in:
parent
6113e36f93
commit
0cc3229c29
|
@ -78,6 +78,8 @@
|
|||
<noscript>
|
||||
<div class="alert alert-danger">JavaScript is disabled!</div>
|
||||
</noscript>
|
||||
<div id="alertMpdState" class="alert alert-danger hide"></div>
|
||||
<div id="alertMympdState" class="alert alert-danger hide"></div>
|
||||
|
||||
<div class="card" id="cardPlayback">
|
||||
<div class="card-header">Playback
|
||||
|
@ -639,20 +641,6 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="modal fade" id="modalConnectionError" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header bg-danger text-light">
|
||||
<h5 class="modal-title"><span class="material-icons title-icon">error</span> Connection Error</h5>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>Connection to myMPD failed. Trying to reconnect to <span id="wsUrl"></span></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="modalUpdateDB" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
/* myMPD
|
||||
(c) 2018 Juergen Mang <mail@jcgames.de>
|
||||
(c) 2018-2019 Juergen Mang <mail@jcgames.de>
|
||||
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 <div class="spinner-border spinner-border-sm"></div>');
|
||||
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});
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue