From 3e6acb17ccf2ccade6801586a955273ac78ef7bb Mon Sep 17 00:00:00 2001 From: azivner Date: Sun, 26 Nov 2017 08:24:27 -0500 Subject: [PATCH] sync WS message is now kind of ping - if there's no ping from server we display error message --- public/javascripts/init.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/public/javascripts/init.js b/public/javascripts/init.js index ceea8c2af..eeb896d52 100644 --- a/public/javascripts/init.js +++ b/public/javascripts/init.js @@ -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); } -}; \ No newline at end of file +}; + +let lastPingTs = new Date().getTime(); + +setInterval(() => { + if (new Date().getTime() - lastPingTs > 5000) { + showError("No communication with server"); + } +}, 3000); \ No newline at end of file