Websocket test

This commit is contained in:
Ben Arc 2021-04-14 09:29:25 +01:00
parent 2ac9e75dac
commit f5487b2185
2 changed files with 8 additions and 12 deletions

View file

@ -62,11 +62,7 @@
console.log('Starting connection to WebSocket Server') console.log('Starting connection to WebSocket Server')
this.connection = new WebSocket( this.connection = new WebSocket(
'wss://' + 'ws://' + document.domain + ':' + location.port + '/ws/{{ copilot.id }}'
document.domain +
':' +
location.port +
'/ws/{{ copilot.id }}'
) )
this.connection.onmessage = function (event) { this.connection.onmessage = function (event) {

View file

@ -6,6 +6,12 @@ from lnbits.decorators import check_user_exists, validate_uuids
from . import copilot_ext from . import copilot_ext
from .crud import get_copilot from .crud import get_copilot
@copilot_ext.websocket('/ws')
async def ws():
while True:
data = await websocket.receive()
await websocket.send(f"echo {data}")
@copilot_ext.route("/") @copilot_ext.route("/")
@validate_uuids(["usr"], required=True) @validate_uuids(["usr"], required=True)
@check_user_exists() @check_user_exists()
@ -26,9 +32,3 @@ async def panel(copilot_id):
HTTPStatus.NOT_FOUND, "Copilot link does not exist." HTTPStatus.NOT_FOUND, "Copilot link does not exist."
) )
return await render_template("copilot/panel.html", copilot=copilot) return await render_template("copilot/panel.html", copilot=copilot)
@copilot_ext.websocket('/ws/<copilot_id>')
async def ws():
while True:
data = await websocket.receive()
await websocket.send(f"echo {data}")