This commit is contained in:
j3d1 2023-12-13 03:00:55 +01:00
parent 4b11264dfe
commit b050c4870f

View file

@ -33,7 +33,7 @@ export default {
}), }),
methods: { methods: {
...mapMutations(['removeToast', 'createToast']), ...mapMutations(['removeToast', 'createToast']),
...mapActions(['loadItems', 'loadTickets']), ...mapActions(['loadEventItems', 'loadTickets']),
openAddModal() { openAddModal() {
this.addModalOpen = true; this.addModalOpen = true;
}, },
@ -42,62 +42,62 @@ export default {
}, },
tryConnect() { tryConnect() {
if (!this.notify_socket || this.notify_socket.readyState !== WebSocket.OPEN) { if (!this.notify_socket || this.notify_socket.readyState !== WebSocket.OPEN) {
if (this.socket_toast) { //if (this.socket_toast) {
this.removeToast(this.socket_toast.key); // this.removeToast(this.socket_toast.key);
this.socket_toast = null; // this.socket_toast = null;
} //}
this.socket_toast = this.createToast({ //this.socket_toast = this.createToast({
title: "Connecting...", // title: "Connecting...",
message: "Connecting to websocket...", // message: "Connecting to websocket...",
color: "warning" // color: "warning"
}); //});
const scheme = window.location.protocol === "https:" ? "wss" : "ws"; const scheme = window.location.protocol === "https:" ? "wss" : "ws";
this.notify_socket = new WebSocket(scheme + '://' + window.location.host + '/ws/2/notify/'); this.notify_socket = new WebSocket(scheme + '://' + window.location.host + '/ws/2/notify/');
this.notify_socket.onopen = (e) => { this.notify_socket.onopen = (e) => {
if (this.socket_toast) { //if (this.socket_toast) {
this.removeToast(this.socket_toast.key); // this.removeToast(this.socket_toast.key);
this.socket_toast = null; // this.socket_toast = null;
} //}
//this.socket_toast = this.createToast({
// title: "Connection established",
// message: JSON.stringify(e),
// color: "success"
//});
console.log(e); console.log(e);
this.socket_toast = this.createToast({
title: "Connection established",
message: JSON.stringify(e),
color: "success"
});
}; };
this.notify_socket.onclose = (e) => { this.notify_socket.onclose = (e) => {
if (this.socket_toast) { //if (this.socket_toast) {
this.removeToast(this.socket_toast.key); // this.removeToast(this.socket_toast.key);
this.socket_toast = null; // this.socket_toast = null;
} //}
//this.socket_toast = this.createToast({
// title: "Connection closed",
// message: JSON.stringify(e),
// color: "danger"
//});
console.log(e); console.log(e);
this.socket_toast = this.createToast({
title: "Connection closed",
message: JSON.stringify(e),
color: "danger"
});
setTimeout(() => { setTimeout(() => {
this.tryConnect(); this.tryConnect();
}, 1000); }, 1000);
}; };
this.notify_socket.onerror = (e) => { this.notify_socket.onerror = (e) => {
if (this.socket_toast) { //if (this.socket_toast) {
this.removeToast(this.socket_toast.key); // this.removeToast(this.socket_toast.key);
this.socket_toast = null; // this.socket_toast = null;
} //}
//this.socket_toast = this.createToast({
// title: "Connection error",
// message: JSON.stringify(e),
// color: "danger"
//});
console.log(e); console.log(e);
this.socket_toast = this.createToast({
title: "Connection error",
message: JSON.stringify(e),
color: "danger"
});
setTimeout(() => { setTimeout(() => {
this.tryConnect(); this.tryConnect();
}, 1000); }, 1000);
}; };
this.notify_socket.onmessage = (e) => { this.notify_socket.onmessage = (e) => {
let data = JSON.parse(e.data); let data = JSON.parse(e.data);
//this.loadItems() this.loadEventItems()
this.loadTickets() this.loadTickets()
} }
} }