diff --git a/package-lock.json b/package-lock.json index 97a6181..d333c57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,20 +1,20 @@ { "name": "mtproto-nodejs-client", - "version": "8.0.0", + "version": "8.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mtproto-nodejs-client", - "version": "8.0.0", + "version": "8.0.1", "license": "GPL-3.0", "dependencies": { "@types/aes-js": "^3.1.4", "@types/debug": "^4.1.12", "@types/lodash.debounce": "^4.0.9", - "@types/node": "^24.10.1", + "@types/node": "^24.10.2", "@types/pako": "^2.0.4", - "@typescript/native-preview": "^7.0.0-dev.20251113.1", + "@typescript/native-preview": "^7.0.0-dev.20251210.1", "aes-js": "3.1.2", "big-integer": "1.6.52", "debug": "4.4.3", @@ -58,9 +58,9 @@ "integrity": "sha512-iiUgKzV9AuaEkZqkOLDIvlQiL6ltuZd9tGcW3gwpnX8JbuiuhFlEGmmFXEXkN50Cvq7Os88IY2v0dkDqXYWVgA==" }, "node_modules/@types/node": { - "version": "24.10.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-24.10.1.tgz", - "integrity": "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==", + "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.16.0" @@ -73,27 +73,27 @@ "license": "MIT" }, "node_modules/@typescript/native-preview": { - "version": "7.0.0-dev.20251113.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview/-/native-preview-7.0.0-dev.20251113.1.tgz", - "integrity": "sha512-gxe+j1h5DSnP/rE2+4BGSzfKRg2RdmMtHlPX+oH1iLGOHTWLQ5IVtS7hW2IlGJY2Y1dXXDARh9wRYzePPXyh8g==", + "version": "7.0.0-dev.20251210.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview/-/native-preview-7.0.0-dev.20251210.1.tgz", + "integrity": "sha512-SiSRpp42K80X+qJKAi8qvjo2xMZIgJgROXCJo0MiZ8a6fjQK6IetRfUvwdApUsDltf/VaEc/j8v2Hiqp8SGhLQ==", "license": "Apache-2.0", "bin": { "tsgo": "bin/tsgo.js" }, "optionalDependencies": { - "@typescript/native-preview-darwin-arm64": "7.0.0-dev.20251113.1", - "@typescript/native-preview-darwin-x64": "7.0.0-dev.20251113.1", - "@typescript/native-preview-linux-arm": "7.0.0-dev.20251113.1", - "@typescript/native-preview-linux-arm64": "7.0.0-dev.20251113.1", - "@typescript/native-preview-linux-x64": "7.0.0-dev.20251113.1", - "@typescript/native-preview-win32-arm64": "7.0.0-dev.20251113.1", - "@typescript/native-preview-win32-x64": "7.0.0-dev.20251113.1" + "@typescript/native-preview-darwin-arm64": "7.0.0-dev.20251210.1", + "@typescript/native-preview-darwin-x64": "7.0.0-dev.20251210.1", + "@typescript/native-preview-linux-arm": "7.0.0-dev.20251210.1", + "@typescript/native-preview-linux-arm64": "7.0.0-dev.20251210.1", + "@typescript/native-preview-linux-x64": "7.0.0-dev.20251210.1", + "@typescript/native-preview-win32-arm64": "7.0.0-dev.20251210.1", + "@typescript/native-preview-win32-x64": "7.0.0-dev.20251210.1" } }, "node_modules/@typescript/native-preview-darwin-arm64": { - "version": "7.0.0-dev.20251113.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-darwin-arm64/-/native-preview-darwin-arm64-7.0.0-dev.20251113.1.tgz", - "integrity": "sha512-ArzjtsMWWUSRnqv/C7p+Lv7SJbL9EDGBPDgBvyI+xIcTqyD9WW2sMStjc1jTwWsimmQXzQQ8jZYpf+xSGj5boQ==", + "version": "7.0.0-dev.20251210.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-darwin-arm64/-/native-preview-darwin-arm64-7.0.0-dev.20251210.1.tgz", + "integrity": "sha512-6FLhFMAdaW/JMzTPqaIxVTgCFhMQY2v88qVGLUmcf9coCJx5plxuY0zxzXaLrvQulGnDurIKZMW5tBGmQy4Buw==", "cpu": [ "arm64" ], @@ -104,9 +104,9 @@ ] }, "node_modules/@typescript/native-preview-darwin-x64": { - "version": "7.0.0-dev.20251113.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-darwin-x64/-/native-preview-darwin-x64-7.0.0-dev.20251113.1.tgz", - "integrity": "sha512-airwguNehqwQhr6LjDcJ0LXfBv2GaOJkpj6fzxMK9gWlrx/tVwvRFoazUesdOnR1DM6zSE4gy+2UROxGeumOSw==", + "version": "7.0.0-dev.20251210.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-darwin-x64/-/native-preview-darwin-x64-7.0.0-dev.20251210.1.tgz", + "integrity": "sha512-JrsZ913/ZyeoFDCVq+k4h0VUJHyqjT6te/IC8aMtLZQRkusQEX+57Anfr/BVXzWBa8+JwIXPGzllilw5dkrHNw==", "cpu": [ "x64" ], @@ -117,9 +117,9 @@ ] }, "node_modules/@typescript/native-preview-linux-arm": { - "version": "7.0.0-dev.20251113.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-arm/-/native-preview-linux-arm-7.0.0-dev.20251113.1.tgz", - "integrity": "sha512-lTYX9vskfbq3kq2+vpqu2fwJP68iZ4OuWHuGLMzS/AlQ1vzs535su/s6xhL8UuyRP+n10A9z2xHq7UJSOx8u1w==", + "version": "7.0.0-dev.20251210.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-arm/-/native-preview-linux-arm-7.0.0-dev.20251210.1.tgz", + "integrity": "sha512-v1hyGd8TWHaoRU8BJfGAdW6ML70TLUOB9+0Xeo30m3xHlOdO1zxunXa/FVhqzrChqzOkcty61PGe9tAPhrIh1w==", "cpu": [ "arm" ], @@ -130,9 +130,9 @@ ] }, "node_modules/@typescript/native-preview-linux-arm64": { - "version": "7.0.0-dev.20251113.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-arm64/-/native-preview-linux-arm64-7.0.0-dev.20251113.1.tgz", - "integrity": "sha512-EefJd94Hm2507bMQekjoaad32pjGQgldSNjD1UAp6P0EKsn2wZV7H9gxosbZwL3tgMY/HDrQoS1j240/qv528w==", + "version": "7.0.0-dev.20251210.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-arm64/-/native-preview-linux-arm64-7.0.0-dev.20251210.1.tgz", + "integrity": "sha512-GViH0JIkpEHCo04VYD/iAKqYjIB2uLXXtTmmLaImzBVd+h1dlKFgi2aOMi51mYnSefnbj7P7PeqIQNLKwi4NSQ==", "cpu": [ "arm64" ], @@ -143,9 +143,9 @@ ] }, "node_modules/@typescript/native-preview-linux-x64": { - "version": "7.0.0-dev.20251113.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-x64/-/native-preview-linux-x64-7.0.0-dev.20251113.1.tgz", - "integrity": "sha512-2VLSCSHgnb94BLLeb1LGYTMIRgbCWkpJa74U45Fi9W+ErTW5QJR+b/nzKAzeeL8/6vu5cfnW4Yf5pCU4d+IvTg==", + "version": "7.0.0-dev.20251210.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-linux-x64/-/native-preview-linux-x64-7.0.0-dev.20251210.1.tgz", + "integrity": "sha512-X6p2MrcRcYE9T+ecNHYZHFYew0t+k9Sc2GbyjbNB0+MJ/Lffp3aUH59dp+JASZoyOxugPwN+MCJ/kNzYqiK9vg==", "cpu": [ "x64" ], @@ -156,9 +156,9 @@ ] }, "node_modules/@typescript/native-preview-win32-arm64": { - "version": "7.0.0-dev.20251113.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-win32-arm64/-/native-preview-win32-arm64-7.0.0-dev.20251113.1.tgz", - "integrity": "sha512-byymVRxjqyQPBDpTxcfFprfNTN0e8RXE1VRmVrMU4kJeCxC9SRPQAZCIFw5bJKt74iic7Ixk0O+Ehjp+YlH/VQ==", + "version": "7.0.0-dev.20251210.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-win32-arm64/-/native-preview-win32-arm64-7.0.0-dev.20251210.1.tgz", + "integrity": "sha512-FewUZSh7d9YnX0j3hr+N+zQ5B54k4jsVpZp8QbuDduMtautxI18bNO+vL5oO86ezqLWbUnZajXV/61MGfpEtMg==", "cpu": [ "arm64" ], @@ -169,9 +169,9 @@ ] }, "node_modules/@typescript/native-preview-win32-x64": { - "version": "7.0.0-dev.20251113.1", - "resolved": "https://registry.npmjs.org/@typescript/native-preview-win32-x64/-/native-preview-win32-x64-7.0.0-dev.20251113.1.tgz", - "integrity": "sha512-H6dR8nmGmuKduG8kODnb5bRgsTScjJ7lLpG6cch+3MflNaIymMAiQsku2kWKtMiFp94wHgQIFk88ov2wG91FYw==", + "version": "7.0.0-dev.20251210.1", + "resolved": "https://registry.npmjs.org/@typescript/native-preview-win32-x64/-/native-preview-win32-x64-7.0.0-dev.20251210.1.tgz", + "integrity": "sha512-NdqTPzm/Ls3F1amP/e/akCuhY32mjBXT0NMQnYODgT9ltbdkk08b572Bp4GbdfRj9AiJxK70pqoNeZWw4e5fhg==", "cpu": [ "x64" ], diff --git a/package.json b/package.json index b49eb10..8ecee1f 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "license": "GPL-3.0", "dependencies": { - "@typescript/native-preview": "^7.0.0-dev.20251113.1", + "@typescript/native-preview": "^7.0.0-dev.20251210.1", "aes-js": "3.1.2", "big-integer": "1.6.52", "debug": "4.4.3", @@ -30,7 +30,7 @@ "@types/aes-js": "^3.1.4", "@types/debug": "^4.1.12", "@types/lodash.debounce": "^4.0.9", - "@types/node": "^24.10.1", + "@types/node": "^24.10.2", "@types/pako": "^2.0.4" }, "repository": { 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)