How to get the log and result of websocket async_to_sync calling

I have websocket and simply send the mesasges to channel_layer

from channels.layers import get_channel_layer
    channel_layer = get_channel_layer()
    async_to_sync(channel_layer.group_send)(
        '{}'.format(mychannelname),
        {
            "type": "chat_message",
            "message": "send you"
        }
    )

It seems works well and messages goes to client browser, however I want to know if it works well or not from server.

Is it possible or can I get the number of clients connected to channel?

My consumers.py makes channels

import json

from channels.db import database_sync_to_async
from channels.generic.websocket import AsyncWebsocketConsumer


class ChatConsumer(AsyncWebsocketConsumer):
    
    async def connect(self):

        self.room_group_name = self.scope["url_route"]["kwargs"]["room_name"]

        await self.channel_layer.group_add(
            self.room_group_name,
            self.channel_name
        )
        await self.accept()
        await self.send(text_data=json.dumps({
            'channel_name': self.channel_name
        }))
    async def disconnect(self, close_code):
        print("some disconnect")
        await self.channel_layer.group_discard(
            self.room_group_name,
            self.channel_name
        )

    async def receive(self, text_data):
        text_data_json = json.loads(text_data)
        message = text_data_json['message']
        print("receive data",text_data_json)
    
        print("channel_name:",self.channel_name)
        print("group_name:",self.room_group_name)
        if text_data_json['type'] == "register":
            self.user_id = text_data_json['message']
        print("user_id is:",self.user_name)

        #res = await self.save_message_to_db(message)
        await self.channel_layer.group_send(
            self.room_group_name,
            {
                'type': 'chat_message',
                'message': "nicelydone",
            }
        )

    async def chat_message(self, event):
        print("someone call chat_message")
        message = event['message']
        await self.send(text_data=json.dumps({
            'message': message
        }))
Вернуться на верх