You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First off, thanks for the work, this is a great library. Clean & Efficient.
With the recent disappearance of the .headers variable, I encountered a slight problem for which I thought I should mention some potential improvements.
Use Case (Simplified)
I need to connect to a websocket using an authentication token, which is passed in the headers of the websocket's request. When my WebsocketManager class is initialized it creates a variable for the websocket.
This variable will not connect just yet, we will first have to wait for a certain user flow(s) to complete. Once that is done, I have the correct token to initiate the connection. In the past I would do the following
This token is subject to changes, in which case the socket is disconnected (if not already done by the server), and I repeat the code shown right above to set the header of eventSocket to the latest token available and re-establish the connection.
Issue
With the latest version, this is not possible. The only alternative I've found is to create a new WebSocket instance and to init it with a brand new request which includes the latest header value. This is ok, but wasteful.
Improvements
At first, I thought I could just subclass WebSocket and implement my own helper methods to update this header, but this is not possible due to request being private.
Here are some improvements, any of which would resolve my problem:
Make request public.
Add convenience method to set a header to the request post init.
Add back support for .headers which would be parsed within createHTTPRequest().
First off, thanks for the work, this is a great library. Clean & Efficient.
With the recent disappearance of the
.headers
variable, I encountered a slight problem for which I thought I should mention some potential improvements.Use Case (Simplified)
I need to connect to a websocket using an authentication token, which is passed in the headers of the websocket's
request
. When myWebsocketManager
class is initialized it creates a variable for the websocket.This variable will not connect just yet, we will first have to wait for a certain user flow(s) to complete. Once that is done, I have the correct token to initiate the connection. In the past I would do the following
This token is subject to changes, in which case the socket is disconnected (if not already done by the server), and I repeat the code shown right above to set the header of
eventSocket
to the latest token available and re-establish the connection.Issue
With the latest version, this is not possible. The only alternative I've found is to create a new
WebSocket
instance and toinit
it with a brand new request which includes the latest header value. This is ok, but wasteful.Improvements
At first, I thought I could just subclass
WebSocket
and implement my own helper methods to update this header, but this is not possible due torequest
being private.Here are some improvements, any of which would resolve my problem:
init
..headers
which would be parsed withincreateHTTPRequest()
.Related Issues
#387
The text was updated successfully, but these errors were encountered: