Unified unexpected disconnect & takeover events

This commit is contained in:
Adhiraj
2020-07-13 16:32:52 +05:30
parent 8b859b9376
commit d87e4e5897
5 changed files with 28 additions and 43 deletions

View File

@@ -5,29 +5,10 @@ import {
WANode,
WAMetric,
WAFlag,
WAGroupCreateResponse,
WAGroupMetadata,
WAGroupModification,
MessageLogLevel,
} from '../WAConnection/Constants'
import { generateMessageTag } from '../WAConnection/Utils'
export default class WhatsAppWebBase extends WAConnection {
/** Set the callback for when the connection is taken over somewhere else or logged out */
setOnDisconnect(callback: (kind: 'replaced' | string | null) => void) {
this.registerCallback (['Cmd', 'type:disconnect'], json => {
this.log ('connection taken over elsewhere')
this.close ()
callback (json[1].kind)
})
}
/** Set the callback for unexpected disconnects */
setOnUnexpectedDisconnect(callback: (error: Error) => void) {
this.unexpectedDisconnect = (err) => {
this.close()
callback(err)
}
}
/** Set the callback for message status updates (when a message is delivered, read etc.) */
setOnMessageStatusChange(callback: (update: MessageStatusUpdate) => void) {
const func = (json) => {