Skip to content

Commit c3c5cc8

Browse files
author
Charlie Somerville
committed
add maxReconnectAttempts to limit number of retries
1 parent e70fc3b commit c3c5cc8

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

reconnecting-websocket.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122

123123
/** The maximum time in milliseconds to wait for a connection to succeed before closing and retrying. */
124124
timeoutInterval: 2000
125+
126+
/** The maximum number of reconnection attempts to make. Unlimited if null. */
127+
maxReconnectAttempts: null,
125128
}
126129
if (!options) { options = {}; }
127130

@@ -202,6 +205,10 @@
202205
eventTarget.dispatchEvent(generateEvent('connecting'));
203206
}
204207

208+
if (this.maxReconnectAttempts && this.reconnectAttempts > this.maxReconnectAttempts) {
209+
return;
210+
}
211+
205212
if (self.debug || ReconnectingWebSocket.debugAll) {
206213
console.debug('ReconnectingWebSocket', 'attempt-connect', self.url);
207214
}

0 commit comments

Comments
 (0)