diff --git a/src/common/connection.js b/src/common/connection.js index 7836c20f..0960a3e9 100644 --- a/src/common/connection.js +++ b/src/common/connection.js @@ -15,6 +15,7 @@ function isStreamMessageType(type) { class Connection extends EventEmitter { constructor(url, options = {}) { super(); + this.setMaxListeners(Infinity); this._url = url; this._trace = options.trace; if (this._trace) { @@ -111,8 +112,10 @@ class Connection extends EventEmitter { const proxyOptions = parseURL(proxyURL); proxyOptions.secureEndpoint = (parsedURL.protocol === 'wss:'); proxyOptions.secureProxy = (proxyOptions.protocol === 'https:'); - proxyOptions.auth = proxyAuthorization; - if (trustedCertificates) { + if (proxyAuthorization !== undefined) { + proxyOptions.auth = proxyAuthorization; + } + if (trustedCertificates !== undefined) { proxyOptions.ca = trustedCertificates; } let HttpsProxyAgent; @@ -127,7 +130,11 @@ class Connection extends EventEmitter { const base64 = new Buffer(authorization).toString('base64'); options.headers = {Authorization: `Basic ${base64}`}; } - return new WebSocket(url, options); + const websocket = new WebSocket(url, options); + // we will have a listener for each outstanding request, + // so we have to raise the limit (the default is 10) + websocket.setMaxListeners(Infinity); + return websocket; } connect() {