File tree Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Expand file tree Collapse file tree 2 files changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -455,7 +455,7 @@ following code in ``chat/consumers.py``, replacing the old code:
455
455
456
456
# Send message to room group
457
457
async_to_sync(self .channel_layer.group_send)(
458
- self .room_group_name, {" type" : " chat_message " , " message" : message}
458
+ self .room_group_name, {" type" : " chat.message " , " message" : message}
459
459
)
460
460
461
461
# Receive message from room group
@@ -514,7 +514,9 @@ Several parts of the new ``ChatConsumer`` code deserve further explanation:
514
514
* ``async_to_sync(self.channel_layer.group_send) ``
515
515
* Sends an event to a group.
516
516
* An event has a special ``'type' `` key corresponding to the name of the method
517
- that should be invoked on consumers that receive the event.
517
+ that should be invoked on consumers that receive the event. This translation
518
+ is done by replacing ``. `` with ``_ ``, thus in this example, ``chat.message ``
519
+ calls the ``chat_message `` method.
518
520
519
521
Let's verify that the new consumer for the ``/ws/chat/ROOM_NAME/ `` path works.
520
522
To start the Channels development server, run the following command:
Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ Put the following code in ``chat/consumers.py``:
58
58
59
59
# Send message to room group
60
60
await self .channel_layer.group_send(
61
- self .room_group_name, {" type" : " chat_message " , " message" : message}
61
+ self .room_group_name, {" type" : " chat.message " , " message" : message}
62
62
)
63
63
64
64
# Receive message from room group
You can’t perform that action at this time.
0 commit comments