Skip to content

Commit e5bc106

Browse files
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: 2f5c948
1 parent f19a9e3 commit e5bc106

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

lib/transports/websocket.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,23 @@ WS.prototype.doOpen = function () {
9292

9393
var uri = this.uri();
9494
var protocols = this.protocols;
95-
var opts = {
96-
agent: this.agent,
97-
perMessageDeflate: this.perMessageDeflate
98-
};
9995

100-
// SSL options for Node.js client
101-
opts.pfx = this.pfx;
102-
opts.key = this.key;
103-
opts.passphrase = this.passphrase;
104-
opts.cert = this.cert;
105-
opts.ca = this.ca;
106-
opts.ciphers = this.ciphers;
107-
opts.rejectUnauthorized = this.rejectUnauthorized;
96+
var opts = {};
97+
98+
if (!this.isReactNative) {
99+
opts.agent = this.agent;
100+
opts.perMessageDeflate = this.perMessageDeflate;
101+
102+
// SSL options for Node.js client
103+
opts.pfx = this.pfx;
104+
opts.key = this.key;
105+
opts.passphrase = this.passphrase;
106+
opts.cert = this.cert;
107+
opts.ca = this.ca;
108+
opts.ciphers = this.ciphers;
109+
opts.rejectUnauthorized = this.rejectUnauthorized;
110+
}
111+
108112
if (this.extraHeaders) {
109113
opts.headers = this.extraHeaders;
110114
}

0 commit comments

Comments
 (0)