Skip to content
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

Cable::Server#active_connections_for and Cable::Server#subscribed_channels_for public checkup methods #86

Conversation

rmarronnier
Copy link
Contributor

From #85, this is a draft proposal PR investigating the best way for the backend to check what connection / channel are active for a given token (ie user).

The maze of different identifiers must make me oblivious to a simpler (ie more efficient than a rough #select == token) way to get the info we need.

I've added some DRY suggestions.

Right now, this is a draft, it lacks proper specs.

I'm working to add them but if you have DX / code design remarks / etc. please tell, I'm really new to this codebase (and websockets in general) !

@rmarronnier rmarronnier marked this pull request as ready for review January 6, 2024 11:51
@rmarronnier
Copy link
Contributor Author

This PR is ready for review, but :

  • I am not 100% convinced Cable need the two new public methods active_connections_for and subscribed_channels_for
    They don't exist in the ruby version (by the way, does cable-cr aim to mirror the action cable backend api ?), they might be misleading / misused when several Cable.server instances are spawn (most serious production cases ?).

That being said, writing these methods and the corresponding specs made me fix a bug (calling connection.close on a connection without channel subscriptions wasn't closing it), refactor some code and complete the server specs.

So, I won't fight for these methods as new public api if it "stalls" this PR as the rest of the code changes suggestions is more valuable IMO :-)

Comment on lines -60 to +65
return true unless Connection::CHANNELS.has_key?(connection_identifier)
if Connection::CHANNELS.has_key?(connection_identifier)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't return before closing the connection socket in the case of a connection without channel subscriptions.

@rmarronnier rmarronnier requested a review from jwoertink January 6, 2024 12:13
Copy link
Collaborator

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's a bit of refactoring going on in here, but it all looks good from what I see 👍 I left a comment, but otherwise I think this is good.

src/cable/connection.cr Outdated Show resolved Hide resolved
@rmarronnier
Copy link
Contributor Author

Looks like there's a bit of refactoring going on in here, but it all looks good from what I see 👍 I left a comment, but otherwise I think this is good.

Thanks for the review :-)

@jwoertink
Copy link
Collaborator

🤦‍♂️ Ameba!!!! lol

@jwoertink jwoertink merged commit f68b822 into cable-cr:master Jan 10, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants