Skip to content

Commit 2b1afbc

Browse files
working websocket
1 parent 59b7252 commit 2b1afbc

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

manager/director/apps/sites/consumers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ async def connect(self):
3838
self.channel_name,
3939
)
4040

41+
await self.accept()
42+
await self.send(text_data=f'<p id="foo">site name: {site.name}</p>')
43+
4144
@asynccontextmanager
4245
async def close_on_error(
4346
self, error: type[BaseException] | tuple[BaseException, ...] = Exception

manager/director/asgi.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from channels.routing import ProtocolTypeRouter, URLRouter
1313
from channels.security.websocket import AllowedHostsOriginValidator
1414
from django.core.asgi import get_asgi_application
15-
from django.urls import include
15+
16+
from director.apps.sites.consumers import urlpatterns as sites_urlpatterns
1617

1718
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "director.settings")
1819

@@ -23,8 +24,6 @@
2324
application = ProtocolTypeRouter(
2425
{
2526
"http": django_asgi_app,
26-
"websocket": AllowedHostsOriginValidator(
27-
AuthMiddlewareStack(URLRouter([*include("director.apps.sites.consumers")]))
28-
),
27+
"websocket": AllowedHostsOriginValidator(AuthMiddlewareStack(URLRouter(sites_urlpatterns))),
2928
}
3029
)

manager/director/templates/sites/dashboard.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
{{ block.super }}
55

66
<script src="https://unpkg.com/htmx-ext-ws@2.0.2"
7-
integrity="sha384-vuKxTKv5TX/b3lLzDKP2U363sOAoRo5wSvzzc3LJsbaQRSBSS+3rKKHcOx5J8doU" crossorigin="anonymous"></script>
7+
integrity="sha384-932iIqjARv+Gy0+r6RTGrfCkCKS5MsF539Iqf6Vt8L4YmbnnWI2DSFoMD90bvXd0" crossorigin="anonymous"></script>
88
{% endblock head %}
99

1010
{% block main %}
11-
<h1 class="p-2 text-large">{{ site.name }}</h1>
12-
<div hx-ext="ws" ws-connect="{% url '' %}">
13-
11+
<!-- <h1 class="p-2 text-large">{{ site.name }}</h1> -->
12+
<div hx-ext="ws" ws-connect="/sites/{{ site.id }}/"
13+
class="p-2 mb-4" hx-swap-oob='true'>
14+
<p id="foo"></p>
1415
</div>
16+
{% comment %}
1517
<button htmx-post="{% url 'sites:clear' site.id %}"
1618
hx-target="{% url 'sites:clear_operations' %}"
1719
class="dt-btn-primary">
1820

1921
{% heroicon_outline "trash" stroke_width="0.8" size="24" class="mr-2" %}
2022
<p>Clear Operations</p>
2123
</button>
24+
{% endcomment %}
2225
{% endblock main %}

0 commit comments

Comments
 (0)