Skip to content

Commit

Permalink
update v2.1.0; fix disconnected sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
mimamch committed Apr 27, 2023
1 parent 43e5845 commit a574d98
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wa-multi-session",
"version": "2.0.0",
"version": "2.1.0",
"description": "Multi Session Whatsapp Library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
13 changes: 9 additions & 4 deletions src/Socket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,24 @@ export const startSession = async (
if (connection === "close") {
const code = (lastDisconnect?.error as Boom)?.output?.statusCode;
let retryAttempt = retryCount.get(sessionId) ?? 0;
const shouldRetry =
code != DisconnectReason.loggedOut &&
(code == DisconnectReason.restartRequired || retryAttempt < 10);
code != DisconnectReason.restartRequired && retryAttempt++;
let shouldRetry;
if (code != DisconnectReason.loggedOut && retryAttempt < 10) {
shouldRetry = true;
}
if (shouldRetry) {
retryAttempt++;
}
if (shouldRetry) {
retryCount.set(sessionId, retryAttempt);
startSocket();
} else {
retryCount.delete(sessionId);
deleteSession(sessionId);
callback.get(CALLBACK_KEY.ON_DISCONNECTED)?.(sessionId);
}
}
if (connection == "open") {
retryCount.delete(sessionId);
callback.get(CALLBACK_KEY.ON_CONNECTED)?.(sessionId);
}
}
Expand Down

0 comments on commit a574d98

Please # to comment.