Skip to content

Commit

Permalink
feat: Added logout method
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Dec 1, 2020
1 parent b439abf commit 6950e40
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/api/whatsapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export class Whatsapp extends ControlsLayer {
return await this.page.evaluate(() => WAPI.takeOver());
}

public async logout() {
return await this.page.evaluate(() => WAPI.logout());
}

/**
* Closes page and browser
* @internal
Expand Down
5 changes: 5 additions & 0 deletions src/lib/wapi/store/store-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,9 @@ export const storeObjects = [
conditions: (module) =>
module.default && module.default.unobscure ? module.default : null,
},
{
id: 'ws2',
conditions: (module) =>
module.default && module.default.destroyStorage ? module.default : null,
},
];
7 changes: 7 additions & 0 deletions src/lib/wapi/wapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,13 @@ if (typeof window.WAPI === 'undefined') {
return true;
};

window.WAPI.logout = async function () {
return await window.WAPI.waitForStore(['ws2'], () => {
window.Store.ws2.logout();
return true;
});
};

window.WAPI.waitForStore = async function (stores, callback) {
if (!Array.isArray(stores)) {
stores = [stores];
Expand Down
1 change: 1 addition & 0 deletions src/types/WAPI.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ interface WAPI {
includeNotifications: boolean
) => Message[];
loadEarlierMessages: (contactId: string) => Message[];
logout: () => Promise<boolean>;
markUnseenMessage: (messageId: string) => boolean;
onAddedToGroup: (callback: Function) => any;
onIncomingCall: (callback: Function) => any;
Expand Down

0 comments on commit 6950e40

Please sign in to comment.