From f5487b2185222b01795ab04edd5a890b3688efac Mon Sep 17 00:00:00 2001 From: Ben Arc Date: Wed, 14 Apr 2021 09:29:25 +0100 Subject: [PATCH] Websocket test --- .../copilot/templates/copilot/compose.html | 6 +----- lnbits/extensions/copilot/views.py | 14 +++++++------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lnbits/extensions/copilot/templates/copilot/compose.html b/lnbits/extensions/copilot/templates/copilot/compose.html index 941838bfe..b5bd89509 100644 --- a/lnbits/extensions/copilot/templates/copilot/compose.html +++ b/lnbits/extensions/copilot/templates/copilot/compose.html @@ -62,11 +62,7 @@ console.log('Starting connection to WebSocket Server') this.connection = new WebSocket( - 'wss://' + - document.domain + - ':' + - location.port + - '/ws/{{ copilot.id }}' + 'ws://' + document.domain + ':' + location.port + '/ws/{{ copilot.id }}' ) this.connection.onmessage = function (event) { diff --git a/lnbits/extensions/copilot/views.py b/lnbits/extensions/copilot/views.py index 8745b41d7..2fa9ac849 100644 --- a/lnbits/extensions/copilot/views.py +++ b/lnbits/extensions/copilot/views.py @@ -6,6 +6,12 @@ from lnbits.decorators import check_user_exists, validate_uuids from . import copilot_ext 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("/") @validate_uuids(["usr"], required=True) @check_user_exists() @@ -25,10 +31,4 @@ async def panel(copilot_id): copilot = await get_copilot(copilot_id) or abort( HTTPStatus.NOT_FOUND, "Copilot link does not exist." ) - return await render_template("copilot/panel.html", copilot=copilot) - -@copilot_ext.websocket('/ws/') -async def ws(): - while True: - data = await websocket.receive() - await websocket.send(f"echo {data}") \ No newline at end of file + return await render_template("copilot/panel.html", copilot=copilot) \ No newline at end of file