Skip to content

Commit

Permalink
fix: fix function useHere()
Browse files Browse the repository at this point in the history
  • Loading branch information
joaosouz4dev committed Oct 15, 2020
1 parent 4b0f597 commit dd0564e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,7 @@ There are some tricks for a better usage of venom.

client.onStateChange((state) => {
console.log('State changed: ', state);
const conflits = [
venom.SocketState.CONFLICT,
venom.SocketState.UNPAIRED,
venom.SocketState.UNLAUNCHED,
];
const conflits = ['CONFLICT', 'UNPAIRED', 'UNLAUNCHED', 'UNPAIRED_IDLE'];
if (conflits.includes(state)) {
client.useHere();
// Detect a logout
Expand Down
14 changes: 2 additions & 12 deletions src/api/whatsapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { useragentOverride } from '../config/WAuserAgente';
declare module WAPI {
const arrayBufferToBase64: (buffer: ArrayBuffer) => string;
const downloadFile: (data: string) => Promise<string | boolean>;
const takeOver: () => boolean;
}

export class Whatsapp extends ControlsLayer {
Expand Down Expand Up @@ -95,18 +96,7 @@ export class Whatsapp extends ControlsLayer {
* Dont rely on this method
*/
public async useHere() {
await this.page.waitForFunction(
() => {
const useHereClass = '.S7_rT.FV2Qy';
return document.querySelector(useHereClass);
},
{ timeout: 0 }
);

await this.page.evaluate(() => {
const useHereClass = '.S7_rT.FV2Qy';
(<any>document.querySelector(useHereClass)).click();
});
return await this.page.evaluate(() => WAPI.takeOver());
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/lib/wapi/wapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,8 @@ window.WAPI.archiveChat = async function (id, archive) {
.then((_) => true)
.catch((_) => false);
};

window.WAPI.takeOver = async function () {
await Store.State.default.takeover();
return true;
};

0 comments on commit dd0564e

Please sign in to comment.