diff options
Diffstat (limited to 'src/zenserver/frontend/html/pages/projects.js')
| -rw-r--r-- | src/zenserver/frontend/html/pages/projects.js | 45 |
1 files changed, 7 insertions, 38 deletions
diff --git a/src/zenserver/frontend/html/pages/projects.js b/src/zenserver/frontend/html/pages/projects.js index 9c1e519d4..a3c0d1555 100644 --- a/src/zenserver/frontend/html/pages/projects.js +++ b/src/zenserver/frontend/html/pages/projects.js @@ -28,7 +28,13 @@ export class Page extends ZenPage this._render_stats(stats); } - this._connect_stats_ws(); + this.connect_stats_ws((all_stats) => { + const stats = all_stats["prj"]; + if (stats) + { + this._render_stats(stats); + } + }); // Projects list var section = this._collapsible_section("Projects"); @@ -145,43 +151,6 @@ export class Page extends ZenPage history.replaceState(null, "", url); } - _connect_stats_ws() - { - try - { - const proto = location.protocol === "https:" ? "wss:" : "ws:"; - const ws = new WebSocket(`${proto}//${location.host}/stats`); - - try { this._ws_paused = localStorage.getItem("zen-ws-paused") === "true"; } catch (e) { this._ws_paused = false; } - document.addEventListener("zen-ws-toggle", (e) => { - this._ws_paused = e.detail.paused; - }); - - ws.onmessage = (ev) => { - if (this._ws_paused) - { - return; - } - try - { - const all_stats = JSON.parse(ev.data); - const stats = all_stats["prj"]; - if (stats) - { - this._render_stats(stats); - } - } - catch (e) { /* ignore parse errors */ } - }; - - ws.onclose = () => { this._stats_ws = null; }; - ws.onerror = () => { ws.close(); }; - - this._stats_ws = ws; - } - catch (e) { /* WebSocket not available */ } - } - _render_stats(stats) { const safe = (obj, path) => path.split(".").reduce((a, b) => a && a[b], obj); |