stash
This commit is contained in:
parent
2ece0cefd8
commit
5d14c28e08
2 changed files with 50 additions and 0 deletions
50
web/public/js/worker.js
Normal file
50
web/public/js/worker.js
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
|
0
web/src/store/index.js
Normal file
0
web/src/store/index.js
Normal file
Loading…
Reference in a new issue