Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = class Connection extends EventEmitter {

registeredSuccessfully() {
this.registered = Date.now();
this.reconnect_attempts = 0;
}

connect(options) {
Expand Down Expand Up @@ -83,7 +84,6 @@ module.exports = class Connection extends EventEmitter {
// Called when the socket is connected and ready to start sending/receiving data.
function socketOpen() {
that.debugOut('Socket fully connected');
that.reconnect_attempts = 0;
that.connected = true;
that.emit('socket connected');
}
Expand Down Expand Up @@ -117,11 +117,13 @@ module.exports = class Connection extends EventEmitter {
} else if (that.reconnect_attempts && that.reconnect_attempts < that.auto_reconnect_max_retries) {
should_reconnect = true;

// If we were originally connected OK, reconnect
} else if (was_connected && safely_registered) {
should_reconnect = true;
// If we were originally connected, reconnect if the connection was OK
} else if (was_connected && that.registered !== false) {
should_reconnect = safely_registered;

// Potentially a transient initial connection error
} else {
should_reconnect = false;
should_reconnect = true;
}

if (should_reconnect) {
Expand Down
Loading