checkwebsocket function

This commit is contained in:
Tiago Vasconcelos 2022-12-22 11:03:23 +00:00
parent 270712e07d
commit 4ad7d915e5
3 changed files with 20 additions and 18 deletions

View file

@ -38,6 +38,7 @@
class="full-width"
dense
outlined
@click="checkWebSocket"
>
<template>
<q-btn

View file

@ -1280,6 +1280,15 @@
this.clearMessage()
},
checkWebSocket() {
if (!this.ws) return
if (this.ws.readyState === WebSocket.CLOSED) {
console.log('WebSocket CLOSED: Reopening')
this.ws = new WebSocket(
ws_scheme + location.host + '/shop/ws/' + this.customerKey
)
}
},
chatRoom(id) {
this.startChat(id)
this.orderMessages = {}
@ -1309,15 +1318,6 @@
}
ws = new WebSocket(ws_scheme + location.host + '/shop/ws/' + room_name)
function checkWebSocket(event) {
if (ws.readyState === WebSocket.CLOSED) {
console.log('WebSocket CLOSED: Reopening')
ws = new WebSocket(
ws_scheme + location.host + '/shop/ws/' + room_name
)
}
}
ws.onmessage = async event => {
let event_data = JSON.parse(event.data)

View file

@ -24,6 +24,7 @@
class="full-width"
dense
outlined
@click="checkWebSocket"
>
<template>
<q-btn
@ -387,6 +388,15 @@
await this.getMessages(this.selectedOrder)
this.startChat(this.selectedOrder)
},
checkWebSocket() {
if (!this.ws) return
if (this.ws.readyState === WebSocket.CLOSED) {
console.log('WebSocket CLOSED: Reopening')
this.ws = new WebSocket(
ws_scheme + location.host + '/shop/ws/' + this.selectedOrder
)
}
},
startChat(room_name) {
if (this.ws) {
this.ws.close()
@ -398,15 +408,6 @@
}
ws = new WebSocket(ws_scheme + location.host + '/shop/ws/' + room_name)
function checkWebSocket(event) {
if (ws.readyState === WebSocket.CLOSED) {
console.log('WebSocket CLOSED: Reopening')
ws = new WebSocket(
ws_scheme + location.host + '/shop/ws/' + room_name
)
}
}
ws.onmessage = event => {
let event_data = JSON.parse(event.data)