sync WS message is now kind of ping - if there's no ping from server we display error message

This commit is contained in:
azivner 2017-11-26 08:24:27 -05:00
parent 8766e9ae4a
commit 3e6acb17cc

View file

@ -152,6 +152,7 @@ ws.onmessage = function (event) {
const message = JSON.parse(event.data);
if (message.type === 'sync') {
lastPingTs = new Date().getTime();
const data = message.data;
if (data.notes_tree) {
@ -169,4 +170,12 @@ ws.onmessage = function (event) {
const changesToPushCountEl = $("#changesToPushCount");
changesToPushCountEl.html(message.changesToPushCount);
}
};
};
let lastPingTs = new Date().getTime();
setInterval(() => {
if (new Date().getTime() - lastPingTs > 5000) {
showError("No communication with server");
}
}, 3000);