fix(client): redundant resends

This commit is contained in:
teidesu 2021-06-15 03:11:11 +03:00
parent 6c8eeb01d2
commit 9928a9156a

View file

@ -327,6 +327,7 @@ export class BaseTelegramClient {
// on reconnection we need to call updates.getState so Telegram // on reconnection we need to call updates.getState so Telegram
// knows we still want the updates // knows we still want the updates
if (!this._disableUpdates) { if (!this._disableUpdates) {
setTimeout(async () => {
try { try {
await this.call({ _: 'updates.getState' }) await this.call({ _: 'updates.getState' })
} catch (e) { } catch (e) {
@ -334,6 +335,7 @@ export class BaseTelegramClient {
this.primaryConnection.reconnect() this.primaryConnection.reconnect()
} }
} }
}, 0)
} }
}) })
this.primaryConnection.on('update', (update) => { this.primaryConnection.on('update', (update) => {
@ -406,6 +408,15 @@ export class BaseTelegramClient {
this.primaryConnection.connect() this.primaryConnection.connect()
} }
/**
* Wait until this client is usable (i.e. connection is fully ready)
*/
async waitUntilUsable(): Promise<void> {
return new Promise((resolve) => {
this.primaryConnection.once('usable', resolve)
})
}
/** /**
* Close all connections and finalize the client. * Close all connections and finalize the client.
*/ */