Imgkl / EventFlux

A Dart package for efficient handling of server-sent event streams with easy connectivity and data management.
https://pub.dev/packages/eventflux
MIT License
25 stars 8 forks source link

Reconnect with new header values #27

Closed ElectricCookie closed 1 month ago

ElectricCookie commented 2 months ago

Hi! Really great project! I love the convenient API and good documentation!

Maybe I'm missing something, but the auto-reconnect will always try the old header values. Since I'm passing an access token to the endpoint this token might have already expired by the time the reconnect is triggered.

Maybe it makes sense to replace/add the body / header / url parameters to be a callback that can be re-evaluated when the re-connect occurs?

Cheers

Imgkl commented 2 months ago

Hey @ElectricCookie,

Thanks for the kind words.

The use case you just explained is completely valid and I'll add this.

Imgkl commented 1 month ago

@ElectricCookie I've released version 2.1.1, which includes the reconnectHeaders parameter in the reconnectConfig object.

I considered adding the body and URL to reconnectConfig, but that would essentially be connecting to a new endpoint rather than reconnecting to a recently disconnected one.

ElectricCookie commented 1 month ago

@Imgkl Thanks for the quick improvement! Would it be possible to make the headers (or reconnect config entirely) async? In many of my use cases I get an access token, which could require fetching a new one via a refresh token (which is an async network request).

Thanks again!

Imgkl commented 1 month ago

@ElectricCookie hmm.. I see.

Should be simple, I guess... I'll see what I can do here. Raising a new issue to track this.