Skip to content

Commit ce2208c

Browse files
committed
Add transports to socket client
1 parent 74a14a0 commit ce2208c

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ typings/
6464

6565
# End of https://www.gitignore.io/api/node
6666
test.js
67+
68+
.idea

lib/Socket.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Socket {
2323
this.historicalBookData = {};
2424
this.candlesData = {};
2525
this.boardData = {};
26+
this.transports = ['websocket', 'polling'];
2627
}
2728

2829
_deepClone(data) {
@@ -45,6 +46,7 @@ class Socket {
4546
reconnectionAttempts: 1,
4647
reconnectionDelay: 1000,
4748
reconnectionDelayMax: 15000,
49+
transports: this.transports,
4850
});
4951
}
5052

@@ -434,19 +436,26 @@ class Socket {
434436
});
435437
}
436438

437-
connect() {
439+
connect(...transports) {
440+
if (!_.isEmpty(transports)) {
441+
this.transports = transports.filter(
442+
(transport) => transport === 'polling' || transport === 'websocket',
443+
);
444+
if (_.isEmpty(this.transports)) {
445+
return Promise.reject(new Error('Invalid transports'));
446+
}
447+
}
438448
this.socketClient = socket(this.urlWorker, {
439449
forceNew: false,
440450
reconnectionAttempts: 1,
441451
reconnectionDelay: 1000,
442452
reconnectionDelayMax: 15000,
453+
transports: this.transports,
443454
});
444455

445456
this._setupGeneralEvents();
446457
this._setupWorkerEvents();
447458

448-
// GENERAL METHODS
449-
// ===============================================================================
450459
return new Promise((resolve, reject) => {
451460
// Fired upon a connection including a successful reconnection.
452461
this.socketClient.on('connect', () => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cryptomarket",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "The CryptoMarket for Node.js",
55
"homepage": "https://www.cryptomkt.com",
66
"main": "./index.js",

0 commit comments

Comments
 (0)