Skip to content

Commit

Permalink
fix(react-native): restrict the list of options for the WebSocket object
Browse files Browse the repository at this point in the history
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: 2f5c948
  • Loading branch information
darrachequesne committed Jun 4, 2020
1 parent f19a9e3 commit e5bc106
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lib/transports/websocket.js
Expand Up @@ -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;
}
Expand Down

0 comments on commit e5bc106

Please sign in to comment.