joewalnes / reconnecting-websocket

A small decorator for the JavaScript WebSocket API that automatically reconnects
MIT License
4.24k stars 970 forks source link

Manipulate the URL #127

Open Tockra opened 7 months ago

Tockra commented 7 months ago

Hi folks,

I've the problem that my websocket endpoint needs authentication. The first approach was to send a Authorization header field with the bearer token like ALL my endpoints expect. But I found no websocket client for javascript providing a custom header field. So I changed to queryParameter. So my URL contains ws://<baseURL>/<path>?token=<access_token> .

Now I ran into the next problem. If I lose the connection to my websocket for longer than 5 minutes, then the access_token stored in the initial URL will be invalid. In this case the re-connect logic results in a infinite loop.

So I would like to adjust the websockets URL in case my auth.access_token changes. Is there currently a mechanism allowing that?

Otherwise I have to kill my websocket connection each 5 minutes and restore it. This would no so cool.

T