Skip to content

Commit 2b402d5

Browse files
committed
update v1.8.1
1 parent a5127f6 commit 2b402d5

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules/
22
.npmrc
33
dist/
4-
wa_credentials/
4+
wa_credentials/
5+
test/

package.json

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

src/Socket/index.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,17 @@ export const startSession = async (
5858
callback.get(CALLBACK_KEY.ON_CONNECTING)?.(sessionId);
5959
}
6060
if (connection === "close") {
61-
// let retryAttempt = retryCount.get(sessionId) ?? 0;
62-
// const shouldRetry = retryAttempt < 5;
6361
const code = (lastDisconnect?.error as Boom)?.output?.statusCode;
64-
if (code !== DisconnectReason.loggedOut) {
65-
// retryAttempt = retryAttempt + 1;
66-
// retryCount.set(sessionId, retryAttempt);
62+
let retryAttempt = retryCount.get(sessionId) ?? 0;
63+
const shouldRetry =
64+
code != DisconnectReason.loggedOut &&
65+
(code == DisconnectReason.restartRequired || retryAttempt < 10);
66+
code != DisconnectReason.restartRequired && retryAttempt++;
67+
console.log(retryAttempt);
68+
console.log(shouldRetry);
69+
console.log(DisconnectReason[code]);
70+
if (shouldRetry) {
71+
retryCount.set(sessionId, retryAttempt);
6772
startSocket();
6873
} else {
6974
deleteSession(sessionId);
@@ -102,9 +107,9 @@ export const startWhatsapp = startSession;
102107
export const deleteSession = async (sessionId: string) => {
103108
const session = getSession(sessionId);
104109
try {
105-
session?.end(undefined);
106110
await session?.logout();
107111
} catch (error) {}
112+
session?.end(undefined);
108113
sessions.delete(sessionId);
109114
const dir = path.resolve(
110115
CREDENTIALS.DIR_NAME,
@@ -150,7 +155,7 @@ const shouldLoadSession = (sessionId: string): boolean => {
150155
return false;
151156
};
152157

153-
const loadSessions = async () => {
158+
const loadSessions = () => {
154159
if (!fs.existsSync(path.resolve(CREDENTIALS.DIR_NAME))) {
155160
fs.mkdirSync(path.resolve(CREDENTIALS.DIR_NAME));
156161
}

0 commit comments

Comments
 (0)