-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Current implementation of receiving new chat messages is to simply have the client send an HTTP request to poll the database for new messages. This means that the user either has to manually refresh the chat window or the front-end has to periodically send these HTTP requests. This is not the best implementation, but to do it another way would require more research than we may have time for.
The best way to do it would probably be to use Django channels, which allow for other protocols than HTTP. My original idea for this implementation would be to use a websocket connection to listen on the channel for a signal (another Django feature - it can fire when a new record is saved to the database, e.g. a chat message) that lets the client know that there is a new message available. However, given my fuzzy understanding of signals and channels, I'm not sure if this would work and I can't find any good examples for how to implement it this way.
There is also a method that would require running Redis as a caching server alongside storing messages in the database. Redis would act as a "channel layer" and would allow for users to communicate directly. However, Redis (from my experience so far) has been very finnicky to set up, so it may not be worth the time.
Here are some resources that may be helpful with implementing this:
- https://channels.readthedocs.io/en/stable/index.html
- https://docs.djangoproject.com/en/3.1/topics/signals/
- https://realpython.com/caching-in-django-with-redis/
- https://channels.readthedocs.io/en/latest/topics/channel_layers.html
An in-progress branch has been created for this issue, chat-channels.