diff --git a/src/webpack/api/init.ts b/src/webpack/api/init.ts index bed714d..a182664 100644 --- a/src/webpack/api/init.ts +++ b/src/webpack/api/init.ts @@ -132,7 +132,7 @@ export async function initServer( }); await client.qrCodeScan(); } - } catch {} + } catch { } }); } else { ev.emitStatusFind({ diff --git a/src/webpack/api/layes/callback-on.layes.ts b/src/webpack/api/layes/callback-on.layes.ts index 38ee038..a79b13d 100644 --- a/src/webpack/api/layes/callback-on.layes.ts +++ b/src/webpack/api/layes/callback-on.layes.ts @@ -1,4 +1,5 @@ import { onMode } from '../../model/enum'; +import { StatusFind } from '../../model/interface'; import { EventEmitter } from 'events'; /** @@ -11,8 +12,11 @@ export class CallbackOnStatus { * Emit an event with the specified type and arguments * @param args Event arguments, including onType to specify the event type */ - public emitStatusFind(args: any) { - this.listenerEmitter.emit(args.onType, args); + public emitStatusFind(args: StatusFind) { + if (!args.onType) { + throw new Error('onType is required to emit an event'); + } + this.listenerEmitter.emit(args.onType, args); } /** @@ -20,7 +24,7 @@ export class CallbackOnStatus { * @param type Type of event to monitor * @param callback Function to call with event data */ - public on(type: onMode, callback: (state: any) => void) { + public on(type: onMode, callback: (state: StatusFind) => void) { this.listenerEmitter.on(type, callback); } } diff --git a/src/webpack/api/layes/listener.layes.ts b/src/webpack/api/layes/listener.layes.ts index 0289623..bba14bb 100644 --- a/src/webpack/api/layes/listener.layes.ts +++ b/src/webpack/api/layes/listener.layes.ts @@ -4,6 +4,7 @@ import { Page, Browser } from 'puppeteer'; import { Whatsapp } from './whatsapp'; import { CreateOptions } from '../../model/interface'; import { sleep } from '../../help'; +import { CallbackOnStatus } from './callback-on.layes'; export class ListenerLayer extends Whatsapp { urlCode = ''; @@ -11,7 +12,7 @@ export class ListenerLayer extends Whatsapp { public page: Page, public browser: Browser, public options: CreateOptions, - public ev: any + public ev: CallbackOnStatus, ) { super(page, browser, options, ev); } @@ -78,7 +79,7 @@ export class ListenerLayer extends Whatsapp { private listener(type: string): { dispose: () => void } { this.listenerEmitter.on(type, (event) => { this.ev.emitStatusFind({ - onType: type, + onType: type as onMode, session: this.options.session, result: event, }); @@ -87,7 +88,7 @@ export class ListenerLayer extends Whatsapp { dispose: () => { this.listenerEmitter.off(type, (event) => { this.ev.emitStatusFind({ - onType: type, + onType: type as onMode, session: this.options.session, result: event, }); diff --git a/src/webpack/model/interface/index.ts b/src/webpack/model/interface/index.ts index c91f3cf..46577b8 100644 --- a/src/webpack/model/interface/index.ts +++ b/src/webpack/model/interface/index.ts @@ -8,3 +8,4 @@ export { id } from './id'; export { CreateSize } from './create-size'; export { contact } from './contact'; export { checkNumber } from './check-number'; +export { StatusFind } from './status-find'; \ No newline at end of file diff --git a/src/webpack/model/interface/status-find.ts b/src/webpack/model/interface/status-find.ts new file mode 100644 index 0000000..3801812 --- /dev/null +++ b/src/webpack/model/interface/status-find.ts @@ -0,0 +1,17 @@ +import { onMode, TypeStatusFind } from '../enum'; +import { Page } from 'puppeteer'; +import { WebPack } from '../../inject/webpack'; +export interface StatusFind { + erro?: boolean; + text?: string; + status?: TypeStatusFind; + statusFind?: string; + onType: onMode; + session?: string; + page?: Page; + connect?: boolean; + qrcode?: string; + client?: WebPack; + base64Image?: string; + result?: any; +} \ No newline at end of file