From 1340279cdb984972f20f709275874fd3bafeadc5 Mon Sep 17 00:00:00 2001 From: Adhiraj Date: Thu, 3 Sep 2020 22:58:27 +0530 Subject: [PATCH] added pong event --- src/WAConnection/3.Connect.ts | 1 + src/WAConnection/4.Events.ts | 3 +++ src/WAConnection/Constants.ts | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/WAConnection/3.Connect.ts b/src/WAConnection/3.Connect.ts index 223ba34..aa5cde3 100644 --- a/src/WAConnection/3.Connect.ts +++ b/src/WAConnection/3.Connect.ts @@ -264,6 +264,7 @@ export class WAConnection extends Base { // when the first character in the message is an '!', the server is updating the last seen const timestamp = message.slice(1, message.length).toString ('utf-8') this.lastSeen = new Date(parseInt(timestamp)) + this.emit ('received-pong') } else { const decrypted = Utils.decryptWA (message, this.authInfo?.macKey, this.authInfo?.encKey, new Decoder()) if (!decrypted) return diff --git a/src/WAConnection/4.Events.ts b/src/WAConnection/4.Events.ts index b7acc31..91f5929 100644 --- a/src/WAConnection/4.Events.ts +++ b/src/WAConnection/4.Events.ts @@ -324,6 +324,9 @@ export class WAConnection extends Base { on (event: 'group-settings-update', listener: (update: {jid: string, restrict?: string, announce?: string, actor?: string}) => void): this /** when the group description is updated */ on (event: 'group-description-update', listener: (update: {jid: string, description?: string, actor?: string}) => void): this + /** when WA sends back a pong */ + on (event: 'received-pong', listener: () => void): this + on (event: BaileysEvent, listener: (...args: any[]) => void) { return super.on (event, listener) } emit (event: BaileysEvent, ...args: any[]) { return super.emit (event, ...args) } diff --git a/src/WAConnection/Constants.ts b/src/WAConnection/Constants.ts index f3bfb6c..d27d1e4 100644 --- a/src/WAConnection/Constants.ts +++ b/src/WAConnection/Constants.ts @@ -368,4 +368,5 @@ export type BaileysEvent = 'group-participants-promote' | 'group-participants-demote' | 'group-settings-update' | - 'group-description-update' \ No newline at end of file + 'group-description-update' | + 'received-pong' \ No newline at end of file