Giter Club home page Giter Club logo

Comments (10)

jrief avatar jrief commented on July 28, 2024

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.

lonemc avatar lonemc commented on July 28, 2024

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.

jrief avatar jrief commented on July 28, 2024

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.

lonemc avatar lonemc commented on July 28, 2024

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.

Morpho avatar Morpho commented on July 28, 2024

@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.

jrief avatar jrief commented on July 28, 2024

@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.

lonemc avatar lonemc commented on July 28, 2024

@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.

Frky avatar Frky commented on July 28, 2024

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.

jrief avatar jrief commented on July 28, 2024

@Frky

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.

domface avatar domface commented on July 28, 2024

+1

from django-websocket-redis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.