@mtkruto/node 0.70.0 → 0.71.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/_dnt.polyfills.d.ts +13 -13
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +11 -11
- package/esm/client/0_abortable_loop.d.ts +1 -1
- package/esm/client/0_abortable_loop.d.ts.map +1 -1
- package/esm/client/0_abortable_loop.js +2 -2
- package/esm/client/0_client_abstract.d.ts +1 -0
- package/esm/client/0_client_abstract.d.ts.map +1 -1
- package/esm/client/0_client_abstract.js +3 -0
- package/esm/client/2_client_encrypted.d.ts.map +1 -1
- package/esm/client/2_client_encrypted.js +26 -23
- package/esm/client/2_network_statistics_manager.d.ts +2 -2
- package/esm/client/2_network_statistics_manager.d.ts.map +1 -1
- package/esm/client/2_network_statistics_manager.js +30 -4
- package/esm/client/2_update_manager.js +1 -1
- package/esm/client/5_client.js +9 -9
- package/esm/session/1_session.d.ts +1 -0
- package/esm/session/1_session.d.ts.map +1 -1
- package/esm/session/1_session.js +3 -0
- package/esm/session/2_session_encrypted.d.ts +1 -1
- package/esm/session/2_session_encrypted.d.ts.map +1 -1
- package/esm/session/2_session_encrypted.js +153 -89
- package/esm/tl/2_telegram.d.ts +1 -1
- package/esm/tl/2_telegram.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/_dnt.polyfills.d.ts +13 -13
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +11 -11
- package/script/client/0_abortable_loop.d.ts +1 -1
- package/script/client/0_abortable_loop.d.ts.map +1 -1
- package/script/client/0_abortable_loop.js +2 -2
- package/script/client/0_client_abstract.d.ts +1 -0
- package/script/client/0_client_abstract.d.ts.map +1 -1
- package/script/client/0_client_abstract.js +3 -0
- package/script/client/2_client_encrypted.d.ts.map +1 -1
- package/script/client/2_client_encrypted.js +26 -23
- package/script/client/2_network_statistics_manager.d.ts +2 -2
- package/script/client/2_network_statistics_manager.d.ts.map +1 -1
- package/script/client/2_network_statistics_manager.js +30 -4
- package/script/client/2_update_manager.js +1 -1
- package/script/client/5_client.js +9 -9
- package/script/session/1_session.d.ts +1 -0
- package/script/session/1_session.d.ts.map +1 -1
- package/script/session/1_session.js +3 -0
- package/script/session/2_session_encrypted.d.ts +1 -1
- package/script/session/2_session_encrypted.d.ts.map +1 -1
- package/script/session/2_session_encrypted.js +153 -89
- package/script/tl/2_telegram.d.ts +1 -1
- package/script/tl/2_telegram.d.ts.map +1 -1
|
@@ -31,21 +31,27 @@ const GZIP_PACKED = 0x3072CFA1;
|
|
|
31
31
|
const RPC_RESULT = 0xF35C6D01;
|
|
32
32
|
const RPC_ERROR = Mtproto.schema.definitions["rpc_error"][0];
|
|
33
33
|
export class SessionEncrypted extends Session {
|
|
34
|
+
static #TGCRYPTO_INITED = false;
|
|
34
35
|
#id = getRandomId();
|
|
36
|
+
handlers = {};
|
|
37
|
+
#L;
|
|
38
|
+
#LsendLoop;
|
|
39
|
+
#LreceiveLoop;
|
|
40
|
+
#LpingLoop;
|
|
35
41
|
#authKey = new Uint8Array();
|
|
36
42
|
#authKeyId = 0n;
|
|
37
|
-
|
|
43
|
+
#sentMessages = new Set();
|
|
44
|
+
#pendingMessages = new Array();
|
|
45
|
+
#containers = new LruCache(20_000);
|
|
46
|
+
#pendingPings = new Map();
|
|
38
47
|
#toAcknowledge = new Array();
|
|
39
|
-
#pendingMessages = new Set();
|
|
40
|
-
#pendingContainers = new LruCache(20_000);
|
|
41
48
|
#pendingAcks = new LruCache(100);
|
|
42
|
-
#pendingPings = new Map();
|
|
43
|
-
#L;
|
|
44
|
-
static #TGCRYPTO_INITED = false;
|
|
45
49
|
constructor(dc, params) {
|
|
46
50
|
super(dc, params);
|
|
47
51
|
const L = this.#L = getLogger("SessionEncrypted").client(id++);
|
|
48
|
-
this.#
|
|
52
|
+
this.#LsendLoop = L.branch("sendLoop");
|
|
53
|
+
this.#LreceiveLoop = L.branch("receiveLoop");
|
|
54
|
+
this.#LpingLoop = L.branch("pingLoop");
|
|
49
55
|
}
|
|
50
56
|
async setAuthKey(key) {
|
|
51
57
|
const hash = await sha1(key);
|
|
@@ -65,13 +71,16 @@ export class SessionEncrypted extends Session {
|
|
|
65
71
|
SessionEncrypted.#TGCRYPTO_INITED = true;
|
|
66
72
|
}
|
|
67
73
|
this.#receiveLoop.start();
|
|
74
|
+
this.#sendLoop.start();
|
|
68
75
|
this.#pingLoop.start();
|
|
76
|
+
this.#awakeSendLoop?.();
|
|
69
77
|
}
|
|
70
78
|
disconnect() {
|
|
71
79
|
super.disconnect();
|
|
72
80
|
this.state.reset();
|
|
73
81
|
this.#id = getRandomId();
|
|
74
|
-
this.#
|
|
82
|
+
this.#pingLoop.abort();
|
|
83
|
+
this.#awakeSendLoop?.();
|
|
75
84
|
this.#rejectAllPending(new ConnectionError("Not connected."));
|
|
76
85
|
}
|
|
77
86
|
#assertNotDisconnected() {
|
|
@@ -88,27 +97,24 @@ export class SessionEncrypted extends Session {
|
|
|
88
97
|
this.#rejectAllPending(new SessionError("Session invalidated."));
|
|
89
98
|
}
|
|
90
99
|
#rejectAllPending(reason) {
|
|
91
|
-
for (const id of this.#
|
|
100
|
+
for (const id of this.#sentMessages) {
|
|
92
101
|
this.#onMessageFailed(id, reason);
|
|
93
102
|
}
|
|
94
|
-
this.#pendingMessages.clear();
|
|
95
103
|
for (const pendingPing of this.#pendingPings.values()) {
|
|
96
|
-
pendingPing.reject(reason);
|
|
104
|
+
pendingPing.promiseWithResolvers.reject(reason);
|
|
97
105
|
}
|
|
106
|
+
this.#sentMessages.clear();
|
|
98
107
|
this.#pendingPings.clear();
|
|
99
|
-
this.#
|
|
108
|
+
this.#containers.clear();
|
|
100
109
|
}
|
|
101
110
|
#onMessageFailed(id, reason) {
|
|
102
|
-
this.#
|
|
103
|
-
const
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
drop(this.#resendPendingPing(pendingPing));
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
pendingPing.reject(reason);
|
|
111
|
+
this.#sentMessages.delete(id);
|
|
112
|
+
const pendingContainer = this.#containers.get(id);
|
|
113
|
+
if (pendingContainer) {
|
|
114
|
+
for (const id of pendingContainer) {
|
|
115
|
+
this.#onMessageFailed(id, reason);
|
|
111
116
|
}
|
|
117
|
+
this.#containers.delete(id);
|
|
112
118
|
return;
|
|
113
119
|
}
|
|
114
120
|
const pendingAck = this.#pendingAcks.get(id);
|
|
@@ -119,12 +125,15 @@ export class SessionEncrypted extends Session {
|
|
|
119
125
|
this.#pendingAcks.delete(id);
|
|
120
126
|
return;
|
|
121
127
|
}
|
|
122
|
-
const
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
128
|
+
const pendingPing = this.#pendingPings.get(id);
|
|
129
|
+
if (pendingPing) {
|
|
130
|
+
this.#pendingPings.delete(id);
|
|
131
|
+
if (reason instanceof SessionError) {
|
|
132
|
+
drop(this.#resendPendingPing(pendingPing));
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
pendingPing.promiseWithResolvers.reject(reason);
|
|
126
136
|
}
|
|
127
|
-
this.#pendingContainers.delete(id);
|
|
128
137
|
return;
|
|
129
138
|
}
|
|
130
139
|
// message was not sent by us
|
|
@@ -139,41 +148,10 @@ export class SessionEncrypted extends Session {
|
|
|
139
148
|
await super.waitUntilConnected();
|
|
140
149
|
}
|
|
141
150
|
this.#assertNotDisconnected();
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
msg_id,
|
|
147
|
-
seqno,
|
|
148
|
-
body,
|
|
149
|
-
};
|
|
150
|
-
if (this.#toAcknowledge.length) {
|
|
151
|
-
const msg_ids = this.#toAcknowledge.splice(0, 8192);
|
|
152
|
-
const ack = {
|
|
153
|
-
_: "message",
|
|
154
|
-
msg_id: this.state.nextMessageId(),
|
|
155
|
-
seqno: this.state.nextSeqNo(false),
|
|
156
|
-
body: Mtproto.serializeObject({ _: "msgs_ack", msg_ids }),
|
|
157
|
-
};
|
|
158
|
-
this.#pendingAcks.set(ack.msg_id, msg_ids);
|
|
159
|
-
message = {
|
|
160
|
-
_: "message",
|
|
161
|
-
msg_id: this.state.nextMessageId(),
|
|
162
|
-
seqno: this.state.nextSeqNo(false),
|
|
163
|
-
body: {
|
|
164
|
-
_: "msg_container",
|
|
165
|
-
messages: [message, ack],
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
this.#L.out(message);
|
|
170
|
-
const payload = await this.#encryptMessage(message);
|
|
171
|
-
await this.transport.transport.send(payload);
|
|
172
|
-
this.#pendingMessages.add(msg_id);
|
|
173
|
-
if (!(message.body instanceof Uint8Array)) {
|
|
174
|
-
this.#pendingContainers.set(message.msg_id, message.body.messages.map((v) => v.msg_id));
|
|
175
|
-
}
|
|
176
|
-
return msg_id;
|
|
151
|
+
const pendingMessage = { body, promiseWithResolvers: Promise.withResolvers() };
|
|
152
|
+
this.#pendingMessages.push(pendingMessage);
|
|
153
|
+
this.#awakeSendLoop?.();
|
|
154
|
+
return await pendingMessage.promiseWithResolvers.promise;
|
|
177
155
|
}
|
|
178
156
|
async #receive() {
|
|
179
157
|
this.#assertNotDisconnected();
|
|
@@ -226,19 +204,98 @@ export class SessionEncrypted extends Session {
|
|
|
226
204
|
const _sessionId_ = plainReader.readInt64(false);
|
|
227
205
|
return deserializeMessage(plainReader);
|
|
228
206
|
}
|
|
207
|
+
//// SEND LOOP ////
|
|
208
|
+
#awakeSendLoop;
|
|
209
|
+
#sendLoop = new AbortableLoop(this.#sendLoopBody.bind(this), (err) => {
|
|
210
|
+
this.#LsendLoop.error("unhandled receive loop error:", err);
|
|
211
|
+
});
|
|
212
|
+
async #sendLoopBody(loop, signal) {
|
|
213
|
+
if (!this.connected) {
|
|
214
|
+
this.#LsendLoop.debug("aborting as not connected");
|
|
215
|
+
loop.abort();
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
const pendingMessage = this.#pendingMessages.shift();
|
|
219
|
+
if (pendingMessage === undefined) {
|
|
220
|
+
this.#LsendLoop.debug("no pending messages");
|
|
221
|
+
return await new Promise((resolve) => {
|
|
222
|
+
const onAbort = () => {
|
|
223
|
+
this.#LsendLoop.debug("got aborted while sleeping");
|
|
224
|
+
resolve();
|
|
225
|
+
};
|
|
226
|
+
signal.addEventListener("abort", onAbort);
|
|
227
|
+
this.#awakeSendLoop = () => {
|
|
228
|
+
this.#LsendLoop.debug("got awaken");
|
|
229
|
+
resolve();
|
|
230
|
+
signal.removeEventListener("abort", onAbort);
|
|
231
|
+
};
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
const msg_id = this.state.nextMessageId();
|
|
235
|
+
const seqno = this.state.nextSeqNo(true);
|
|
236
|
+
let message = {
|
|
237
|
+
_: "message",
|
|
238
|
+
msg_id,
|
|
239
|
+
seqno,
|
|
240
|
+
body: pendingMessage.body,
|
|
241
|
+
};
|
|
242
|
+
this.#LsendLoop.debug("msg_id =", msg_id, "seqno =", seqno);
|
|
243
|
+
if (this.#toAcknowledge.length) {
|
|
244
|
+
const msg_ids = this.#toAcknowledge.splice(0, 8192);
|
|
245
|
+
this.#LsendLoop.debug("acknowledging", msg_ids.length, "message(s) while sending this one");
|
|
246
|
+
const ack = {
|
|
247
|
+
_: "message",
|
|
248
|
+
msg_id: this.state.nextMessageId(),
|
|
249
|
+
seqno: this.state.nextSeqNo(false),
|
|
250
|
+
body: Mtproto.serializeObject({ _: "msgs_ack", msg_ids }),
|
|
251
|
+
};
|
|
252
|
+
this.#LsendLoop.debug("msgs_ack msg_id =", ack.msg_id, "seqno =", seqno);
|
|
253
|
+
this.#pendingAcks.set(ack.msg_id, msg_ids);
|
|
254
|
+
message = {
|
|
255
|
+
_: "message",
|
|
256
|
+
msg_id: this.state.nextMessageId(),
|
|
257
|
+
seqno: this.state.nextSeqNo(false),
|
|
258
|
+
body: {
|
|
259
|
+
_: "msg_container",
|
|
260
|
+
messages: [message, ack],
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
this.#LsendLoop.debug("container msg_id =", message.msg_id, "seqno =", message.seqno);
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
const payload = await this.#encryptMessage(message);
|
|
267
|
+
await this.transport.transport.send(payload);
|
|
268
|
+
pendingMessage.promiseWithResolvers.resolve(msg_id);
|
|
269
|
+
}
|
|
270
|
+
catch (err) {
|
|
271
|
+
pendingMessage.promiseWithResolvers.reject(err);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
this.#LsendLoop.out(message);
|
|
275
|
+
this.#sentMessages.add(msg_id);
|
|
276
|
+
if (!(message.body instanceof Uint8Array)) {
|
|
277
|
+
const msg_ids = message.body.messages.map((v) => v.msg_id);
|
|
278
|
+
this.#LsendLoop.debug("sent container", message.msg_id, "with messages", ...msg_ids);
|
|
279
|
+
this.#containers.set(message.msg_id, msg_ids);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
this.#LsendLoop.debug("sent message", message.msg_id);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
229
285
|
//// RECEIVE LOOP ////
|
|
230
286
|
#receiveLoop = new AbortableLoop(this.#receiveLoopBody.bind(this), (err) => {
|
|
231
|
-
this.#
|
|
287
|
+
this.#LreceiveLoop.error("unhandled receive loop error:", err);
|
|
232
288
|
});
|
|
233
|
-
async #receiveLoopBody() {
|
|
289
|
+
async #receiveLoopBody(loop) {
|
|
234
290
|
let message;
|
|
235
291
|
try {
|
|
236
292
|
message = await this.#receive();
|
|
237
293
|
}
|
|
238
294
|
catch (err) {
|
|
239
|
-
this.#
|
|
295
|
+
this.#LreceiveLoop.error("failed to receive message:", err);
|
|
240
296
|
if (!this.connected) {
|
|
241
|
-
this.#
|
|
297
|
+
this.#LreceiveLoop.debug("aborting as not connected");
|
|
298
|
+
loop.abort();
|
|
242
299
|
return;
|
|
243
300
|
}
|
|
244
301
|
else {
|
|
@@ -247,29 +304,33 @@ export class SessionEncrypted extends Session {
|
|
|
247
304
|
}
|
|
248
305
|
try {
|
|
249
306
|
if (message.body instanceof Uint8Array) {
|
|
250
|
-
this.#onMessage(message.msg_id, message.body);
|
|
307
|
+
this.#onMessage(message.msg_id, message.body, null);
|
|
251
308
|
}
|
|
252
309
|
else {
|
|
253
310
|
this.#onMessageContainer(message.msg_id, message.body);
|
|
254
311
|
}
|
|
255
312
|
}
|
|
256
313
|
catch (err) {
|
|
257
|
-
this.#
|
|
314
|
+
this.#LreceiveLoop.error("failed to handle message:", err);
|
|
258
315
|
}
|
|
259
316
|
}
|
|
260
317
|
//// RECEIVE LOOP HANDLERS ////
|
|
261
|
-
async #onMessage(msgId, body) {
|
|
318
|
+
async #onMessage(msgId, body, containerId) {
|
|
319
|
+
this.#LreceiveLoop.debug("received message with ID", msgId, "and size", body.length, "inside", ...(containerId === null ? ["no container"] : ["container", containerId]));
|
|
320
|
+
const logger = this.#LreceiveLoop.branch(msgId + "");
|
|
262
321
|
let reader = new TLReader(body);
|
|
263
322
|
let id = reader.readInt32(false);
|
|
264
323
|
if (id === GZIP_PACKED) {
|
|
324
|
+
logger.debug("unpacking compressed body");
|
|
265
325
|
reader = new TLReader(await gunzip(reader.readBytes()));
|
|
266
326
|
id = reader.readInt32(false);
|
|
267
327
|
}
|
|
268
328
|
if (id === RPC_RESULT) {
|
|
269
|
-
this.#onRpcResult(msgId, reader.buffer);
|
|
329
|
+
this.#onRpcResult(msgId, reader.buffer, logger);
|
|
270
330
|
return;
|
|
271
331
|
}
|
|
272
332
|
if (!Mtproto.schema.identifierToName[id]) {
|
|
333
|
+
logger.debug("identified body as a non-MTProto constructor");
|
|
273
334
|
reader.unreadInt32();
|
|
274
335
|
this.handlers.onUpdate?.(reader.buffer);
|
|
275
336
|
return;
|
|
@@ -280,10 +341,10 @@ export class SessionEncrypted extends Session {
|
|
|
280
341
|
type = await Mtproto.deserializeType(X, reader);
|
|
281
342
|
}
|
|
282
343
|
catch (err) {
|
|
283
|
-
|
|
344
|
+
logger.error("failed to deserialize MTProto type:", err);
|
|
284
345
|
return;
|
|
285
346
|
}
|
|
286
|
-
|
|
347
|
+
logger.debug("received", repr(type));
|
|
287
348
|
if (Mtproto.is("new_session_created", type)) {
|
|
288
349
|
this.#onNewSessionCreated(msgId, type);
|
|
289
350
|
}
|
|
@@ -294,24 +355,26 @@ export class SessionEncrypted extends Session {
|
|
|
294
355
|
this.#onBadServerSalt(type);
|
|
295
356
|
}
|
|
296
357
|
else if (Mtproto.is("bad_msg_notification", type)) {
|
|
297
|
-
await this.#onBadMsgNotification(msgId, type);
|
|
358
|
+
await this.#onBadMsgNotification(msgId, type, logger);
|
|
298
359
|
}
|
|
299
360
|
else if (Mtproto.is("msg_detailed_info", type)) {
|
|
300
|
-
this.#onMsgDetailedInfo(type);
|
|
361
|
+
this.#onMsgDetailedInfo(type, logger);
|
|
301
362
|
}
|
|
302
363
|
else if (Mtproto.is("msg_new_detailed_info", type)) {
|
|
303
|
-
this.#onMsgNewDetailedInfo(type);
|
|
364
|
+
this.#onMsgNewDetailedInfo(type, logger);
|
|
304
365
|
}
|
|
305
366
|
else {
|
|
306
|
-
|
|
367
|
+
logger.warning(`unhandled MTProto type: ${repr(type)}`);
|
|
307
368
|
}
|
|
308
369
|
}
|
|
309
|
-
async #onRpcResult(msgId, body) {
|
|
370
|
+
async #onRpcResult(msgId, body, logger) {
|
|
371
|
+
logger.debug("received rpc_result");
|
|
310
372
|
this.#toAcknowledge.push(msgId);
|
|
311
373
|
let reader = new TLReader(body);
|
|
312
374
|
const reqMsgId = reader.readInt64();
|
|
313
375
|
let id = reader.readInt32(false);
|
|
314
376
|
if (id === GZIP_PACKED) {
|
|
377
|
+
logger.debug("unpacking compressed rpc_result");
|
|
315
378
|
reader = new TLReader(await gunzip(reader.readBytes()));
|
|
316
379
|
id = reader.readInt32(false);
|
|
317
380
|
reader.unreadInt32();
|
|
@@ -320,6 +383,7 @@ export class SessionEncrypted extends Session {
|
|
|
320
383
|
reader.unreadInt32();
|
|
321
384
|
}
|
|
322
385
|
if (id === RPC_ERROR) {
|
|
386
|
+
logger.debug("received rpc_error from message", msgId);
|
|
323
387
|
const error = await Mtproto.deserializeType("rpc_error", reader);
|
|
324
388
|
this.handlers.onRpcError?.(reqMsgId, error);
|
|
325
389
|
}
|
|
@@ -327,13 +391,15 @@ export class SessionEncrypted extends Session {
|
|
|
327
391
|
this.handlers.onRpcResult?.(reqMsgId, reader.buffer);
|
|
328
392
|
}
|
|
329
393
|
}
|
|
330
|
-
#onMsgDetailedInfo(msgDetailedInfo) {
|
|
394
|
+
#onMsgDetailedInfo(msgDetailedInfo, logger) {
|
|
395
|
+
logger.debug("scheduling the acknowledgement of", msgDetailedInfo.answer_msg_id, "because of", msgDetailedInfo._);
|
|
331
396
|
this.#toAcknowledge.push(msgDetailedInfo.answer_msg_id);
|
|
332
397
|
}
|
|
333
|
-
#onMsgNewDetailedInfo(msgNewDetailedInfo) {
|
|
398
|
+
#onMsgNewDetailedInfo(msgNewDetailedInfo, logger) {
|
|
399
|
+
logger.debug("scheduling the acknowledgement of", msgNewDetailedInfo.answer_msg_id, "because of", msgNewDetailedInfo._);
|
|
334
400
|
this.#toAcknowledge.push(msgNewDetailedInfo.answer_msg_id);
|
|
335
401
|
}
|
|
336
|
-
async #onBadMsgNotification(msgId, badMsgNotification) {
|
|
402
|
+
async #onBadMsgNotification(msgId, badMsgNotification, logger) {
|
|
337
403
|
let low = false;
|
|
338
404
|
switch (badMsgNotification.error_code) {
|
|
339
405
|
case 16: // message ID too low
|
|
@@ -343,11 +409,12 @@ export class SessionEncrypted extends Session {
|
|
|
343
409
|
this.state.timeDifference = Math.abs(toUnixTimestamp(new Date()) - Number(msgId >> 32n));
|
|
344
410
|
if (!low) {
|
|
345
411
|
this.state.timeDifference = -this.state.timeDifference;
|
|
412
|
+
logger.debug("resetting time difference to", -this.state.timeDifference, "because the ID of the message", badMsgNotification.bad_msg_id, "was too high");
|
|
346
413
|
await this.#invalidateSession("message ID too high");
|
|
347
414
|
return;
|
|
348
415
|
}
|
|
349
416
|
else {
|
|
350
|
-
|
|
417
|
+
logger.debug("resending message", badMsgNotification.bad_msg_id, "because its ID was too low");
|
|
351
418
|
}
|
|
352
419
|
break;
|
|
353
420
|
case 48: // bad server salt
|
|
@@ -368,7 +435,7 @@ export class SessionEncrypted extends Session {
|
|
|
368
435
|
this.#toAcknowledge.push(msgId);
|
|
369
436
|
const pendingPing = this.#pendingPings.get(pong.msg_id);
|
|
370
437
|
if (pendingPing) {
|
|
371
|
-
pendingPing.resolve(pong);
|
|
438
|
+
pendingPing.promiseWithResolvers.resolve(pong);
|
|
372
439
|
this.#pendingPings.delete(pong.msg_id);
|
|
373
440
|
}
|
|
374
441
|
else {
|
|
@@ -381,9 +448,10 @@ export class SessionEncrypted extends Session {
|
|
|
381
448
|
this.#toAcknowledge.push(msgId);
|
|
382
449
|
}
|
|
383
450
|
#onMessageContainer(msgId, msgContainer) {
|
|
451
|
+
this.#LreceiveLoop.debug("received container with ID", msgId, "and", msgContainer.messages.length, "message(s)");
|
|
384
452
|
for (const message of msgContainer.messages) {
|
|
385
453
|
if (message.body instanceof Uint8Array) {
|
|
386
|
-
this.#onMessage(message.msg_id, message.body);
|
|
454
|
+
this.#onMessage(message.msg_id, message.body, msgId);
|
|
387
455
|
}
|
|
388
456
|
else {
|
|
389
457
|
this.#onMessageContainer(msgId, message.body);
|
|
@@ -392,12 +460,10 @@ export class SessionEncrypted extends Session {
|
|
|
392
460
|
}
|
|
393
461
|
//// PING LOOP ////
|
|
394
462
|
#pingInterval = 56 * SECOND;
|
|
395
|
-
#pingLoopAbortController;
|
|
396
|
-
#LpingLoop;
|
|
397
463
|
#pingLoop = new AbortableLoop(this.#pingLoopBody.bind(this), (err) => {
|
|
398
464
|
this.#LpingLoop.error(err);
|
|
399
465
|
});
|
|
400
|
-
async #pingLoopBody(signal) {
|
|
466
|
+
async #pingLoopBody(_loop, signal) {
|
|
401
467
|
let timeElapsed = 0;
|
|
402
468
|
await delay(Math.max(0, this.#pingInterval - timeElapsed), { signal });
|
|
403
469
|
if (!this.connected) {
|
|
@@ -417,9 +483,7 @@ export class SessionEncrypted extends Session {
|
|
|
417
483
|
const ping_id = getRandomId();
|
|
418
484
|
const call = { _: "ping_delay_disconnect", ping_id, disconnect_delay };
|
|
419
485
|
const messageId = await this.send(Mtproto.serializeObject(call));
|
|
420
|
-
|
|
421
|
-
this.#pendingPings.set(messageId, { call, resolve, reject });
|
|
422
|
-
});
|
|
486
|
+
this.#pendingPings.set(messageId, { call, promiseWithResolvers: Promise.withResolvers() });
|
|
423
487
|
}
|
|
424
488
|
async #resendPendingPing(pendingPing) {
|
|
425
489
|
try {
|
|
@@ -427,7 +491,7 @@ export class SessionEncrypted extends Session {
|
|
|
427
491
|
this.#pendingPings.set(messageId, pendingPing);
|
|
428
492
|
}
|
|
429
493
|
catch (err) {
|
|
430
|
-
pendingPing.reject(err);
|
|
494
|
+
pendingPing.promiseWithResolvers.reject(err);
|
|
431
495
|
}
|
|
432
496
|
}
|
|
433
497
|
}
|
package/esm/tl/2_telegram.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ import * as Api from "./1_telegram_api.js";
|
|
|
22
22
|
export * from "./1_telegram_api.js";
|
|
23
23
|
export type DeserializedType = boolean | number | bigint | string | Uint8Array | Api.AnyType | Array<DeserializedType>;
|
|
24
24
|
export declare function deserializeType<T extends (keyof Api.Types) | "X" | string>(name: T, bufferOrReader: TLReader | Uint8Array): Promise<T extends keyof Api.Types ? Api.Types[T] : DeserializedType>;
|
|
25
|
-
export declare function serializeObject(object: Api.AnyObject): Uint8Array
|
|
25
|
+
export declare function serializeObject(object: Api.AnyObject): Uint8Array<ArrayBuffer>;
|
|
26
26
|
export declare function isValidObject(object: any): object is Api.AnyType;
|
|
27
27
|
export declare function assertIsValidObject(object: any): asserts object is Api.AnyType;
|
|
28
28
|
export declare function is<S extends keyof (Api.Types & Api.Functions)>(name: S, value: unknown): value is S extends keyof Api.Types ? Api.Types[S] : S extends keyof Api.Functions ? Api.Functions[S] : never;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"2_telegram.d.ts","sourceRoot":"","sources":["../../src/tl/2_telegram.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI5C,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAG3C,cAAc,qBAAqB,CAAC;AAEpC,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;AAEvH,wBAAsB,eAAe,CAAC,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,cAAc,EAAE,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAGtM;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,SAAS,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"2_telegram.d.ts","sourceRoot":"","sources":["../../src/tl/2_telegram.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAI5C,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAG3C,cAAc,qBAAqB,CAAC;AAEpC,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,gBAAgB,CAAC,CAAC;AAEvH,wBAAsB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AC,MAAM,EAAE,MAAM,GAAG,MAAM,CAWrD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAQ7E;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,GAAG,CAAC,SAAS,GAAG,GAAG,CAAC,IAAI,CAUlE"}
|
package/package.json
CHANGED
|
@@ -11,6 +11,19 @@ declare global {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
export {};
|
|
14
|
+
declare global {
|
|
15
|
+
interface PromiseConstructor {
|
|
16
|
+
/**
|
|
17
|
+
* Creates a Promise that can be resolved or rejected using provided functions.
|
|
18
|
+
* @returns An object containing `promise` promise object, `resolve` and `reject` functions.
|
|
19
|
+
*/
|
|
20
|
+
withResolvers<T>(): {
|
|
21
|
+
promise: Promise<T>;
|
|
22
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
23
|
+
reject: (reason?: any) => void;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
14
27
|
/**
|
|
15
28
|
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
16
29
|
* but instead of using npm to install additional dependencies,
|
|
@@ -110,17 +123,4 @@ interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyf
|
|
|
110
123
|
export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
|
|
111
124
|
export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
|
|
112
125
|
export declare let import_meta_ponyfill: ImportMetaPonyfill;
|
|
113
|
-
declare global {
|
|
114
|
-
interface PromiseConstructor {
|
|
115
|
-
/**
|
|
116
|
-
* Creates a Promise that can be resolved or rejected using provided functions.
|
|
117
|
-
* @returns An object containing `promise` promise object, `resolve` and `reject` functions.
|
|
118
|
-
*/
|
|
119
|
-
withResolvers<T>(): {
|
|
120
|
-
promise: Promise<T>;
|
|
121
|
-
resolve: (value: T | PromiseLike<T>) => void;
|
|
122
|
-
reject: (reason?: any) => void;
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
126
|
//# sourceMappingURL=_dnt.polyfills.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,gBAAgB;QACxB,SAAS,CAAC,CAAC,EACP,mBAAmB,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,GAC7F,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;QAEhB,SAAS,CAAC,CAAC,EAAE,CAAC,EACV,mBAAmB,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EAClE,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAC/B,OAAO,CAAC,EAAE,GAAG,GACd,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;KAC1B;CACF;AAoID,OAAO,EAAE,CAAC;AAAA,OAAO,CAAC,MAAM,CAAC;IACvB,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC;AACV;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;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AM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC"}
|
package/script/_dnt.polyfills.js
CHANGED
|
@@ -110,6 +110,17 @@ async function fromAsync(items, mapfn, thisArg) {
|
|
|
110
110
|
if (!Array.fromAsync) {
|
|
111
111
|
Array.fromAsync = fromAsync;
|
|
112
112
|
}
|
|
113
|
+
// https://github.com/tc39/proposal-promise-with-resolvers/blob/3a78801e073e99217dbeb2c43ba7212f3bdc8b83/polyfills.js#L1C1-L9C2
|
|
114
|
+
if (Promise.withResolvers === undefined) {
|
|
115
|
+
Promise.withResolvers = () => {
|
|
116
|
+
const out = {};
|
|
117
|
+
out.promise = new Promise((resolve_, reject_) => {
|
|
118
|
+
out.resolve = resolve_;
|
|
119
|
+
out.reject = reject_;
|
|
120
|
+
});
|
|
121
|
+
return out;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
113
124
|
/**
|
|
114
125
|
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
115
126
|
* but instead of using npm to install additional dependencies,
|
|
@@ -237,14 +248,3 @@ exports.import_meta_ponyfill = ((...args) => {
|
|
|
237
248
|
//@ts-ignore
|
|
238
249
|
return (0, exports.import_meta_ponyfill)(...args);
|
|
239
250
|
});
|
|
240
|
-
// https://github.com/tc39/proposal-promise-with-resolvers/blob/3a78801e073e99217dbeb2c43ba7212f3bdc8b83/polyfills.js#L1C1-L9C2
|
|
241
|
-
if (Promise.withResolvers === undefined) {
|
|
242
|
-
Promise.withResolvers = () => {
|
|
243
|
-
const out = {};
|
|
244
|
-
out.promise = new Promise((resolve_, reject_) => {
|
|
245
|
-
out.resolve = resolve_;
|
|
246
|
-
out.reject = reject_;
|
|
247
|
-
});
|
|
248
|
-
return out;
|
|
249
|
-
};
|
|
250
|
-
}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import { type MaybePromise } from "../1_utilities.js";
|
|
21
21
|
export declare class AbortableLoop {
|
|
22
22
|
#private;
|
|
23
|
-
constructor(body: (signal: AbortSignal) => MaybePromise<void>, onError: (err: unknown) => void);
|
|
23
|
+
constructor(body: (loop: AbortableLoop, signal: AbortSignal) => MaybePromise<void>, onError: (loop: AbortableLoop, err: unknown) => void);
|
|
24
24
|
abort(): void;
|
|
25
25
|
start(): void;
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"0_abortable_loop.d.ts","sourceRoot":"","sources":["../../src/client/0_abortable_loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAQ,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,aAAa;;gBAIZ,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI;
|
|
1
|
+
{"version":3,"file":"0_abortable_loop.d.ts","sourceRoot":"","sources":["../../src/client/0_abortable_loop.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAQ,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE5D,qBAAa,aAAa;;gBAIZ,IAAI,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,KAAK,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,aAAa,EAAE,GAAG,EAAE,OAAO,KAAK,IAAI;IAOxI,KAAK;IAIL,KAAK;CAiBN"}
|
|
@@ -40,11 +40,11 @@ class AbortableLoop {
|
|
|
40
40
|
const controller = this.#controller = new AbortController();
|
|
41
41
|
do {
|
|
42
42
|
try {
|
|
43
|
-
await this.#body(controller.signal);
|
|
43
|
+
await this.#body(this, controller.signal);
|
|
44
44
|
}
|
|
45
45
|
catch (err) {
|
|
46
46
|
if (!controller.signal.aborted) {
|
|
47
|
-
this.#onError(err);
|
|
47
|
+
this.#onError(this, err);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
} while (!controller.signal.aborted);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"0_client_abstract.d.ts","sourceRoot":"","sources":["../../src/client/0_client_abstract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,8BAAsB,cAAc;IAClC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,IAAI,EAAE,IAAI,EAAE,CAEX;IAED,IAAI,GAAG,IAAI,OAAO,CAEjB;IAED,IAAI,UAAU,CAAC,UAAU,EAAE,MAAM,EAEhC;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAEK,OAAO;IAIb,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,UAAU;IAIV,IAAI,kBAAkB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,SAAS,EAExE;IAED,IAAI,uBAAuB,CAAC,uBAAuB,EAAE,UAAU,CAAC,oBAAoB,CAAC,EAEpF;CACF"}
|
|
1
|
+
{"version":3,"file":"0_client_abstract.d.ts","sourceRoot":"","sources":["../../src/client/0_client_abstract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/C,8BAAsB,cAAc;IAClC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,IAAI,EAAE,IAAI,EAAE,CAEX;IAED,IAAI,GAAG,IAAI,OAAO,CAEjB;IAED,IAAI,UAAU,CAAC,UAAU,EAAE,MAAM,EAEhC;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAEK,OAAO;IAIb,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,UAAU;IAIV,IAAI,kBAAkB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,SAAS,EAExE;IAED,IAAI,uBAAuB,CAAC,uBAAuB,EAAE,UAAU,CAAC,oBAAoB,CAAC,EAEpF;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"2_client_encrypted.d.ts","sourceRoot":"","sources":["../../src/client/2_client_encrypted.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,GAAG,EAAE,OAAO,EAAK,MAAM,YAAY,CAAC;AAE7C,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAgB,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,OA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