diff --git a/Example/example.ts b/Example/example.ts index b5e712e..edcac84 100644 --- a/Example/example.ts +++ b/Example/example.ts @@ -27,9 +27,13 @@ async function example() { fs.writeFileSync('./auth_info.json', JSON.stringify(authInfo, null, '\t')) // save this info to a file /* Note: one can take this auth_info.json file and login again from any computer without having to scan the QR code, and get full access to one's WhatsApp. Despite the convenience, be careful with this file */ - client.setOnTakenOver (async () => { - // uncomment to reconnect whenever the connection gets taken over from somewhere else - // await client.connect () + client.setOnDisconnect (async kind => { + if (kind === 'replaced') { + // uncomment to reconnect whenever the connection gets taken over from somewhere else + // await client.connect () + } else { + console.log ('oh no got logged out!') + } }) client.setOnPresenceUpdate(json => console.log(json.id + ' presence is ' + json.type)) client.setOnMessageStatusChange(json => { diff --git a/src/WAClient/Base.ts b/src/WAClient/Base.ts index eec6243..93aa79a 100644 --- a/src/WAClient/Base.ts +++ b/src/WAClient/Base.ts @@ -13,8 +13,8 @@ import { import { generateMessageTag } from '../WAConnection/Utils' export default class WhatsAppWebBase extends WAConnection { - /** Set the callback for when the connection is taken over somewhere else */ - setOnTakenOver(callback: (kind: 'replaced' | string | null) => void) { + /** 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 ()