diff --git a/package-lock.json b/package-lock.json index b449695..4f2494a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -62,9 +62,9 @@ "integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==" }, "node_modules/@types/node": { - "version": "24.13.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.13.2.tgz", - "integrity": "sha512-fRa09kZTgu8o71KFcDjUFuc7F+dEbZYZmkI0mg5YBTRs0yMKjYHsq/c0urDKeDb+D5qVgXOdFcuu+DZPKOITwA==", + "version": "24.10.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.2.tgz", + "integrity": "sha512-WOhQTZ4G8xZ1tjJTvKOpyEVSGgOTvJAfDK3FNFgELyaTpzhdgHVHeqW8V+UJvzF5BT+/B54T/1S2K6gd9c7bbA==", "license": "MIT", "dependencies": { "undici-types": "~7.18.0" diff --git a/src/builder.ts b/src/builder.ts index 6b307a5..efe148d 100644 --- a/src/builder.ts +++ b/src/builder.ts @@ -2254,6 +2254,7 @@ export interface BuilderMap { 'users.getSavedMusicByID': (this: any, params: any) => void 'account.getUniqueGiftChatThemes': (this: any, params: any) => void } + export const builderMap: BuilderMap = { 'mt_vector': function(params) { this.int32(481674261); diff --git a/src/mtptoto-types.ts b/src/mtptoto-types.ts index 074fc78..2c27f36 100644 --- a/src/mtptoto-types.ts +++ b/src/mtptoto-types.ts @@ -17003,5 +17003,14 @@ export interface Methods { hash: string; } response: Account$ChatThemes + }, + 'mt_ping': { + params: { + ping_id: number + } + response: { + msg_id: number + ping_id: number + } } } \ No newline at end of file diff --git a/src/rpc.ts b/src/rpc.ts index c1dd8a5..a3bdad7 100644 --- a/src/rpc.ts +++ b/src/rpc.ts @@ -80,6 +80,7 @@ export class RPC { authKeyAuxHash?: any lastMessageId?: any seqNo: number + pingId: number constructor({ api_id, api_hash, initConnectionParams, dc, storage, updates }: { api_id: number @@ -107,6 +108,7 @@ export class RPC { this.newNonce = new Uint8Array() this.serverNonce = new Uint8Array() this.seqNo = 0 + this.pingId = Date.now() this.handleTransportOpen = this.handleTransportOpen.bind(this); this.handleTransportError = this.handleTransportError.bind(this); @@ -212,8 +214,13 @@ export class RPC { this.isAuth = true; this.sendWaitMessages(); - // This request is necessary to ensure that you start interacting with the server. If we have not made any request, the server will not send us updates. - this.ping() + // This request is necessary to ensure that you start interacting with the server. + // If we have not made any request, the server will not send us updates. + await this.getConfig() + + setTimeout(() => { + this.ping() + }, 5000).unref() } else { this.nonce = getRandomBytes(16); @@ -745,7 +752,7 @@ export class RPC { this.sendAcks(); } - call(method: T | string, params?: Methods[T]["params"]): Promise { + call(method: T, params?: Methods[T]["params"]): Promise { if (!this.isReady) { return new Promise((resolve, reject) => { this.messagesWaitAuth.push({ @@ -961,10 +968,24 @@ export class RPC { return this.storage.get(`${this.dc.id}${key}`); } + getConfig() { + debug("try to get server config after opening the connection") + + return this.call("help.getConfig") + .then(config => { + debug("get config after open connection %j", config) + }) + .catch(err => { + debug("fail to get config after open connection err=%s err_data=%j", String(err), JSON.stringify(err)) + }) + } + ping() { this.pongTimer = setTimeout(this.reconnect, this.pongTimeout).unref() + + debugger - this.call("help.getConfig") + this.call("mt_ping", { ping_id: this.pingId++, }) .then(this.pong) .catch(this.pongError) .finally(this.schedulePing)