Skip to content

Commit

Permalink
feat: add interface StatusFind
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Nov 18, 2024
1 parent 0a06572 commit 3de0126
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/webpack/api/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export async function initServer(
});
await client.qrCodeScan();
}
} catch {}
} catch { }
});
} else {
ev.emitStatusFind({
Expand Down
10 changes: 7 additions & 3 deletions src/webpack/api/layes/callback-on.layes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { onMode } from '../../model/enum';
import { StatusFind } from '../../model/interface';
import { EventEmitter } from 'events';

/**
Expand All @@ -11,16 +12,19 @@ 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);
}

/**
* Listen for specific user events
* @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);
}
}
7 changes: 4 additions & 3 deletions src/webpack/api/layes/listener.layes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ 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 = '';
constructor(
public page: Page,
public browser: Browser,
public options: CreateOptions,
public ev: any
public ev: CallbackOnStatus,
) {
super(page, browser, options, ev);
}
Expand Down Expand Up @@ -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,
});
Expand All @@ -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,
});
Expand Down
1 change: 1 addition & 0 deletions src/webpack/model/interface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
17 changes: 17 additions & 0 deletions src/webpack/model/interface/status-find.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 3de0126

Please sign in to comment.