Skip to content

Commit 783d1fe

Browse files
committed
Add way to specify transport-specific options using transportOptions hash.
Fixes #272
1 parent 0bbd9cc commit 783d1fe

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function SockJS(url, protocols, options) {
4848
log.warn("'protocols_whitelist' is DEPRECATED. Use 'transports' instead.");
4949
}
5050
this._transportsWhitelist = options.transports;
51+
this._transportOptions = options.transportOptions || {};
5152

5253
var sessionId = options.sessionId || 8;
5354
if (typeof sessionId === 'function') {
@@ -213,8 +214,9 @@ SockJS.prototype._connect = function() {
213214
debug('using timeout', timeoutMs);
214215

215216
var transportUrl = urlUtils.addPath(this._transUrl, '/' + this._server + '/' + this._generateSessionId());
217+
var options = this._transportOptions[Transport.transportName];
216218
debug('transport url', transportUrl);
217-
var transportObj = new Transport(transportUrl, this._transUrl);
219+
var transportObj = new Transport(transportUrl, this._transUrl, options);
218220
transportObj.on('message', this._transportMessage.bind(this));
219221
transportObj.once('close', this._transportClose.bind(this));
220222
transportObj.transportName = Transport.transportName;

lib/transport/websocket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (process.env.NODE_ENV !== 'production') {
1212
debug = require('debug')('sockjs-client:websocket');
1313
}
1414

15-
function WebSocketTransport(transUrl) {
15+
function WebSocketTransport(transUrl, ignore, options) {
1616
if (!WebSocketTransport.enabled()) {
1717
throw new Error('Transport created when disabled');
1818
}
@@ -29,7 +29,7 @@ function WebSocketTransport(transUrl) {
2929
}
3030
this.url = url;
3131

32-
this.ws = new WebsocketDriver(this.url);
32+
this.ws = new WebsocketDriver(this.url, undefined, options);
3333
this.ws.onmessage = function(e) {
3434
debug('message event', e.data);
3535
self.emit('message', e.data);

0 commit comments

Comments
 (0)