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

Add support for WebSocket requestOptions #325

Closed
Deraen opened this issue Jul 10, 2018 · 1 comment
Closed

Add support for WebSocket requestOptions #325

Deraen opened this issue Jul 10, 2018 · 1 comment

Comments

@Deraen
Copy link

Deraen commented Jul 10, 2018

In Node (and React-native) the WebSocket constructor can take additional parameter which can set the HTTP request options for the initial request. This can be used to set headers etc.

https://github.com/theturtle32/WebSocket-Node/blob/master/docs/W3CWebSocket.md#constructor
https://github.com/facebook/react-native/blob/29fb2a8e90fa3811f9485d4b89d9dbcfffea93a6/Libraries/WebSocket/WebSocket.js#L97

Inconveniently W3CWebSocket and React-Native class take different parameters.

Maybe it would be best to add option to provide a function to create the WebSocket object?

Currently I'm using workaround to replace global WebSocket object:

(defonce orig-websocket (.-WebSocket goog/global))
(defonce new-websocket
  ;; Note React-native 0.49 changes headers parameters to options
  ;; and headers is property inside options.
  (set! (.-WebSocket goog/global) (fn [url & [protocols headers]]
                                    (let [headers (or headers #js {})]
                                      (gobj/set headers "X-Access-Key" config/api-access-key)
                                      (new orig-websocket url protocols headers)))))
@ptaoussanis
Copy link
Member

@Deraen Hi Juho, apologies for the long delay replying!
An option for this will be included in forthcoming v1.18 release.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants