Skip to content

Commit c01b9a8

Browse files
[feature] Add support for per transport options (#518)
1 parent 176d7ab commit c01b9a8

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ Exposed as `eio` in the browser standalone build.
206206
Defaults to `['polling', 'websocket']`. `Engine`
207207
always attempts to connect directly with the first one, provided the
208208
feature detection test for it passes.
209+
- `transportOptions` (`Object`): hash of options, indexed by transport name, overriding the common options for the given transport
209210
- `rememberUpgrade` (`Boolean`): defaults to false.
210211
If true and if the previous websocket connection to the server succeeded,
211212
the connection attempt will bypass the normal upgrade process and will initially

lib/socket.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function Socket (uri, opts) {
7070
this.timestampParam = opts.timestampParam || 't';
7171
this.timestampRequests = opts.timestampRequests;
7272
this.transports = opts.transports || ['polling', 'websocket'];
73+
this.transportOptions = opts.transportOptions || {};
7374
this.readyState = '';
7475
this.writeBuffer = [];
7576
this.prevBufferLen = 0;
@@ -163,35 +164,39 @@ Socket.prototype.createTransport = function (name) {
163164
// transport name
164165
query.transport = name;
165166

167+
// per-transport options
168+
var options = this.transportOptions[name] || {};
169+
166170
// session id if we already have one
167171
if (this.id) query.sid = this.id;
168172

169173
var transport = new transports[name]({
170-
agent: this.agent,
171-
hostname: this.hostname,
172-
port: this.port,
173-
secure: this.secure,
174-
path: this.path,
175174
query: query,
176-
forceJSONP: this.forceJSONP,
177-
jsonp: this.jsonp,
178-
forceBase64: this.forceBase64,
179-
enablesXDR: this.enablesXDR,
180-
timestampRequests: this.timestampRequests,
181-
timestampParam: this.timestampParam,
182-
policyPort: this.policyPort,
183175
socket: this,
184-
pfx: this.pfx,
185-
key: this.key,
186-
passphrase: this.passphrase,
187-
cert: this.cert,
188-
ca: this.ca,
189-
ciphers: this.ciphers,
190-
rejectUnauthorized: this.rejectUnauthorized,
191-
perMessageDeflate: this.perMessageDeflate,
192-
extraHeaders: this.extraHeaders,
193-
forceNode: this.forceNode,
194-
localAddress: this.localAddress
176+
agent: options.agent || this.agent,
177+
hostname: options.hostname || this.hostname,
178+
port: options.port || this.port,
179+
secure: options.secure || this.secure,
180+
path: options.path || this.path,
181+
forceJSONP: options.forceJSONP || this.forceJSONP,
182+
jsonp: options.jsonp || this.jsonp,
183+
forceBase64: options.forceBase64 || this.forceBase64,
184+
enablesXDR: options.enablesXDR || this.enablesXDR,
185+
timestampRequests: options.timestampRequests || this.timestampRequests,
186+
timestampParam: options.timestampParam || this.timestampParam,
187+
policyPort: options.policyPort || this.policyPort,
188+
pfx: options.pfx || this.pfx,
189+
key: options.key || this.key,
190+
passphrase: options.passphrase || this.passphrase,
191+
cert: options.cert || this.cert,
192+
ca: options.ca || this.ca,
193+
ciphers: options.ciphers || this.ciphers,
194+
rejectUnauthorized: options.rejectUnauthorized || this.rejectUnauthorized,
195+
perMessageDeflate: options.perMessageDeflate || this.perMessageDeflate,
196+
extraHeaders: options.extraHeaders || this.extraHeaders,
197+
forceNode: options.forceNode || this.forceNode,
198+
localAddress: options.localAddress || this.localAddress,
199+
requestTimeout: options.requestTimeout || this.requestTimeout
195200
});
196201

197202
return transport;

0 commit comments

Comments
 (0)