mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-29 18:10:46 +02:00
Merge pull request #1150 from lnbits/lnurldeviceswitchupdate
Adds websocket checker to lnurldevice switch
This commit is contained in:
@ -487,6 +487,17 @@
|
|||||||
@click="copyText(lnurlValue, 'LNURL copied to clipboard!')"
|
@click="copyText(lnurlValue, 'LNURL copied to clipboard!')"
|
||||||
>Copy LNURL</q-btn
|
>Copy LNURL</q-btn
|
||||||
>
|
>
|
||||||
|
<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
|
||||||
@ -534,6 +545,7 @@
|
|||||||
filter: '',
|
filter: '',
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
lnurlValue: '',
|
lnurlValue: '',
|
||||||
|
websocketMessage: '',
|
||||||
switches: 0,
|
switches: 0,
|
||||||
lnurldeviceLinks: [],
|
lnurldeviceLinks: [],
|
||||||
lnurldeviceLinksObj: [],
|
lnurldeviceLinksObj: [],
|
||||||
@ -622,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, {
|
||||||
@ -631,11 +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.lnurlValueFetch(
|
||||||
|
this.qrCodeDialog.data.switches[0][3],
|
||||||
|
this.qrCodeDialog.data.id
|
||||||
|
)
|
||||||
this.qrCodeDialog.show = true
|
this.qrCodeDialog.show = true
|
||||||
},
|
},
|
||||||
lnurlValueFetch: function (lnurl) {
|
lnurlValueFetch: function (lnurl, switchId) {
|
||||||
this.lnurlValue = lnurl
|
this.lnurlValue = lnurl
|
||||||
|
this.websocketConnector(
|
||||||
|
'wss://' + window.location.host + '/lnurldevice/ws/' + switchId
|
||||||
|
)
|
||||||
},
|
},
|
||||||
addSwitch: function () {
|
addSwitch: function () {
|
||||||
var self = this
|
var self = this
|
||||||
@ -797,6 +820,25 @@
|
|||||||
LNbits.utils.notifyApiError(error)
|
LNbits.utils.notifyApiError(error)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
websocketConnector: function (websocketUrl) {
|
||||||
|
if ('WebSocket' in window) {
|
||||||
|
self = this
|
||||||
|
var ws = new WebSocket(websocketUrl)
|
||||||
|
self.updateWsMessage('Websocket connected')
|
||||||
|
ws.onmessage = function (evt) {
|
||||||
|
var received_msg = evt.data
|
||||||
|
self.updateWsMessage('Message recieved: ' + received_msg)
|
||||||
|
}
|
||||||
|
ws.onclose = function () {
|
||||||
|
self.updateWsMessage('Connection closed')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.updateWsMessage('WebSocket NOT supported by your Browser!')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateWsMessage: function (message) {
|
||||||
|
this.websocketMessage = message
|
||||||
|
},
|
||||||
clearFormDialoglnurldevice() {
|
clearFormDialoglnurldevice() {
|
||||||
this.formDialoglnurldevice.data = {
|
this.formDialoglnurldevice.data = {
|
||||||
lnurl_toggle: false,
|
lnurl_toggle: false,
|
||||||
|
Reference in New Issue
Block a user