new
parent
bf50732d70
commit
4c4e123897
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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,
|
||||
}))
|
||||
|
@ -0,0 +1,7 @@
|
||||
from django.urls import path
|
||||
from .consumers import *
|
||||
|
||||
websocket_urlpatterns = [
|
||||
path("ws/osichat/", OsitcomChatRoom.as_asgi()),
|
||||
|
||||
]
|
@ -0,0 +1,3 @@
|
||||
<div>
|
||||
Hiiii
|
||||
</div>
|
Binary file not shown.
@ -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
|
||||
websocket_urlpatterns = support_websocket_urlpatterns + osinacore_websocket_urlpatterns + osichat_websocket_urlpatterns
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue