From e5bc1063cc90a7b6262146c7b5338ffff1ff9e5b Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 4 Jun 2020 07:49:13 +0200 Subject: [PATCH] fix(react-native): restrict the list of options for the WebSocket object Only 'headers' and 'localAddress' options are supported by the WebSocket implementation in React Native. The following message was printed to the console: > Unrecognized WebSocket connection option(s) `agent`, `perMessageDeflate`, `pfx`, `key`, `passphrase`, `cert`, `ca`, `ciphers`, `rejectUnauthorized`. Did you mean to put these under `headers`? Reference: https://reactnative.dev/docs/network.html#websocket-support Backported from master: https://github.com/socketio/engine.io-client/commit/2f5c948abe8fd1c0fdb010e88f96bd933a3792ea --- lib/transports/websocket.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/transports/websocket.js b/lib/transports/websocket.js index de590bc51..f9c4b7a46 100644 --- a/lib/transports/websocket.js +++ b/lib/transports/websocket.js @@ -92,19 +92,23 @@ WS.prototype.doOpen = function () { var uri = this.uri(); var protocols = this.protocols; - var opts = { - agent: this.agent, - perMessageDeflate: this.perMessageDeflate - }; - // SSL options for Node.js client - opts.pfx = this.pfx; - opts.key = this.key; - opts.passphrase = this.passphrase; - opts.cert = this.cert; - opts.ca = this.ca; - opts.ciphers = this.ciphers; - opts.rejectUnauthorized = this.rejectUnauthorized; + var opts = {}; + + if (!this.isReactNative) { + opts.agent = this.agent; + opts.perMessageDeflate = this.perMessageDeflate; + + // SSL options for Node.js client + opts.pfx = this.pfx; + opts.key = this.key; + opts.passphrase = this.passphrase; + opts.cert = this.cert; + opts.ca = this.ca; + opts.ciphers = this.ciphers; + opts.rejectUnauthorized = this.rejectUnauthorized; + } + if (this.extraHeaders) { opts.headers = this.extraHeaders; }