-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connection heartbeat #85
Comments
Actually, I just started to implement a test and realized that this also won't solve my issue because I was confusing |
I'm going to piggyback on this issue :
If I need to check if there are active connections with a specific token, I couldn't find a better way than : Cable.server.connections.values.any? { |connection| connection.identifier == secret_token && !connection.closed? } It gets really ugly and hackish, when checking also if a channel was subscribed to : if active_auth_connection = Cable.server.connections.values.find { |connection| connection.identifier == secret_token && !connection.closed? }
Cable.server.@channels.values.flatten.sum.any? { |channel| channel.connection.connection_identifier == active_auth_connection.connection_identifier }
else
false
end Maybe, we could benefit from public and documented class methods global helpers like : Cable::Server
def self.active_connections_for(token : String) : Array(Cable::Connection)
def self.subscribed_channels_for(token : String) : Array(Cable::Channel) wdyt? |
I like that @rmarronnier 👍 |
We have this WebSocketPinger that pings the client every 3 seconds, but there's not really a way on the backend to know that things are still alive. I have a case where when a user joins a chat, we add their ID to an array, and when they leave, we remove their ID from that array. There's an edge case though where they join on desktop, then join on mobile, then leave desktop and now their ID is no longer in the array. This is a tricky problem to solve with how our app works. What would be nice is when the ping happens, we can see they're still in chat and just re-add them to the array.
To do this, I think instead of passing the
socket
in to the pinger, we just pass the connection. The connection has access to the socket and can still send the message, but then we can also call a method on the connection likeping
. If you override this method in your connection class, you'll receive that ping on the backend too. And it shouldn't be a breaking change since the logic will all be the same.The text was updated successfully, but these errors were encountered: