Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 38 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/mtptoto-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
29 changes: 25 additions & 4 deletions src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
authKeyAuxHash?: any
lastMessageId?: any
seqNo: number
pingId: number

constructor({ api_id, api_hash, initConnectionParams, dc, storage, updates }: {
api_id: number
Expand Down Expand Up @@ -107,6 +108,7 @@
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);
Expand Down Expand Up @@ -212,8 +214,13 @@
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);
Expand Down Expand Up @@ -557,7 +564,7 @@
message.reject(new Error(`'${message.method}' has Ack but missing a response`))
}
else {
this.call(message.method, message.params).then(message.resolve).catch(message.reject);

Check failure on line 567 in src/rpc.ts

View workflow job for this annotation

GitHub Actions / test

Argument of type 'string' is not assignable to parameter of type 'keyof Methods'.
}

this.messagesWaitResponse.delete(key)
Expand All @@ -565,7 +572,7 @@

for (let message of this.messagesWaitAuth) {
const { method, params, resolve, reject } = message;
this.call(method, params).then(resolve).catch(reject);

Check failure on line 575 in src/rpc.ts

View workflow job for this annotation

GitHub Actions / test

Argument of type 'string' is not assignable to parameter of type 'keyof Methods'.
}

this.messagesWaitAuth = [];
Expand Down Expand Up @@ -670,7 +677,7 @@
const waitMessage = this.messagesWaitResponse.get(message.bad_msg_id);

if (waitMessage) {
this.call(waitMessage.method, waitMessage.params)

Check failure on line 680 in src/rpc.ts

View workflow job for this annotation

GitHub Actions / test

Argument of type 'string' is not assignable to parameter of type 'keyof Methods'.
.then(waitMessage.resolve)
.catch(waitMessage.reject);
this.messagesWaitResponse.delete(message.bad_msg_id);
Expand Down Expand Up @@ -745,7 +752,7 @@
this.sendAcks();
}

call<T extends keyof Methods>(method: T | string, params?: Methods[T]["params"]): Promise<Methods[T]["response"]> {
call<T extends keyof Methods>(method: T, params?: Methods[T]["params"]): Promise<Methods[T]["response"]> {
if (!this.isReady) {
return new Promise((resolve, reject) => {
this.messagesWaitAuth.push({
Expand Down Expand Up @@ -961,10 +968,24 @@
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)
Expand Down
Loading