add ws
This commit is contained in:
0
chat/__init__.py
Normal file
0
chat/__init__.py
Normal file
0
chat/api.py
Normal file
0
chat/api.py
Normal file
6
chat/apps.py
Normal file
6
chat/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ChatConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'chat'
|
||||
17
chat/consumers.py
Normal file
17
chat/consumers.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import json
|
||||
|
||||
from channels.generic.websocket import WebsocketConsumer
|
||||
|
||||
|
||||
class ChatConsumer(WebsocketConsumer):
|
||||
def connect(self):
|
||||
self.accept()
|
||||
|
||||
def disconnect(self, close_code):
|
||||
pass
|
||||
|
||||
def receive(self, text_data):
|
||||
text_data_json = json.loads(text_data)
|
||||
message = text_data_json["message"]
|
||||
|
||||
self.send(text_data=json.dumps({"message": message}))
|
||||
0
chat/migrations/__init__.py
Normal file
0
chat/migrations/__init__.py
Normal file
3
chat/models.py
Normal file
3
chat/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
6
chat/url.py
Normal file
6
chat/url.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from .consumers import ChatConsumer
|
||||
|
||||
websocket_urlpatterns = [
|
||||
path("ws/chat/", ChatConsumer.as_asgi()),
|
||||
]
|
||||
Reference in New Issue
Block a user