-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ChannelConfig(AppConfig): | ||
class ChatConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'channel' | ||
name = 'chat' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import json | ||
from channels.generic.websocket import WebsocketConsumer | ||
class ChatConsumer(WebsocketConsumer): | ||
def connect(self): | ||
# accept connection | ||
self.accept() | ||
|
||
|
||
def disconnect(self, close_code): | ||
pass | ||
|
||
|
||
# receive message from WebSocket | ||
def receive(self, text_data): | ||
text_data_json = json.loads(text_data) | ||
message = text_data_json['message'] | ||
# send message to WebSocket | ||
self.send(text_data=json.dumps({'message': message})) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import re_path | ||
from . import consumers | ||
|
||
|
||
|
||
websocket_urlpatterns = [ | ||
re_path(r'ws/chat/room/(?P<course_id>\d+)/$', | ||
consumers.ChatConsumer.as_asgi()), | ||
] |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |