Skip to content

Commit

Permalink
feat: Added deviceSyncTimeout option (close #1551)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Feb 19, 2023
1 parent caf7275 commit d4458e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/api/layers/host.layer.ts
Expand Up @@ -200,7 +200,7 @@ export class HostLayer {
}

if (
this.options.autoClose > 0 &&
(this.options.autoClose > 0 || this.options.deviceSyncTimeout > 0) &&
!this.autoCloseInterval &&
!this.page.isClosed()
) {
Expand All @@ -213,9 +213,13 @@ export class HostLayer {
}
}

protected startAutoClose() {
if (this.options.autoClose > 0 && !this.autoCloseInterval) {
const seconds = Math.round(this.options.autoClose / 1000);
protected startAutoClose(time: number | null = null) {
if (time === null || time === undefined) {
time = this.options.autoClose;
}

if (time > 0 && !this.autoCloseInterval) {
const seconds = Math.round(time / 1000);
this.log('info', `Auto close configured to ${seconds}s`);

let remain = seconds;
Expand Down Expand Up @@ -358,7 +362,7 @@ export class HostLayer {
this.cancelAutoClose();
// Wait for interface update
await sleep(200);
this.startAutoClose();
this.startAutoClose(this.options.deviceSyncTimeout);
this.log('http', 'Checking phone is connected...');
const inChat = await this.waitForInChat();

Expand Down
6 changes: 6 additions & 0 deletions src/config/create-config.ts
Expand Up @@ -81,6 +81,11 @@ export interface CreateConfig {
* @default 60000
*/
autoClose?: number;
/**
* Automatically closes the wppconnect only when is syncing the device (default 180000 miliseconds, 3 minutes, if you want to turn it off, assign 0 or false)
* @default 180000 (3 minutes)
*/
deviceSyncTimeout?: number;
/**
* Wait for in chat to return a instance of {@link Whatsapp}
* @default false
Expand Down Expand Up @@ -176,6 +181,7 @@ export const defaultOptions: CreateConfig = {
disableWelcome: false,
updatesLog: true,
autoClose: 60000,
deviceSyncTimeout: 180000,
createPathFileToken: true,
waitForLogin: true,
logger: defaultLogger,
Expand Down

2 comments on commit d4458e5

@renandecarlo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edgardmessias , this breaks autoClose = false. I have to also set deviceSyncTimeout = false for it to work

@edgardmessias
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the normally problems with stuck sessions is with syncing devices

Please sign in to comment.