I’m working on a project where we are using Django channels. We have to send a notification in the room if any of the users disconnect. To start with, each room will be limited to 2 users only. I have a utility function inside websocket_disconnect()
, to send messages to the room to notify other users. The issue, that notification is being sent for all requests even when a user is sending a message(using receive_json(), send_json()
). Here message is sent, but still the function send_external_msg_to_channel()
from websocket_disconnect()
is being triggered. I am using AsyncJsonWebsocketConsumer
. The front end uses a reconnecting-websocket package.
class CustomConsumer(AsyncJsonWebsocketConsumer):
async def websocket_disconnect(self, message):
print("disconnecting")
await send_external_msg_to_channel(self.room_name, {"type": "send_json", "event": "disconnect"})
return await super().websocket_disconnect(message)
Any kind of help with the above issue will be of great help.
Thanks in advance!