Skip to content

Commit

Permalink
feat: Added 'conn.logout_reason' event (close #1899)
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jul 12, 2024
1 parent 0bcc81f commit 2466c30
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/conn/events/eventTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

import { LogoutReason } from '../../whatsapp/enums';
import { AuthCode } from '../types';

export interface ConnEventTypes {
Expand All @@ -30,6 +31,7 @@ export interface ConnEventTypes {
*/
'conn.authenticated': undefined;
'conn.logout': undefined;
'conn.logout_reason': LogoutReason;
/**
* Triggered when the interface is booting
*
Expand Down
1 change: 1 addition & 0 deletions src/conn/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import './registerAuthCodeChangeEvent';
import './registerAuthenticatedEvent';
import './registerLogoutEvent';
import './registerLogoutReasonEvent';
import './registerMainInit';
import './registerMainLoadedEvent';
import './registerMainReadyEvent';
Expand Down
31 changes: 31 additions & 0 deletions src/conn/events/registerLogoutReasonEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*!
* Copyright 2024 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { internalEv } from '../../eventEmitter';
import * as webpack from '../../webpack';
import { wrapModuleFunction } from '../../whatsapp/exportModule';
import { getErrorCodeFromLogoutReason } from '../../whatsapp/functions';

webpack.onInjected(registerLogoutReasonEvent);

function registerLogoutReasonEvent() {
wrapModuleFunction(getErrorCodeFromLogoutReason, (func, ...args) => {
const [data]: any = args;
internalEv.emit('conn.logout_reason', data);

return func(...args);
});
}
37 changes: 28 additions & 9 deletions src/whatsapp/enums/LogoutReason.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,42 @@ import { exportModule } from '../exportModule';
/** @whatsapp 83578
* @whatsapp 88950 >= 2.2218.4
* @whatsapp 788950 >= 2.2222.8
* @whatsapp WAWebLogoutReasonConstants >= 2.3000.x
*/
export declare enum LogoutReason {
USER_INITIATED = 'user_initiated',
SYNCD_FAILURE = 'syncd_failure',
CRITICAL_SYNC_TIMEOUT = 'critical_sync_timeout',
UNKNOWN_COMPANION = 'unknown_companion',
CLIENT_VERSION_OUTDATED = 'client_version_outdated',
SYNCD_ERROR_DURING_BOOTSTRAP = 'syncd_error_during_bootstrap',
ACCOUNT_SYNC_ERROR = 'account_sync_error',
CLIENT_FATAL_ERROR = 'client_fatal_error',
UserInitiated = 'user_initiated',
SyncdFailure = 'syncd_failure',
InvalidAdvStatus = 'invalid_adv_status',
CriticalSyncTimeout = 'critical_sync_timeout',
SyncdTimeout = 'syncd_timeout',
HistorySyncTimeout = 'history_sync_timeout',
AccountSyncTimeout = 'account_sync_timeout',
MDOptOut = 'md_opt_out',
UnknownCompanion = 'unknown_companion',
ClientVersionOutdated = 'client_version_outdated',
SyncdErrorDuringBootstrap = 'syncd_error_during_bootstrap',
AccountSyncError = 'account_sync_error',
ClientFatalError = 'client_fatal_error',
StorageQuotaExceeded = 'storage_quota_exceeded',
PrimaryIdentityKeyChange = 'primary_identity_key_change',
MissingEncSalt = 'missing_enc_salt',
MissingScreenLockSalt = 'missing_screen_lock_salt',
AccountLocked = 'account_locked',
UNKNOWN = 'unknown',
}

export declare enum LOGOUT_REASON_CODE {
CLIENT_FATAL = '0',
SYNC_FAIL = '1',
INITIAL_HISTORY_SYNC_TIMEOUT = '2',
ACCOUNT_LOCKED = '3',
}

exportModule(
exports,
{
LogoutReason: 'LogoutReason',
LOGOUT_REASON_CODE: 'LOGOUT_REASON_CODE',
},
(m) => m.LogoutReason
(m) => m.LogoutReason && m.LOGOUT_REASON_CODE
);
33 changes: 33 additions & 0 deletions src/whatsapp/functions/getErrorCodeFromLogoutReason.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { LOGOUT_REASON_CODE, LogoutReason } from '../enums';
import { exportModule } from '../exportModule';

/**
* @whatsapp WAWebLogoutReason >= 2.3000.x
*/
export declare function getErrorCodeFromLogoutReason(
type: LogoutReason
): LOGOUT_REASON_CODE | null;

exportModule(
exports,
{
getErrorCodeFromLogoutReason: 'getErrorCodeFromLogoutReason',
},
(m) => m.getErrorCodeFromLogoutReason
);
1 change: 1 addition & 0 deletions src/whatsapp/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export * from './getCommunityParticipants';
export * from './getCountryShortcodeByPhone';
export * from './getCurrentLid';
export * from './getEphemeralFields';
export * from './getErrorCodeFromLogoutReason';
export * from './getFanOutList';
export * from './getGroupSenderKeyList';
export * from './getGroupSizeLimit';
Expand Down

0 comments on commit 2466c30

Please sign in to comment.