Tuesday, February 26, 2019

Re: django channels help please

The development server does not display an error.
This is the same as normal operation.
However, the information is not sent to chat_message.


# chat/consumers.py
from channels.generic.websocket import AsyncWebsocketConsumer
import json

class ChatConsumer(AsyncWebsocketConsumer):
    async def connect(self):
        self.room_name = self.scope['url_route']['kwargs']['room_name']
        self.room_group_name = 'chat_%s' % self.room_name

        # Join room group
        await self.channel_layer.group_add(
            self.room_group_name,
            self.channel_name
        )

        await self.accept()

    async def disconnect(self, close_code):
        # Leave room group
        await self.channel_layer.group_discard(
            self.room_group_name,
            self.channel_name
        )

    # Receive message from WebSocket
    async def receive(self, text_data):
        text_data_json = json.loads(text_data)
        message = text_data_json['message']

        # Send message to room group
        await self.channel_layer.group_send(
            self.room_group_name,
            {
                'type': 'chat_message',
                'message': message
            }
        )

    # Receive message from room group
    async def chat_message(self, event):
        message = event['message']

        # Send message to WebSocket
        await self.send(text_data=json.dumps({
            'message': message
        }))



Thank you for your help.


2019년 2월 26일 화요일 오후 7시 2분 42초 UTC+9, 정정수 님의 말:
Hi Dear
( I use Google Translator ) 
I'm Korea devoleper,
please help,

I am developing two projects.
I saw the tutorial and created chat features for both projects.
The code for both projects is the same.  
But one of them is a problem.


[A user] creates a chat room and enters [B user].
Chatting is good so far.
However, if [B user] creates a room for another room_name
You can not chat in both rooms.

It does not pass from receive in consumers.py to chat_message.
( Chatting alone will be done immediately after [B user] creates a room. 
  The chat_room of [A user], [B user] Only two or three chats are available.)


Emphasize again, one of the projects works normally. 

 
I have not been able to fix it for a few days.......
Please help me.....ㅜ_ㅜ

Thank you.
Good day.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f49ab91c-ee52-4db1-a87c-99d5e9a11bfc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment