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 // 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) {
try { setTimeout(async () => {
await this.call({ _: 'updates.getState' }) try {
} catch (e) { await this.call({ _: 'updates.getState' })
if (!(e instanceof RpcError)) { } catch (e) {
this.primaryConnection.reconnect() if (!(e instanceof RpcError)) {
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.
*/ */