websocket reimplementation of status requests

This commit is contained in:
azivner
2017-11-25 17:43:05 -05:00
parent f433b30089
commit 992238f0b3
6 changed files with 113 additions and 20 deletions

View File

@@ -139,4 +139,31 @@ function initAjax() {
});
}
initAjax();
initAjax();
// use wss for secure messaging
const ws = new WebSocket("ws://" + location.host);
ws.onopen = function (event) {
};
ws.onmessage = function (event) {
console.log(event.data);
const message = JSON.parse(event.data);
if (message.type === 'sync') {
const data = message.data;
if (data.notes_tree) {
console.log("Reloading tree because of background changes");
noteTree.reload();
}
if (data.notes && data.notes.includes(noteEditor.getCurrentNoteId())) {
showMessage('Reloading note because background change');
noteEditor.reload();
}
}
};