Skip to content

Commit

Permalink
update v1.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mimamch committed Mar 26, 2023
1 parent a5127f6 commit 2b402d5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
.npmrc
dist/
wa_credentials/
wa_credentials/
test/
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": "1.8.0",
"version": "1.8.1",
"description": "Multi Session Whatsapp Library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
19 changes: 12 additions & 7 deletions src/Socket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ export const startSession = async (
callback.get(CALLBACK_KEY.ON_CONNECTING)?.(sessionId);
}
if (connection === "close") {
// let retryAttempt = retryCount.get(sessionId) ?? 0;
// const shouldRetry = retryAttempt < 5;
const code = (lastDisconnect?.error as Boom)?.output?.statusCode;
if (code !== DisconnectReason.loggedOut) {
// retryAttempt = retryAttempt + 1;
// retryCount.set(sessionId, retryAttempt);
let retryAttempt = retryCount.get(sessionId) ?? 0;
const shouldRetry =
code != DisconnectReason.loggedOut &&
(code == DisconnectReason.restartRequired || retryAttempt < 10);
code != DisconnectReason.restartRequired && retryAttempt++;
console.log(retryAttempt);
console.log(shouldRetry);
console.log(DisconnectReason[code]);
if (shouldRetry) {
retryCount.set(sessionId, retryAttempt);
startSocket();
} else {
deleteSession(sessionId);
Expand Down Expand Up @@ -102,9 +107,9 @@ export const startWhatsapp = startSession;
export const deleteSession = async (sessionId: string) => {
const session = getSession(sessionId);
try {
session?.end(undefined);
await session?.logout();
} catch (error) {}
session?.end(undefined);
sessions.delete(sessionId);
const dir = path.resolve(
CREDENTIALS.DIR_NAME,
Expand Down Expand Up @@ -150,7 +155,7 @@ const shouldLoadSession = (sessionId: string): boolean => {
return false;
};

const loadSessions = async () => {
const loadSessions = () => {
if (!fs.existsSync(path.resolve(CREDENTIALS.DIR_NAME))) {
fs.mkdirSync(path.resolve(CREDENTIALS.DIR_NAME));
}
Expand Down

0 comments on commit 2b402d5

Please sign in to comment.