diff --git a/osinaweb/.DS_Store b/osinaweb/.DS_Store index a91821cf..89d5581e 100644 Binary files a/osinaweb/.DS_Store and b/osinaweb/.DS_Store differ diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 4212d46b..6058a9b8 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osichat/__pycache__/consumers.cpython-310.pyc b/osinaweb/osichat/__pycache__/consumers.cpython-310.pyc new file mode 100644 index 00000000..9b2cb8d7 Binary files /dev/null and b/osinaweb/osichat/__pycache__/consumers.cpython-310.pyc differ diff --git a/osinaweb/osichat/__pycache__/routing.cpython-310.pyc b/osinaweb/osichat/__pycache__/routing.cpython-310.pyc new file mode 100644 index 00000000..a6a9cf3c Binary files /dev/null and b/osinaweb/osichat/__pycache__/routing.cpython-310.pyc differ diff --git a/osinaweb/osichat/consumers.py b/osinaweb/osichat/consumers.py new file mode 100644 index 00000000..30bf1bd5 --- /dev/null +++ b/osinaweb/osichat/consumers.py @@ -0,0 +1,40 @@ +from channels.generic.websocket import WebsocketConsumer +from .models import * +import json +from django.template.loader import render_to_string +from asgiref.sync import async_to_sync + + + +class OsitcomChatRoom(WebsocketConsumer): + def connect(self): + async_to_sync(self.channel_layer.group_add)( + 'ositcom_chat', self.channel_name + ) + self.accept() + self.send_template() + + def disconnect(self, close_code): + async_to_sync(self.channel_layer.group_discard)( + "ositcom_chat", + self.channel_name + ) + + def send_template(self): + event = { + 'type': 'send_template_handler', + } + async_to_sync(self.channel_layer.group_send)( + 'ositcom_chat', event + ) + + def send_template_handler(self, event): + context = { + + } + html = render_to_string("test.html", context=context) + self.send(text_data=json.dumps({ + 'event_type': 'chat', + 'html': html, + })) + diff --git a/osinaweb/osichat/routing.py b/osinaweb/osichat/routing.py new file mode 100644 index 00000000..cb07f4a8 --- /dev/null +++ b/osinaweb/osichat/routing.py @@ -0,0 +1,7 @@ +from django.urls import path +from .consumers import * + +websocket_urlpatterns = [ + path("ws/osichat/", OsitcomChatRoom.as_asgi()), + +] \ No newline at end of file diff --git a/osinaweb/osichat/templates/test.html b/osinaweb/osichat/templates/test.html new file mode 100644 index 00000000..28ab7384 --- /dev/null +++ b/osinaweb/osichat/templates/test.html @@ -0,0 +1,3 @@ +