Skip to content

Commit a85e635

Browse files
committed
message type routing for WS
1 parent d53c6f4 commit a85e635

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/reactpy/asgi/middleware.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,15 @@ async def __call__(
173173
break
174174

175175
elif event["type"] == "websocket.receive" and event["text"]:
176-
queue_put_func = recv_queue.put(orjson.loads(event["text"]))
177-
await queue_put_func
176+
msg = orjson.loads(event["text"])
177+
msg_type = msg.get("type")
178+
if msg_type == "layout-event":
179+
queue_put_func = recv_queue.put(msg)
180+
await queue_put_func
181+
else:
182+
await asyncio.to_thread(
183+
_logger.warning, f"Unknown message type: {msg_type}"
184+
)
178185

179186
async def run_dispatcher(
180187
self,

tests/test_asgi/test_standalone.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
from collections.abc import MutableMapping
33

44
import pytest
5+
from asgi_tools import ResponseText
56
from asgiref.testing import ApplicationCommunicator
67
from requests import request
78

89
import reactpy
910
from reactpy import html
1011
from reactpy.asgi.standalone import ReactPy
11-
from reactpy.asgi.utils import http_response
1212
from reactpy.testing import BackendFixture, DisplayFixture, poll
1313
from reactpy.testing.common import REACTPY_TESTS_DEFAULT_TIMEOUT
1414
from reactpy.types import Connection, Location
@@ -180,7 +180,8 @@ async def custom_http_app(scope, receive, send) -> None:
180180
raise ValueError("Custom HTTP app received a non-HTTP scope")
181181

182182
rendered.current = True
183-
await http_response(send=send, method=scope["method"], message="Hello World")
183+
response = ResponseText("Hello World")
184+
await response(scope, receive, send)
184185

185186
scope = {
186187
"type": "http",

0 commit comments

Comments
 (0)