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 @@ +
+ Hiiii +
\ No newline at end of file diff --git a/osinaweb/osinacore/templates/index.html b/osinaweb/osinacore/templates/index.html index 0e53361c..ff9c2d12 100644 --- a/osinaweb/osinacore/templates/index.html +++ b/osinaweb/osinacore/templates/index.html @@ -361,6 +361,28 @@ + + + + diff --git a/osinaweb/osinaweb/__pycache__/routing.cpython-310.pyc b/osinaweb/osinaweb/__pycache__/routing.cpython-310.pyc index 0b533a9c..fa1236c0 100644 Binary files a/osinaweb/osinaweb/__pycache__/routing.cpython-310.pyc and b/osinaweb/osinaweb/__pycache__/routing.cpython-310.pyc differ diff --git a/osinaweb/osinaweb/routing.py b/osinaweb/osinaweb/routing.py index 98055dfd..47735a58 100644 --- a/osinaweb/osinaweb/routing.py +++ b/osinaweb/osinaweb/routing.py @@ -1,4 +1,5 @@ from support.routing import websocket_urlpatterns as support_websocket_urlpatterns from osinacore.routing import websocket_urlpatterns as osinacore_websocket_urlpatterns +from osichat.routing import websocket_urlpatterns as osichat_websocket_urlpatterns -websocket_urlpatterns = support_websocket_urlpatterns + osinacore_websocket_urlpatterns \ No newline at end of file +websocket_urlpatterns = support_websocket_urlpatterns + osinacore_websocket_urlpatterns + osichat_websocket_urlpatterns \ No newline at end of file diff --git a/osinaweb/static/.DS_Store b/osinaweb/static/.DS_Store index 350081a5..cdfc093b 100644 Binary files a/osinaweb/static/.DS_Store and b/osinaweb/static/.DS_Store differ diff --git a/osinaweb/static/images/.DS_Store b/osinaweb/static/images/.DS_Store index 6ad166fe..de94bf25 100644 Binary files a/osinaweb/static/images/.DS_Store and b/osinaweb/static/images/.DS_Store differ