Skip to content

Commit a0e0870

Browse files
author
Zan Markan
committed
Reset reconnection counter when connection is successful
1 parent 9caff8a commit a0e0870

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/main/java/com/pusher/client/connection/websocket/WebSocketConnection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class WebSocketConnection implements InternalConnection, WebSocketListene
3131

3232
private static final String INTERNAL_EVENT_PREFIX = "pusher:";
3333
private static final String PING_EVENT_SERIALIZED = "{\"event\": \"pusher:ping\"}";
34-
private static final int MAX_CONNECTION_ATTEMPTS = 6; //Taken from the Swift lib
34+
private static final int MAX_RECONNECTION_ATTEMPTS = 6; //Taken from the Swift lib
3535
private static final int MAX_RECONNECT_GAP_IN_SECONDS = 30;
3636

3737
private final Factory factory;
@@ -178,6 +178,7 @@ private void handleEvent(final String event, final String wholeMessage) {
178178
private void handleInternalEvent(final String event, final String wholeMessage) {
179179
if (event.equals("pusher:connection_established")) {
180180
handleConnectionMessage(wholeMessage);
181+
reconnectAttempts = 0;
181182
}
182183
else if (event.equals("pusher:error")) {
183184
handleError(wholeMessage);
@@ -267,7 +268,7 @@ public void onClose(final int code, final String reason, final boolean remote) {
267268
//Reconnection logic
268269
if(state == ConnectionState.CONNECTED || state == ConnectionState.CONNECTING){
269270

270-
if(reconnectAttempts < MAX_CONNECTION_ATTEMPTS){
271+
if(reconnectAttempts < MAX_RECONNECTION_ATTEMPTS){
271272
tryReconnecting();
272273
}
273274
else{

0 commit comments

Comments
 (0)