@@ -58,12 +58,17 @@ export const startSession = async (
58
58
callback . get ( CALLBACK_KEY . ON_CONNECTING ) ?.( sessionId ) ;
59
59
}
60
60
if ( connection === "close" ) {
61
- // let retryAttempt = retryCount.get(sessionId) ?? 0;
62
- // const shouldRetry = retryAttempt < 5;
63
61
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 ) ;
67
72
startSocket ( ) ;
68
73
} else {
69
74
deleteSession ( sessionId ) ;
@@ -102,9 +107,9 @@ export const startWhatsapp = startSession;
102
107
export const deleteSession = async ( sessionId : string ) => {
103
108
const session = getSession ( sessionId ) ;
104
109
try {
105
- session ?. end ( undefined ) ;
106
110
await session ?. logout ( ) ;
107
111
} catch ( error ) { }
112
+ session ?. end ( undefined ) ;
108
113
sessions . delete ( sessionId ) ;
109
114
const dir = path . resolve (
110
115
CREDENTIALS . DIR_NAME ,
@@ -150,7 +155,7 @@ const shouldLoadSession = (sessionId: string): boolean => {
150
155
return false ;
151
156
} ;
152
157
153
- const loadSessions = async ( ) => {
158
+ const loadSessions = ( ) => {
154
159
if ( ! fs . existsSync ( path . resolve ( CREDENTIALS . DIR_NAME ) ) ) {
155
160
fs . mkdirSync ( path . resolve ( CREDENTIALS . DIR_NAME ) ) ;
156
161
}
0 commit comments