making WS connection asynchronous to not block module registration

This commit is contained in:
azivner 2018-03-25 13:08:58 -04:00
parent fddd1c278f
commit 299252b650

View file

@ -3,9 +3,14 @@
import treeService from './tree_service.js';
import noteDetailService from './note_detail.js';
import utils from './utils.js';
import recentNotes from '../dialogs/recent_notes.js';
const $changesToPushCount = $("#changes-to-push-count");
let ws;
let lastSyncId;
let lastPingTs;
function logError(message) {
console.log(utils.now(), message); // needs to be separate from .trace()
console.trace();
@ -80,13 +85,14 @@ function connectWebSocket() {
return ws;
}
const ws = connectWebSocket();
setTimeout(() => {
ws = connectWebSocket();
let lastSyncId = glob.maxSyncIdAtLoad;
let lastPingTs = new Date().getTime();
let connectionBrokenNotification = null;
lastSyncId = glob.maxSyncIdAtLoad;
lastPingTs = new Date().getTime();
let connectionBrokenNotification = null;
setInterval(async () => {
setInterval(async () => {
if (new Date().getTime() - lastPingTs > 30000) {
if (!connectionBrokenNotification) {
connectionBrokenNotification = $.notify({
@ -110,6 +116,7 @@ setInterval(async () => {
type: 'ping',
lastSyncId: lastSyncId
}));
}, 1000);
}, 1000);
export default {