fix(#21): add pass-thru options and URL override for WebSocket client. Update docs.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user