From 5d14c28e0846e53d739e26dc4a033f0d6e091274 Mon Sep 17 00:00:00 2001 From: jedi Date: Sat, 20 Jan 2024 01:18:00 +0100 Subject: [PATCH] stash --- web/public/js/worker.js | 50 +++++++++++++++++++++++++++++++++++++++++ web/src/store/index.js | 0 2 files changed, 50 insertions(+) create mode 100644 web/public/js/worker.js create mode 100644 web/src/store/index.js diff --git a/web/public/js/worker.js b/web/public/js/worker.js new file mode 100644 index 0000000..19f4203 --- /dev/null +++ b/web/public/js/worker.js @@ -0,0 +1,50 @@ +let state = 0; +let ports = []; +let notify_socket; + +function tryConnect(){ + if(self.WebSocket === undefined){ + console.log("no websocket support"); + return; + } + if (!notify_socket || notify_socket.readyState !== WebSocket.OPEN) { + const scheme = location.protocol === "https:" ? "wss" : "ws"; + notify_socket = new WebSocket(scheme + '://' + location.host + '/ws/2/notify/'); + notify_socket.onopen = (e) => { + console.log("open", JSON.stringify(e)); + }; + notify_socket.onclose = (e) => { + console.log("close", JSON.stringify(e)); + setTimeout(() => { + tryConnect(); + }, 1000); + }; + notify_socket.onerror = (e) => { + console.log("error", JSON.stringify(e)); + setTimeout(() => { + tryConnect(); + }, 1000); + }; + notify_socket.onmessage = (e) => { + let data = JSON.parse(e.data); + console.log("message", data); + //this.loadEventItems() + //this.loadTickets() + } + } +} + +onconnect = function (e) { + const port = e.ports[0]; + ports.push(port); + port.onmessage = function (e) { + state = state + 1; + for (let i = 0; i < ports.length; i++) { + ports[i].postMessage({d: e.data, s: state, n: ports.length}); + } + } + port.start(); + console.log("worker connected", JSON.stringify(e)); + tryConnect(); +} + diff --git a/web/src/store/index.js b/web/src/store/index.js new file mode 100644 index 0000000..e69de29