Skip to content

Commit a574d98

Browse files
committed
update v2.1.0; fix disconnected sometimes
1 parent 43e5845 commit a574d98

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

.DS_Store

0 Bytes
Binary file not shown.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wa-multi-session",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "Multi Session Whatsapp Library",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/Socket/index.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,24 @@ export const startSession = async (
6464
if (connection === "close") {
6565
const code = (lastDisconnect?.error as Boom)?.output?.statusCode;
6666
let retryAttempt = retryCount.get(sessionId) ?? 0;
67-
const shouldRetry =
68-
code != DisconnectReason.loggedOut &&
69-
(code == DisconnectReason.restartRequired || retryAttempt < 10);
70-
code != DisconnectReason.restartRequired && retryAttempt++;
67+
let shouldRetry;
68+
if (code != DisconnectReason.loggedOut && retryAttempt < 10) {
69+
shouldRetry = true;
70+
}
71+
if (shouldRetry) {
72+
retryAttempt++;
73+
}
7174
if (shouldRetry) {
7275
retryCount.set(sessionId, retryAttempt);
7376
startSocket();
7477
} else {
78+
retryCount.delete(sessionId);
7579
deleteSession(sessionId);
7680
callback.get(CALLBACK_KEY.ON_DISCONNECTED)?.(sessionId);
7781
}
7882
}
7983
if (connection == "open") {
84+
retryCount.delete(sessionId);
8085
callback.get(CALLBACK_KEY.ON_CONNECTED)?.(sessionId);
8186
}
8287
}

0 commit comments

Comments
 (0)