fix(#21): add pass-thru options and URL override for WebSocket client. Update docs.

This commit is contained in:
tiagosiebler
2020-11-11 21:31:15 +00:00
parent ec6c9a40a5
commit ee9e34a2fb
2 changed files with 39 additions and 5 deletions

View File

@@ -1,5 +1,4 @@
const {EventEmitter} = require('events');
const { EventEmitter } = require('events');
const WebSocket = require('ws');
const defaultLogger = require('./logger');
@@ -35,7 +34,7 @@ module.exports = class WebsocketClient extends EventEmitter {
...options
};
this.client = new RestClient(null, null, this.options.livenet);
this.client = new RestClient(null, null, this.options.livenet, this.options.restOptions, this.options.requestOptions);
this._subscriptions = new Set();
this._connect();
@@ -65,12 +64,19 @@ module.exports = class WebsocketClient extends EventEmitter {
this.ws && this.ws.close();
}
_getWsUrl() {
if (this.options.wsUrl) {
return this.options.wsUrl;
}
return wsUrls[this.options.livenet ? 'livenet' : 'testnet'];
}
async _connect() {
try {
if (this.readyState === READY_STATE_INITIAL) this.readyState = READY_STATE_CONNECTING;
const authParams = await this._authenticate();
const url = wsUrls[this.options.livenet ? 'livenet' : 'testnet'] + authParams;
const url = this._getWsUrl() + authParams;
this.ws = new WebSocket(url);