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,13 +327,15 @@ export class BaseTelegramClient {
// on reconnection we need to call updates.getState so Telegram
// knows we still want the updates
if (!this._disableUpdates) {
try {
await this.call({ _: 'updates.getState' })
} catch (e) {
if (!(e instanceof RpcError)) {
this.primaryConnection.reconnect()
setTimeout(async () => {
try {
await this.call({ _: 'updates.getState' })
} catch (e) {
if (!(e instanceof RpcError)) {
this.primaryConnection.reconnect()
}
}
}
}, 0)
}
})
this.primaryConnection.on('update', (update) => {
@ -406,6 +408,15 @@ export class BaseTelegramClient {
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.
*/