Skip to content

Commit

Permalink
feat(context): client desconnected mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Oct 14, 2020
1 parent fed693c commit 0fafa3c
Show file tree
Hide file tree
Showing 12 changed files with 20,031 additions and 8,163 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ venom
},
////statusFind
(statusSession) => {
console.log('Status Session: ', statusSession); //return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled
console.log('Status Session: ', statusSession); //return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled || desconnectedMobile
//Create session wss return "serverClose" case server for close
},
////options
{
Expand Down Expand Up @@ -131,7 +132,7 @@ venom

## Callback Status Session

Gets the return if the session is `isLogged` or `notLogged` or `browserClose` or `qrReadSuccess` or `qrReadFail` or `autocloseCalled`
Gets the return if the session is `isLogged` or `notLogged` or `browserClose` or `qrReadSuccess` or `qrReadFail` or `autocloseCalled` or `desconnectedMobile` or `Create session wss return "serverClose" case server for close`

##### `isLogged: When the user is already logged in to the browser`.

Expand All @@ -145,6 +146,8 @@ Gets the return if the session is `isLogged` or `notLogged` or `browserClose` or

##### `autocloseCalled: The browser was closed using the autoClose command`.

##### `desconnectedMobile: Client has desconnected in to mobile`.

```javascript
const venom = require('venom-bot');
venom
Expand All @@ -153,7 +156,8 @@ venom
undefined,
(statusSession) => {
console.log('Status Session: ', statusSession);
//return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled
//return isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled || desconnectedMobile
//Create session wss return "serverClose" case server for close
},
undefined
)
Expand Down
27,750 changes: 19,745 additions & 8,005 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"puppeteer-extra": "^3.1.9",
"puppeteer-extra-plugin-stealth": "^2.4.9",
"qrcode-terminal": "^0.12.0",
"react-scripts": "^3.4.3",
"rxjs": "^6.6.3",
"sharp": "^0.25.2",
"spinnies": "^0.5.1",
Expand Down
1 change: 1 addition & 0 deletions src/api/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ export { downloadFileImgHttp, MINES } from './download-image-file';
export { stickerSelect, resizeImg } from './select-sticker';
export { scrapeImgReload } from './scrape-img-reload';
export { scrapeImg } from './scrape-img-qr';
export { scrapeLogin } from './scrape-login';
2 changes: 1 addition & 1 deletion src/api/helpers/scrape-img-qr.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export async function scrapeImg(page) {
export async function scrapeImg(page): Promise<any> {
var result = await page.evaluate(() => {
const selectorimg = document.querySelector('canvas');
let selectorUrl = document.querySelector('._1QMFu');
Expand Down
2 changes: 1 addition & 1 deletion src/api/helpers/scrape-img-reload.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export async function scrapeImgReload(page, url) {
export async function scrapeImgReload(page, url): Promise<any> {
let click = await page.evaluate(() => {
let bt = document.querySelector('._3IKPF');
if (bt != null) {
Expand Down
16 changes: 16 additions & 0 deletions src/api/helpers/scrape-login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export async function scrapeLogin(page): Promise<boolean> {
var result = await page.evaluate(() => {
let count = document.querySelector('._9a59P');
var data: boolean;
data = false;
if (count != null) {
var text = count.textContent,
timeNumber = text.match('Invalid');
if (timeNumber) {
data = true;
}
return data;
}
});
return result;
}
3 changes: 2 additions & 1 deletion src/api/layers/retriever.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
*/
import { Page } from 'puppeteer';
import { async } from 'rxjs';
import {
Chat,
Contact,
Expand Down Expand Up @@ -97,7 +98,7 @@ declare module WAPI {
includeMe: boolean,
includeNotifications: boolean
) => Message[];
const getSessionTokenBrowser: () => object;
const getSessionTokenBrowser: () => void;
}

export class RetrieverLayer extends SenderLayer {
Expand Down
33 changes: 21 additions & 12 deletions src/controllers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ import { CreateConfig } from '../config/create-config';
export const isAuthenticated = (waPage: puppeteer.Page) => {
return merge(needsToScan(waPage), isInsideChat(waPage))
.pipe(take(1))
.toPromise();
.toPromise()
.catch(() => {});
};

export const needsToScan = (waPage: puppeteer.Page) => {
Expand Down Expand Up @@ -104,6 +105,9 @@ export const isInsideChat = (waPage: puppeteer.Page) => {
};
export async function retrieveQR(page: puppeteer.Page) {
const { code, data } = await decodeQR(page);
if (data === null || code === null) {
return false;
}
const asciiQR = await asciiQr(code);
return { code, data, asciiQR };
}
Expand All @@ -120,22 +124,27 @@ async function decodeQR(
page: puppeteer.Page
): Promise<{ code: string; data: string }> {
await page.waitForSelector('canvas', { timeout: 0 });

await page.addScriptTag({
path: require.resolve(path.join(__dirname, '../lib/jsQR', 'jsQR.js')),
});

return await page.evaluate(() => {
const canvas = document.querySelector('canvas');
const context = canvas.getContext('2d');

// @ts-ignore
const code = jsQR(
context.getImageData(0, 0, canvas.width, canvas.height).data,
canvas.width,
canvas.height
);

return { code: code.data, data: canvas.toDataURL() };
const canvas = document.querySelector('canvas') || null;
if (canvas !== null) {
const context = canvas.getContext('2d') || null;
if (context !== null) {
// @ts-ignore
const code = jsQR(
context.getImageData(0, 0, canvas.width, canvas.height).data,
canvas.width,
canvas.height
);
return { code: code.data, data: canvas.toDataURL() };
}
} else {
return { code: null, data: null };
}
});
}

Expand Down
6 changes: 4 additions & 2 deletions src/controllers/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export async function initBrowser(
browser = e;
})
.catch(() => {
throw new Error('Error when try to connect');
browser = 'connect';
});
} else {
await puppeteer
Expand All @@ -159,7 +159,9 @@ export async function initBrowser(
.then((e) => {
browser = e;
})
.catch(() => {});
.catch(() => {
browser = 'launch';
});
}

return browser;
Expand Down
Loading

0 comments on commit 0fafa3c

Please sign in to comment.