djangoflow / django-df-chat

Djangoflow in-app chat server using django-channels
MIT License
0 stars 16 forks source link

Allowing users to connect to multiple rooms using a single websocket connection #17

Closed sreekanthreddybalne closed 1 year ago

sreekanthreddybalne commented 1 year ago

Intent:

Fix for Issue https://github.com/djangoflow/django-df-chat/issues/2 The current implementation of RoomConsumer allows user to connect to a single room via websocket. In order to connect to a different room, the user has to create a new websocket connection. Maintaining multiple connections is expensive. The server may exhaust the connection pool. So, there is a need to use a single connection and communicate across multiple rooms.

Also, the "is_online" field was placed on the RoomUser. This means that only the users connected to that particular room will know if a user is online. But, we should rather notify all the rooms a user is part of that the user is online.

New Implementation:

Usage:

The consuming application should change the websocket connection url to "/ws/chat". As we now send events from multiple rooms while being connected to a single websocket, you should segregate the events by room id, before displaying them in the UI.

Refactoring not related to this PR's Intent