feat(core): override layer number

This commit is contained in:
teidesu 2021-07-24 17:00:20 +03:00
parent cb2df91187
commit f3e7de5c8c
2 changed files with 16 additions and 1 deletions

View file

@ -146,6 +146,15 @@ export namespace BaseTelegramClient {
* @default true
*/
niceStacks?: boolean
/**
* **EXPERT USE ONLY!**
*
* Override TL layer used for the connection. /;'
*
* **Does not** change the schema used.
*/
overrideLayer?: number
}
}
@ -207,6 +216,7 @@ export class BaseTelegramClient extends EventEmitter {
protected _primaryDc: tl.RawDcOption
private _niceStacks: boolean
readonly _layer: number
private _keepAliveInterval: NodeJS.Timeout
private _lastRequestTime = 0
@ -265,6 +275,8 @@ export class BaseTelegramClient extends EventEmitter {
this._disableUpdates = opts.disableUpdates ?? false
this._niceStacks = opts.niceStacks ?? true
this._layer = opts.overrideLayer ?? tl.CURRENT_LAYER
let deviceModel = 'mtcute on '
if (typeof process !== 'undefined' && typeof require !== 'undefined') {
const os = require('os')
@ -310,6 +322,7 @@ export class BaseTelegramClient extends EventEmitter {
transportFactory: this._transportFactory,
dc: this._primaryDc,
reconnectionStrategy: this._reconnectionStrategy,
layer: this._layer,
})
this.primaryConnection.on('usable', async () => {
this._keepAliveInterval = setInterval(async () => {
@ -654,6 +667,7 @@ export class BaseTelegramClient extends EventEmitter {
transportFactory: this._transportFactory,
reconnectionStrategy: this._reconnectionStrategy,
inactivityTimeout,
layer: this._layer,
})
connection.on('error', (err) => this._emitError(err, connection))

View file

@ -42,6 +42,7 @@ export interface TelegramConnectionParams extends PersistentConnectionParams {
initConnection: tl.RawInitConnectionRequest
inactivityTimeout?: number
niceStacks?: boolean
layer: number
}
const messageHandlers: Record<string, string /* keyof TelegramConnection */> = {
@ -668,7 +669,7 @@ export class TelegramConnection extends PersistentConnection {
debug('wrapping %s with initConnection', message._)
obj = {
_: 'invokeWithLayer',
layer: tl.CURRENT_LAYER,
layer: this.params.layer,
query: {
...this.params.initConnection,
query: message,