Comments (10)
This only makes sense for websockets connected using session
as audience.
In that case, then yes, it could be implemented.
I could imagine to create a special list in Redis, containing all the session-id's, of connected clients. If one of those clients disconnects, that session-id disappears from the list.
Do you think such an implementation makes sense for you?
from django-websocket-redis.
You are right. Tracking the websockets by their sessions instead of users makes more sense. Saving the session-id's in a Redis list sounds like a good plan too but it only solves half of my problem, since I still need to check that list and then update the django database accordingly. How about having a WEBSOCKET_ON_CLOSE option in the settings where one can define a callback function for ws4redis to call when a websocket closes? One of the parameters of that function could be the websocket's saved session.
from django-websocket-redis.
I strongly recommend against any database stuff inside the websocket loop.
Its even dangerous to retrieve a User using the session-id, but at least, Django caches these objects.
A callback would give programmers too many hooks to ignore this rule.
But why do you need to know immediately, when the client disconnects? Isn't it enough to find out that information the next time a Django does something?
from django-websocket-redis.
I am trying to make a web-based chat app. If someone leaves the chat channel, by closing the browser and subsequently the websocket, I would like to automatically notify the other users and also update the server about who is online and who is not.
from django-websocket-redis.
@lonemc Why dont you use a long running celery task for example? It could check every few seconds for a change in the redis session-list and act accordingly, i.e. broadcasting a message to all remaining chat-users.
from django-websocket-redis.
@Morpho @lonemc The websocket loop gets notified, if the (web)socket is closed. However, this event currently is not propagated to any business logic. It could easily be done though.
from django-websocket-redis.
@Morpho Implementing a special redis session-list with the opened/active web-sockets is one possible solution, as also suggested by @jrief in his post from Mar 11. Then it will be the responsibility of the developers to periodically check that list for closed/unused sockets.
from django-websocket-redis.
Hi,
First, thanks for this project, it is of great help for mine.
I have the same need as Ionemc. Has someone already implemented this feature, or is the issue still not handled ? If so, I could give a hand, but although I am familiar with Python and already worked with Django, it is the very first time I deal with Redis, so I might not be the best one to implement properly this idea.
F.dG
from django-websocket-redis.
it is the very first time I deal with Redis, so I might not be the best one to implement properly this idea
Before starting this project, I never used Redis before. The API is quite simple, so you should be able to proceed easily.
from django-websocket-redis.
+1
from django-websocket-redis.
Related Issues (20)
- How to define {{ WEBSOCKET_URI }} with corresponding slug on front end?
- uWSGI server not working like the docs HOT 3
- 1
- WebSocket Connection refused
- Subscription not created, errors? How to debug?
- Websocket doesn't run after reloading whole site and starting uwsgi
- ws4redis slices messages HOT 1
- DWR doesn't work with overridden groups
- Switching from username to users id HOT 1
- Handle ssl connections HOT 4
- Exception: 'LimitedStream' object has no attribute 'raw' when using Django 2.1.5 HOT 7
- django-websocket-redis with gunicorn
- WebSocket opening handshake timed out in https
- ValueError: filedescriptor out of range in select() HOT 1
- Django Websocket send data HOT 1
- Each websocket connection results into a brand new socket connection to redis hence it implicitly limits the maximum number of websockets that could be established by using this library HOT 2
- Whether clustering is supported or not?
- Compatibility with Django 3.2 and new release of django-websocket-redis
- OSS License compatibility question HOT 1
- No module named 'django.utils.six'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-websocket-redis.