-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
* Fix heartbeat channel subscriptions - Automatically adds the `heartbeat` channel if not already subscribed - Removes redundant `keepalive` ping on the socket Fixes #113 * Remove heartbeat from OrderbookSync signature
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,20 +14,21 @@ class WebsocketClient extends EventEmitter { | |
productIDs, | ||
websocketURI = 'wss://ws-feed.gdax.com', | ||
auth = null, | ||
{ heartbeat = false, channels = null } = {} | ||
{ channels = null } = {} | ||
) { | ||
super(); | ||
this.productIDs = Utils.determineProductIDs(productIDs); | ||
this.websocketURI = websocketURI; | ||
this.channels = channels; | ||
this.auth = Utils.checkAuth(auth); | ||
this.heartbeat = heartbeat; | ||
this.channels = channels || ['full']; | ||
if (!this.channels.includes('heartbeat')) { | ||
this.channels.push('heartbeat'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rmm5t
Author
Contributor
|
||
} | ||
this.connect(); | ||
} | ||
|
||
connect() { | ||
if (this.socket) { | ||
clearInterval(this.pinger); | ||
this.socket.close(); | ||
} | ||
|
||
|
@@ -40,8 +41,6 @@ class WebsocketClient extends EventEmitter { | |
} | ||
|
||
disconnect() { | ||
clearInterval(this.pinger); | ||
|
||
if (!this.socket) { | ||
throw new Error('Could not disconnect (not connected)'); | ||
} | ||
|
@@ -55,12 +54,9 @@ class WebsocketClient extends EventEmitter { | |
const subscribeMessage = { | ||
type: 'subscribe', | ||
product_ids: this.productIDs, | ||
channels: this.channels, | ||
}; | ||
|
||
if (this.channels) { | ||
subscribeMessage.channels = this.channels; | ||
} | ||
|
||
// Add Signature | ||
if (this.auth.secret) { | ||
let sig = signRequest( | ||
|
@@ -72,26 +68,9 @@ class WebsocketClient extends EventEmitter { | |
} | ||
|
||
this.socket.send(JSON.stringify(subscribeMessage)); | ||
|
||
if (this.heartbeat) { | ||
// send heartbeat | ||
const heartbeatMessage = { | ||
type: 'heartbeat', | ||
on: true, | ||
}; | ||
this.socket.send(JSON.stringify(heartbeatMessage)); | ||
} else { | ||
// Set a 30 second ping to keep connection alive | ||
this.pinger = setInterval(() => { | ||
if (this.socket) { | ||
this.socket.ping('keepalive'); | ||
} | ||
}, 30000); | ||
} | ||
} | ||
|
||
onClose() { | ||
clearInterval(this.pinger); | ||
this.socket = null; | ||
this.emit('close'); | ||
} | ||
|
Hi @rmm5t, why forcing the heartbeat channel?