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

Set url parameters for reconnecting #251

Closed
tyilo opened this issue Nov 1, 2022 · 6 comments
Closed

Set url parameters for reconnecting #251

tyilo opened this issue Nov 1, 2022 · 6 comments

Comments

@tyilo
Copy link
Contributor

tyilo commented Nov 1, 2022

I need to connect a socket.io that on connection will check if a specific query parameter contains a valid JWT token (which is not expired).

During the lifetime of the client using this library, the JWT token will expire. I can retrieve a fresh token which is not expired, but I need to update the url that rust-socketio uses for reconnection, otherwise reconnection will fail.

I see two different approaches for implementing this:

  1. Add a public set_reconnect_url function to Client.
  2. Add a on_reconnect function to ClientBuilder with the signature fn(ClientBuilder) -> ClientBuilder. Before the client tries to reconnect it will use the reconnect handler (if specified) to get a modified ClientBuilder. This handler can then change the url, opening headers, auth, etc...

I have implemented option 1 in #252

@1c3t3a
Copy link
Owner

1c3t3a commented Jan 15, 2023

Ough.. I think this is really odd behavior that doesn't really sound like proper API design. Have you tried using something like HTTP 301 status codes to do redirection to different endpoint? I am not sure if I like the idea of redesigning the public interface for this "edge-casey" use case.

@tyilo
Copy link
Contributor Author

tyilo commented Jan 16, 2023

Ough.. I think this is really odd behavior that doesn't really sound like proper API design. Have you tried using something like HTTP 301 status codes to do redirection to different endpoint? I am not sure if I like the idea of redesigning the public interface for this "edge-casey" use case.

That doesn't seem to work with authentication.

Also the javascript socket.io library supports this.

@1c3t3a
Copy link
Owner

1c3t3a commented Jan 16, 2023

Can you point me to the JS implementation of this?

@tyilo
Copy link
Contributor Author

tyilo commented Jan 16, 2023

The official socket.io documentation has an example of updating the query parameters on reconnect1:

socket.io.on("reconnect_attempt", () => {
  socket.io.opts.query.x++;
});

I actually also only need the ability to change the query parameters, not the full url.

Footnotes

  1. https://socket.io/docs/v4/client-options/#query

@rageshkrishna
Copy link
Contributor

This seems to be a valid use case. I'm running into the same auth problem myself now. When a reconnect is required, I should be able to pass a new auth value. It seems like a callback for reconnect would solve this and a few other problems, like the app needing to know when a reconnect is about to happen.

@tyilo
Copy link
Contributor Author

tyilo commented Mar 8, 2024

@rageshkrishna I think you should open a new issue, as this issue has been fixed.

@tyilo tyilo closed this as completed Mar 8, 2024
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

No branches or pull requests

3 participants