- commit
- 057cf18735170c515266b73f85daae5f318971b8
- parent
- f7cd1721262d72fd9292afceb37619a8184827cc
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2023-11-17 11:47
close event source on offline
Diffstat
| M | static/pad.js | 9 | ++++----- |
1 files changed, 4 insertions, 5 deletions
diff --git a/static/pad.js b/static/pad.js
@@ -111,6 +111,7 @@ document.querySelector('button').addEventListener('click', function() {
111 111
112 112 window.addEventListener('offline', function() {
113 113 el.readOnly = true;
-1 114 evtSource.close();
114 115 });
115 116
116 117 var evtSource = new EventSource(url);
@@ -118,12 +119,10 @@ evtSource.onopen = function() {
118 119 el.readOnly = false;
119 120 };
120 121 evtSource.onmessage = function(event) {
121 -1 if (!el.readOnly) {
122 -1 handleMessage(JSON.parse(event.data));
-1 122 handleMessage(JSON.parse(event.data));
123 123
124 -1 if (Math.random() < 0.05) {
125 -1 optimize(event.lastEventId);
126 -1 }
-1 124 if (Math.random() < 0.05) {
-1 125 optimize(event.lastEventId);
127 126 }
128 127 };
129 128