Skip to content

Commit

Permalink
🔧 added config.oorTimeout #2994
Browse files Browse the repository at this point in the history
  • Loading branch information
smashah committed Jan 8, 2023
1 parent 075eefd commit 1e5893d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/api/model/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ export interface ConfigObject {
* @default `60`
*/
authTimeout?: number;
/**
* phoneIsOutOfReach check timeout
* @default `60`
*/
oorTimeout?: number,
/**
* Setting this to `true` will kill the whole process when the client is disconnected from the page or if the browser is closed.
* @default `false`
Expand Down
6 changes: 4 additions & 2 deletions src/controllers/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { log, setupLogging } from '../logging/logging';

export const pkg = readJsonSync(path.join(__dirname,'../../package.json')),
configWithCases = readJsonSync(path.join(__dirname,'../../bin/config-schema.json')),
timeout = (ms : number) => {
timeout : (ms: number) => Promise<string> = (ms : number) => {
return new Promise(resolve => setTimeout(resolve, ms, 'timeout'));
}

Expand Down Expand Up @@ -246,7 +246,9 @@ export async function create(config: AdvancedConfig | ConfigObject = {}): Promis
},debugInfo,spinner)

if (authenticated == 'timeout') {
const outOfReach = await Promise.race([phoneIsOutOfReach(waPage), timeout(20 * 1000)]);
const oorProms : Promise<boolean | string>[] = [phoneIsOutOfReach(waPage)];
if(config?.oorTimeout!== 0) oorProms.push(timeout((config?.oorTimeout || 60) * 1000))
const outOfReach : string | boolean = await Promise.race(oorProms) as any
spinner.emit(outOfReach && outOfReach !== 'timeout' ? 'appOffline' : 'authTimeout');
spinner.fail(outOfReach && outOfReach !== 'timeout' ? 'Authentication timed out. Please open the app on the phone. Shutting down' : 'Authentication timed out. Shutting down. Consider increasing authTimeout config variable: https://open-wa.github.io/wa-automate-nodejs/interfaces/configobject.html#authtimeout');
await kill(waPage);
Expand Down

0 comments on commit 1e5893d

Please sign in to comment.