Skip to content

Build your personal knowledge base with Trilium Notes

making WS connection asynchronous to not block module registration

azivner299252b650d3
diff --git a/src/public/javascripts/services/messaging.js b/src/public/javascripts/services/messaging.js
index d64921cfb2..8b3c7ba319 100644
--- a/src/public/javascripts/services/messaging.js
+++ b/src/public/javascripts/services/messaging.js
@@ -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,36 +85,38 @@ function connectWebSocket() {
return ws;
}
-const ws = connectWebSocket();
-
-let lastSyncId = glob.maxSyncIdAtLoad;
-let lastPingTs = new Date().getTime();
-let connectionBrokenNotification = null;
-
-setInterval(async () => {
- if (new Date().getTime() - lastPingTs > 30000) {
- if (!connectionBrokenNotification) {
- connectionBrokenNotification = $.notify({
- // options
- message: "Lost connection to server"
- },{
- // settings
- type: 'danger',
- delay: 100000000 // keep it until we explicitly close it
- });
+setTimeout(() => {
+ ws = connectWebSocket();
+
+ lastSyncId = glob.maxSyncIdAtLoad;
+ lastPingTs = new Date().getTime();
+ let connectionBrokenNotification = null;
+
+ setInterval(async () => {
+ if (new Date().getTime() - lastPingTs > 30000) {
+ if (!connectionBrokenNotification) {
+ connectionBrokenNotification = $.notify({
+ // options
+ message: "Lost connection to server"
+ },{
+ // settings
+ type: 'danger',
+ delay: 100000000 // keep it until we explicitly close it
+ });
+ }
}
- }
- else if (connectionBrokenNotification) {
- await connectionBrokenNotification.close();
- connectionBrokenNotification = null;
+ else if (connectionBrokenNotification) {
+ await connectionBrokenNotification.close();
+ connectionBrokenNotification = null;
- utils.showMessage("Re-connected to server");
- }
+ utils.showMessage("Re-connected to server");
+ }
- ws.send(JSON.stringify({
- type: 'ping',
- lastSyncId: lastSyncId
- }));
+ ws.send(JSON.stringify({
+ type: 'ping',
+ lastSyncId: lastSyncId
+ }));
+ }, 1000);
}, 1000);
export default {