felangel / web_socket_client

A simple WebSocket client for Dart which includes automatic reconnection logic.
https://pub.dev/packages/web_socket_client
MIT License
150 stars 30 forks source link

feat: a function to generate URI before every connecting #31

Open laeo opened 1 year ago

laeo commented 1 year ago

Description

I want to add the user authentication token as query param to URI, but the token has short lifetime, while trying reconnect after token expires, there is no way to update the token, it will stuck looping.

WebSocket(
  uri: () => "wss://localhost/?_token=xxxxx", // we can use the callback to retrieve valid token before connects.
);

Requirements

Additional Context

No.

richiehowelll commented 2 months ago

This would be helpful for me, are there any suggested alternatives to handle a situation like this?

wkok commented 4 hours ago

Plus one as I'm also in need of this. In my case the jwt token is sent in the request headers, not the Uri, but the same principle applies - if we could have a way to update the request (Uri / headers etc.) before reconnecting, that would be really helpful.