|
1 | 1 | """Anything used to construct a websocket endpoint""" |
2 | 2 | import asyncio |
| 3 | +import json |
3 | 4 | import logging |
4 | 5 | from typing import Any |
5 | 6 | from urllib.parse import parse_qsl |
6 | 7 |
|
7 | 8 | from channels.generic.websocket import AsyncJsonWebsocketConsumer |
8 | | -from django.urls import path |
9 | 9 | from idom.core.dispatcher import dispatch_single_view |
10 | 10 | from idom.core.layout import Layout, LayoutEvent |
11 | 11 |
|
12 | 12 | from .app_components import get_component, has_component |
13 | | -from .app_settings import IDOM_WEBSOCKET_URL |
14 | 13 |
|
15 | 14 |
|
16 | 15 | logger = logging.getLogger(__name__) |
17 | 16 |
|
18 | 17 |
|
19 | | -def django_idom_websocket_consumer_url(*args, **kwargs): |
20 | | - """Return a URL resolver for :class:`IdomAsyncWebSocketConsumer` |
21 | | -
|
22 | | - While this is relatively uncommon in most Django apps, because the URL of the |
23 | | - websocket must be defined by the setting ``IDOM_WEBSOCKET_URL``. There's no need |
24 | | - to allow users to configure the URL themselves |
25 | | - """ |
26 | | - return path( |
27 | | - IDOM_WEBSOCKET_URL + "<view_id>/", |
28 | | - IdomAsyncWebSocketConsumer.as_asgi(), |
29 | | - *args, |
30 | | - **kwargs, |
31 | | - ) |
32 | | - |
33 | | - |
34 | 18 | class IdomAsyncWebSocketConsumer(AsyncJsonWebsocketConsumer): |
35 | 19 | """Communicates with the browser to perform actions on-demand.""" |
36 | 20 |
|
@@ -59,7 +43,9 @@ async def _run_dispatch_loop(self): |
59 | 43 | return |
60 | 44 |
|
61 | 45 | component_constructor = get_component(view_id) |
62 | | - component_kwargs = dict(parse_qsl(self.scope["query_string"])) |
| 46 | + |
| 47 | + query_dict = dict(parse_qsl(self.scope["query_string"].decode())) |
| 48 | + component_kwargs = json.loads(query_dict.get("kwargs", "{}")) |
63 | 49 |
|
64 | 50 | try: |
65 | 51 | component_instance = component_constructor(**component_kwargs) |
|
0 commit comments