TiddlyWebAdaptor: Avoid crashing if server sent events not available

Fixes #5663
new-json-store-area
jeremy@jermolene.com 2021-05-04 17:31:37 +01:00
rodzic cf56a17f28
commit d8ac00a108
1 zmienionych plików z 12 dodań i 9 usunięć

Wyświetl plik

@ -40,14 +40,17 @@ function debounce(callback) {
} }
function setupEvents(host) { function setupEvents(host) {
var events = new EventSource(host + "events/plugins/tiddlywiki/tiddlyweb"); if(window.EventSource) {
var debouncedSync = debounce($tw.syncer.syncFromServer.bind($tw.syncer)); var events = new EventSource(host + "events/plugins/tiddlywiki/tiddlyweb");
events.addEventListener("change",debouncedSync); var debouncedSync = debounce($tw.syncer.syncFromServer.bind($tw.syncer));
events.onerror = function() { events.addEventListener("change",debouncedSync);
events.close(); events.onerror = function() {
setTimeout(function() { events.close();
setupEvents(host); setTimeout(function() {
},$tw.syncer.errorRetryInterval); setupEvents(host);
}; },$tw.syncer.errorRetryInterval);
};
}
} }
})(); })();