Added websocket checker for switch

This commit is contained in:
ben
2022-11-26 22:46:46 +00:00
parent 988c7eb7b4
commit aa8c543325

View File

@@ -485,9 +485,19 @@
outline outline
color="grey" color="grey"
@click="copyText(lnurlValue, 'LNURL copied to clipboard!')" @click="copyText(lnurlValue, 'LNURL copied to clipboard!')"
>Copy LNURL</q-btn> >Copy LNURL</q-btn
<br /> >
{{ websocketMessage }} <q-chip
v-if="websocketMessage == 'WebSocket NOT supported by your Browser!' || websocketMessage == 'Connection closed'"
clickable
color="red"
text-color="white"
icon="error"
>{% raw %}{{ wsMessage }}{% endraw %}</q-chip
>
<q-chip v-else clickable color="green" text-color="white" icon="check"
>{% raw %}{{ wsMessage }}{% endraw %}</q-chip
>
<br /> <br />
<div class="row q-mt-lg q-gutter-sm"> <div class="row q-mt-lg q-gutter-sm">
<q-btn <q-btn
@@ -624,6 +634,11 @@
} }
} }
}, },
computed: {
wsMessage: function () {
return this.websocketMessage
}
},
methods: { methods: {
openQrCodeDialog: function (lnurldevice_id) { openQrCodeDialog: function (lnurldevice_id) {
var lnurldevice = _.findWhere(this.lnurldeviceLinks, { var lnurldevice = _.findWhere(this.lnurldeviceLinks, {
@@ -633,12 +648,17 @@
this.qrCodeDialog.data = _.clone(lnurldevice) this.qrCodeDialog.data = _.clone(lnurldevice)
this.qrCodeDialog.data.url = this.qrCodeDialog.data.url =
window.location.protocol + '//' + window.location.host window.location.protocol + '//' + window.location.host
this.lnurlValueFetch(this.qrCodeDialog.data.switches[0][3], this.qrCodeDialog.data.switches[0][0]) this.lnurlValueFetch(
this.qrCodeDialog.data.switches[0][3],
this.qrCodeDialog.data.id
)
this.qrCodeDialog.show = true this.qrCodeDialog.show = true
}, },
lnurlValueFetch: function (lnurl, switchId) { lnurlValueFetch: function (lnurl, switchId) {
this.lnurlValue = lnurl this.lnurlValue = lnurl
this.websocketConnector('wss://' + window.location.host + '/lnurldevice/ws/' + switchId) this.websocketConnector(
'wss://' + window.location.host + '/lnurldevice/ws/' + switchId
)
}, },
addSwitch: function () { addSwitch: function () {
var self = this var self = this
@@ -801,19 +821,23 @@
}) })
}, },
websocketConnector: function (websocketUrl) { websocketConnector: function (websocketUrl) {
if ("WebSocket" in window) { if ('WebSocket' in window) {
this.websocketMessage = "Websocket connected" self = this
var ws = new WebSocket(websocketUrl) var ws = new WebSocket(websocketUrl)
self.updateWsMessage('Websocket connected')
ws.onmessage = function (evt) { ws.onmessage = function (evt) {
var received_msg = evt.data var received_msg = evt.data
this.websocketMessage = "Message recieved: " + received_msg self.updateWsMessage('Message recieved: ' + received_msg)
} }
ws.onclose = function () { ws.onclose = function () {
this.websocketMessage = "Connection closed" self.updateWsMessage('Connection closed')
};
} else {
this.websocketMessage = "WebSocket NOT supported by your Browser!"
} }
} else {
self.updateWsMessage('WebSocket NOT supported by your Browser!')
}
},
updateWsMessage: function (message) {
this.websocketMessage = message
}, },
clearFormDialoglnurldevice() { clearFormDialoglnurldevice() {
this.formDialoglnurldevice.data = { this.formDialoglnurldevice.data = {