@mtkruto/node 0.2.23 → 0.2.30
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/3_types.d.ts +1 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +1 -0
- package/esm/client/0_html.d.ts.map +1 -1
- package/esm/client/0_html.js +3 -0
- package/esm/client/0_params.d.ts +5 -6
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/1_client_encrypted.d.ts.map +1 -1
- package/esm/client/1_client_encrypted.js +33 -24
- package/esm/client/3_message_manager.d.ts.map +1 -1
- package/esm/client/3_message_manager.js +14 -2
- package/esm/client/5_client.d.ts +22 -14
- package/esm/client/5_client.d.ts.map +1 -1
- package/esm/client/5_client.js +136 -76
- package/esm/tl/0_api.d.ts +175 -23
- package/esm/tl/0_api.d.ts.map +1 -1
- package/esm/tl/0_api.js +279 -91
- package/esm/types/0_failed_invitation.d.ts +19 -0
- package/esm/types/0_failed_invitation.d.ts.map +1 -1
- package/esm/types/0_failed_invitation.js +19 -0
- package/esm/types/0_message_entity.d.ts +1 -0
- package/esm/types/0_message_entity.d.ts.map +1 -1
- package/esm/types/0_message_entity.js +3 -2
- package/esm/types/2_reply_to.d.ts +35 -0
- package/esm/types/2_reply_to.d.ts.map +1 -0
- package/esm/types/2_reply_to.js +20 -0
- package/esm/types/3_join_request.d.ts +19 -0
- package/esm/types/3_join_request.d.ts.map +1 -1
- package/esm/types/3_join_request.js +19 -0
- package/package.json +1 -1
- package/script/3_types.d.ts +1 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +1 -0
- package/script/client/0_html.d.ts.map +1 -1
- package/script/client/0_html.js +3 -0
- package/script/client/0_params.d.ts +5 -6
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/1_client_encrypted.d.ts.map +1 -1
- package/script/client/1_client_encrypted.js +32 -23
- package/script/client/3_message_manager.d.ts.map +1 -1
- package/script/client/3_message_manager.js +14 -2
- package/script/client/5_client.d.ts +22 -14
- package/script/client/5_client.d.ts.map +1 -1
- package/script/client/5_client.js +136 -76
- package/script/tl/0_api.d.ts +175 -23
- package/script/tl/0_api.d.ts.map +1 -1
- package/script/tl/0_api.js +279 -91
- package/script/types/0_failed_invitation.d.ts +19 -0
- package/script/types/0_failed_invitation.d.ts.map +1 -1
- package/script/types/0_failed_invitation.js +19 -0
- package/script/types/0_message_entity.d.ts +1 -0
- package/script/types/0_message_entity.d.ts.map +1 -1
- package/script/types/0_message_entity.js +3 -2
- package/script/types/2_reply_to.d.ts +35 -0
- package/script/types/2_reply_to.d.ts.map +1 -0
- package/script/types/2_reply_to.js +21 -0
- package/script/types/3_join_request.d.ts +19 -0
- package/script/types/3_join_request.d.ts.map +1 -1
- package/script/types/3_join_request.js +19 -0
package/esm/client/5_client.js
CHANGED
|
@@ -28,7 +28,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
28
28
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
29
29
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
30
30
|
};
|
|
31
|
-
var _Client_instances, _a, _Client_client, _Client_guaranteeUpdateDelivery, _Client_updateManager, _Client_networkStatisticsManager, _Client_botInfoManager, _Client_fileManager, _Client_reactionManager, _Client_videoChatManager, _Client_businessConnectionManager, _Client_messageManager, _Client_storyManager, _Client_callbackQueryManager, _Client_inlineQueryManager, _Client_chatListManager, _Client_accountManager, _Client_paymentManager, _Client_storage_, _Client_messageStorage_, _Client_parseMode, _Client_apiId, _Client_apiHash, _Client_publicKeys, _Client_ignoreOutgoing, _Client_persistCache, _Client_cdn, _Client_LsignIn, _Client_LpingLoop, _Client_LhandleMigrationError, _Client_L$initConncetion, _Client_getApiId, _Client_getCdnConnectionPool, _Client_getCdnConnection, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_stateChangeHandler, _Client_storageInited, _Client_initStorage, _Client_connectMutex, _Client_lastConnect, _Client_connectionInited, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_getSelfId, _Client_pingLoopAbortController, _Client_pingInterval, _Client_lastUpdates, _Client_startPingLoop, _Client_pingLoop, _Client_invoke, _Client_handleInvokeError, _Client_getUserAccessHash, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_handleCtxUpdate, _Client_queueHandleCtxUpdate, _Client_handleUpdate, _Client_lastGetMe, _Client_getMe;
|
|
31
|
+
var _Client_instances, _a, _Client_client, _Client_guaranteeUpdateDelivery, _Client_updateManager, _Client_networkStatisticsManager, _Client_botInfoManager, _Client_fileManager, _Client_reactionManager, _Client_videoChatManager, _Client_businessConnectionManager, _Client_messageManager, _Client_storyManager, _Client_callbackQueryManager, _Client_inlineQueryManager, _Client_chatListManager, _Client_accountManager, _Client_paymentManager, _Client_storage_, _Client_messageStorage_, _Client_parseMode, _Client_apiId, _Client_apiHash, _Client_publicKeys, _Client_ignoreOutgoing, _Client_persistCache, _Client_cdn, _Client_L, _Client_LsignIn, _Client_LpingLoop, _Client_LhandleMigrationError, _Client_L$initConncetion, _Client_reconnecting, _Client_reconnect, _Client_getApiId, _Client_getCdnConnectionPool, _Client_getCdnConnection, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_stateChangeHandler, _Client_storageInited, _Client_initStorage, _Client_connectMutex, _Client_lastConnect, _Client_connectionInited, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_getSelfId, _Client_connectionInsuranceLoopStarted, _Client_connectionInsuranceLoopAbortController, _Client_startConnectionInsuranceLoop, _Client_connectionInsuranceLoop, _Client_pingLoopAbortController, _Client_pingInterval, _Client_lastUpdates, _Client_startPingLoop, _Client_pingLoop, _Client_invoke, _Client_handleInvokeError, _Client_getUserAccessHash, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_handleCtxUpdate, _Client_queueHandleCtxUpdate, _Client_handleUpdate, _Client_lastGetMe, _Client_getMe;
|
|
32
32
|
import { unreachable } from "../0_deps.js";
|
|
33
33
|
import { AccessError, ConnectionError, InputError } from "../0_errors.js";
|
|
34
34
|
import { cleanObject, drop, getLogger, getRandomId, minute, mustPrompt, mustPromptOneOf, Mutex, second, ZERO_CHANNEL_ID } from "../1_utilities.js";
|
|
@@ -151,16 +151,18 @@ export class Client extends Composer {
|
|
|
151
151
|
_Client_ignoreOutgoing.set(this, void 0);
|
|
152
152
|
_Client_persistCache.set(this, void 0);
|
|
153
153
|
_Client_cdn.set(this, void 0);
|
|
154
|
+
_Client_L.set(this, void 0);
|
|
154
155
|
_Client_LsignIn.set(this, void 0);
|
|
155
156
|
_Client_LpingLoop.set(this, void 0);
|
|
156
157
|
_Client_LhandleMigrationError.set(this, void 0);
|
|
157
158
|
_Client_L$initConncetion.set(this, void 0);
|
|
159
|
+
_Client_reconnecting.set(this, false);
|
|
158
160
|
_Client_constructContext.set(this, async (update) => {
|
|
159
161
|
const msg = "message" in update ? update.message : "editedMessage" in update ? update.editedMessage : "callbackQuery" in update ? update.callbackQuery.message : undefined;
|
|
160
162
|
const reactions = "messageInteractions" in update ? update.messageInteractions : undefined;
|
|
161
163
|
const mustGetMsg = () => {
|
|
162
164
|
if (msg !== undefined) {
|
|
163
|
-
return { chatId: msg.chat.id, messageId: msg.id, businessConnectionId: msg.businessConnectionId, senderId: (msg.from ?? msg.senderChat)?.id };
|
|
165
|
+
return { chatId: msg.chat.id, messageId: msg.id, businessConnectionId: msg.businessConnectionId, senderId: (msg.from ?? msg.senderChat)?.id, userId: msg.from?.id };
|
|
164
166
|
}
|
|
165
167
|
else if (reactions !== undefined) {
|
|
166
168
|
return { chatId: reactions.chatId, messageId: reactions.messageId };
|
|
@@ -200,11 +202,13 @@ export class Client extends Composer {
|
|
|
200
202
|
const chat = chat_ ?? msg?.chat;
|
|
201
203
|
const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "message" in update ? update.message.from : "editedMessage" in update ? update.editedMessage?.from : "chatMember" in update ? update.chatMember.from : "messageReactions" in update ? update.messageReactions.user : "preCheckoutQuery" in update ? update.preCheckoutQuery.from : "joinRequest" in update ? update.joinRequest.user : undefined;
|
|
202
204
|
const senderChat = msg?.senderChat;
|
|
203
|
-
const
|
|
205
|
+
const getReplyTo = (quote, chatId, messageId) => {
|
|
206
|
+
if ("story" in update) {
|
|
207
|
+
return { chatId: update.story.chat.id, storyId: update.story.id };
|
|
208
|
+
}
|
|
204
209
|
const isPrivate = chatId > 0;
|
|
205
210
|
const shouldQuote = quote === undefined ? !isPrivate : quote;
|
|
206
|
-
|
|
207
|
-
return replyToMessageId;
|
|
211
|
+
return shouldQuote ? { messageId } : undefined;
|
|
208
212
|
};
|
|
209
213
|
const me = "connectionState" in update ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : ("authorizationState" in update && !update.authorizationState.authorized) ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMe).call(this);
|
|
210
214
|
const context = {
|
|
@@ -220,73 +224,83 @@ export class Client extends Composer {
|
|
|
220
224
|
},
|
|
221
225
|
reply: (text, params) => {
|
|
222
226
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
223
|
-
const
|
|
224
|
-
return this.sendMessage(chatId, text, { ...params,
|
|
227
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
228
|
+
return this.sendMessage(chatId, text, { ...params, replyTo, businessConnectionId });
|
|
225
229
|
},
|
|
226
230
|
replyPoll: (question, options, params) => {
|
|
227
231
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
228
|
-
const
|
|
229
|
-
return this.sendPoll(chatId, question, options, { ...params,
|
|
232
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
233
|
+
return this.sendPoll(chatId, question, options, { ...params, replyTo, businessConnectionId });
|
|
230
234
|
},
|
|
231
235
|
replyPhoto: (photo, params) => {
|
|
232
236
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
233
|
-
const
|
|
234
|
-
return this.sendPhoto(chatId, photo, { ...params,
|
|
237
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
238
|
+
return this.sendPhoto(chatId, photo, { ...params, replyTo, businessConnectionId });
|
|
239
|
+
},
|
|
240
|
+
replyMediaGroup: (media, params) => {
|
|
241
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
242
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
243
|
+
return this.sendMediaGroup(chatId, media, { ...params, replyTo, businessConnectionId });
|
|
244
|
+
},
|
|
245
|
+
replyInvoice: (title, description, payload, currency, prices, params) => {
|
|
246
|
+
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
247
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
248
|
+
return this.sendInvoice(chatId, title, description, payload, currency, prices, { ...params, replyTo, businessConnectionId });
|
|
235
249
|
},
|
|
236
250
|
replyDocument: (document, params) => {
|
|
237
251
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
238
|
-
const
|
|
239
|
-
return this.sendDocument(chatId, document, { ...params,
|
|
252
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
253
|
+
return this.sendDocument(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
240
254
|
},
|
|
241
255
|
replySticker: (sticker, params) => {
|
|
242
256
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
243
|
-
const
|
|
244
|
-
return this.sendSticker(chatId, sticker, { ...params,
|
|
257
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
258
|
+
return this.sendSticker(chatId, sticker, { ...params, replyTo, businessConnectionId });
|
|
245
259
|
},
|
|
246
260
|
replyContact: (firstName, number, params) => {
|
|
247
261
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
248
|
-
const
|
|
249
|
-
return this.sendContact(chatId, firstName, number, { ...params,
|
|
262
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
263
|
+
return this.sendContact(chatId, firstName, number, { ...params, replyTo, businessConnectionId });
|
|
250
264
|
},
|
|
251
265
|
replyLocation: (latitude, longitude, params) => {
|
|
252
266
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
253
|
-
const
|
|
254
|
-
return this.sendLocation(chatId, latitude, longitude, { ...params,
|
|
267
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
268
|
+
return this.sendLocation(chatId, latitude, longitude, { ...params, replyTo, businessConnectionId });
|
|
255
269
|
},
|
|
256
270
|
replyDice: (params) => {
|
|
257
271
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
258
|
-
const
|
|
259
|
-
return this.sendDice(chatId, { ...params,
|
|
272
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
273
|
+
return this.sendDice(chatId, { ...params, replyTo, businessConnectionId });
|
|
260
274
|
},
|
|
261
275
|
replyVenue: (latitude, longitude, title, address, params) => {
|
|
262
276
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
263
|
-
const
|
|
264
|
-
return this.sendVenue(chatId, latitude, longitude, title, address, { ...params,
|
|
277
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
278
|
+
return this.sendVenue(chatId, latitude, longitude, title, address, { ...params, replyTo, businessConnectionId });
|
|
265
279
|
},
|
|
266
280
|
replyVideo: (video, params) => {
|
|
267
281
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
268
|
-
const
|
|
269
|
-
return this.sendVideo(chatId, video, { ...params,
|
|
282
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
283
|
+
return this.sendVideo(chatId, video, { ...params, replyTo, businessConnectionId });
|
|
270
284
|
},
|
|
271
285
|
replyAnimation: (document, params) => {
|
|
272
286
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
273
|
-
const
|
|
274
|
-
return this.sendAnimation(chatId, document, { ...params,
|
|
287
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
288
|
+
return this.sendAnimation(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
275
289
|
},
|
|
276
290
|
replyVoice: (document, params) => {
|
|
277
291
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
278
|
-
const
|
|
279
|
-
return this.sendVoice(chatId, document, { ...params,
|
|
292
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
293
|
+
return this.sendVoice(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
280
294
|
},
|
|
281
295
|
replyAudio: (document, params) => {
|
|
282
296
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
283
|
-
const
|
|
284
|
-
return this.sendAudio(chatId, document, { ...params,
|
|
297
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
298
|
+
return this.sendAudio(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
285
299
|
},
|
|
286
300
|
replyVideoNote: (videoNote, params) => {
|
|
287
301
|
const { chatId, messageId, businessConnectionId } = mustGetMsg();
|
|
288
|
-
const
|
|
289
|
-
return this.sendVideoNote(chatId, videoNote, { ...params,
|
|
302
|
+
const replyTo = getReplyTo(params?.quote, chatId, messageId);
|
|
303
|
+
return this.sendVideoNote(chatId, videoNote, { ...params, replyTo, businessConnectionId });
|
|
290
304
|
},
|
|
291
305
|
delete: () => {
|
|
292
306
|
const { chatId, messageId } = mustGetMsg();
|
|
@@ -504,11 +518,26 @@ export class Client extends Composer {
|
|
|
504
518
|
}
|
|
505
519
|
return this.answerPreCheckoutQuery(update.preCheckoutQuery.id, ok, params);
|
|
506
520
|
},
|
|
521
|
+
approveJoinRequest: () => {
|
|
522
|
+
const { chatId, userId } = mustGetMsg();
|
|
523
|
+
if (!userId) {
|
|
524
|
+
unreachable();
|
|
525
|
+
}
|
|
526
|
+
return this.approveJoinRequest(chatId, userId);
|
|
527
|
+
},
|
|
528
|
+
declineJoinRequest: () => {
|
|
529
|
+
const { chatId, userId } = mustGetMsg();
|
|
530
|
+
if (!userId) {
|
|
531
|
+
unreachable();
|
|
532
|
+
}
|
|
533
|
+
return this.declineJoinRequest(chatId, userId);
|
|
534
|
+
},
|
|
507
535
|
};
|
|
508
536
|
return cleanObject(context);
|
|
509
537
|
});
|
|
510
538
|
_Client_lastPropagatedConnectionState.set(this, null);
|
|
511
539
|
_Client_stateChangeHandler.set(this, ((connected) => {
|
|
540
|
+
drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_reconnect).call(this));
|
|
512
541
|
const connectionState = connected ? "ready" : "notConnected";
|
|
513
542
|
if (__classPrivateFieldGet(this, _Client_lastPropagatedConnectionState, "f") != connectionState) {
|
|
514
543
|
__classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateConnectionState).call(this, connectionState);
|
|
@@ -519,6 +548,8 @@ export class Client extends Composer {
|
|
|
519
548
|
_Client_lastConnect.set(this, null);
|
|
520
549
|
_Client_connectionInited.set(this, false);
|
|
521
550
|
_Client_lastPropagatedAuthorizationState.set(this, null);
|
|
551
|
+
_Client_connectionInsuranceLoopStarted.set(this, false);
|
|
552
|
+
_Client_connectionInsuranceLoopAbortController.set(this, null);
|
|
522
553
|
_Client_pingLoopAbortController.set(this, null);
|
|
523
554
|
_Client_pingInterval.set(this, 56 * second);
|
|
524
555
|
_Client_lastUpdates.set(this, new Date());
|
|
@@ -600,7 +631,7 @@ export class Client extends Composer {
|
|
|
600
631
|
this.prefixes = params?.prefixes;
|
|
601
632
|
}
|
|
602
633
|
__classPrivateFieldSet(this, _Client_guaranteeUpdateDelivery, params?.guaranteeUpdateDelivery ?? false, "f");
|
|
603
|
-
const L = getLogger("Client").client(id++);
|
|
634
|
+
const L = __classPrivateFieldSet(this, _Client_L, getLogger("Client").client(id++), "f");
|
|
604
635
|
__classPrivateFieldSet(this, _Client_LsignIn, L.branch("signIn"), "f");
|
|
605
636
|
__classPrivateFieldSet(this, _Client_LpingLoop, L.branch("pingLoop"), "f");
|
|
606
637
|
__classPrivateFieldSet(this, _Client_LhandleMigrationError, L.branch("[handleMigrationError]"), "f");
|
|
@@ -677,46 +708,6 @@ export class Client extends Composer {
|
|
|
677
708
|
return next();
|
|
678
709
|
}
|
|
679
710
|
});
|
|
680
|
-
let reconnecting = false;
|
|
681
|
-
this.on("connectionState", ({ connectionState }, next) => {
|
|
682
|
-
if (connectionState != "notConnected") {
|
|
683
|
-
return next();
|
|
684
|
-
}
|
|
685
|
-
__classPrivateFieldGet(this, _Client_pingLoopAbortController, "f")?.abort();
|
|
686
|
-
if (this.disconnected) {
|
|
687
|
-
L.debug("not reconnecting");
|
|
688
|
-
return next();
|
|
689
|
-
}
|
|
690
|
-
if (reconnecting) {
|
|
691
|
-
return next();
|
|
692
|
-
}
|
|
693
|
-
reconnecting = true;
|
|
694
|
-
drop((async () => {
|
|
695
|
-
try {
|
|
696
|
-
let delay = 5;
|
|
697
|
-
while (!this.connected) {
|
|
698
|
-
L.debug("reconnecting");
|
|
699
|
-
try {
|
|
700
|
-
await this.connect();
|
|
701
|
-
L.debug("reconnected");
|
|
702
|
-
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("reconnect"));
|
|
703
|
-
break;
|
|
704
|
-
}
|
|
705
|
-
catch (err) {
|
|
706
|
-
if (delay < 15) {
|
|
707
|
-
delay += 5;
|
|
708
|
-
}
|
|
709
|
-
L.debug(`failed to reconnect, retrying in ${delay}:`, err);
|
|
710
|
-
}
|
|
711
|
-
await new Promise((r) => setTimeout(r, delay * second));
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
finally {
|
|
715
|
-
reconnecting = false;
|
|
716
|
-
}
|
|
717
|
-
})());
|
|
718
|
-
return next();
|
|
719
|
-
});
|
|
720
711
|
if (params?.defaultHandlers ?? true) {
|
|
721
712
|
this.invoke.use(async ({ error }, next) => {
|
|
722
713
|
if (error instanceof FloodWait && error.seconds <= 10) {
|
|
@@ -791,6 +782,7 @@ export class Client extends Composer {
|
|
|
791
782
|
await __classPrivateFieldGet(this, _Client_client, "f").connect();
|
|
792
783
|
__classPrivateFieldSet(this, _Client_lastConnect, new Date(), "f");
|
|
793
784
|
await Promise.all([this.storage.setAuthKey(__classPrivateFieldGet(this, _Client_client, "f").authKey), this.storage.setDc(__classPrivateFieldGet(this, _Client_client, "f").dc), this.storage.setServerSalt(__classPrivateFieldGet(this, _Client_client, "f").serverSalt)]);
|
|
785
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_startConnectionInsuranceLoop).call(this);
|
|
794
786
|
__classPrivateFieldGet(this, _Client_instances, "m", _Client_startPingLoop).call(this);
|
|
795
787
|
}
|
|
796
788
|
finally {
|
|
@@ -803,7 +795,42 @@ export class Client extends Composer {
|
|
|
803
795
|
}
|
|
804
796
|
await __classPrivateFieldGet(this, _Client_client, "f").reconnect();
|
|
805
797
|
}
|
|
806
|
-
async [(_Client_client = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_updateManager = new WeakMap(), _Client_networkStatisticsManager = new WeakMap(), _Client_botInfoManager = new WeakMap(), _Client_fileManager = new WeakMap(), _Client_reactionManager = new WeakMap(), _Client_videoChatManager = new WeakMap(), _Client_businessConnectionManager = new WeakMap(), _Client_messageManager = new WeakMap(), _Client_storyManager = new WeakMap(), _Client_callbackQueryManager = new WeakMap(), _Client_inlineQueryManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_accountManager = new WeakMap(), _Client_paymentManager = new WeakMap(), _Client_storage_ = new WeakMap(), _Client_messageStorage_ = new WeakMap(), _Client_parseMode = new WeakMap(), _Client_apiId = new WeakMap(), _Client_apiHash = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_persistCache = new WeakMap(), _Client_cdn = new WeakMap(), _Client_LsignIn = new WeakMap(), _Client_LpingLoop = new WeakMap(), _Client_LhandleMigrationError = new WeakMap(), _Client_L$initConncetion = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_stateChangeHandler = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_lastConnect = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_pingLoopAbortController = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_instances = new WeakSet(),
|
|
798
|
+
async [(_Client_client = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_updateManager = new WeakMap(), _Client_networkStatisticsManager = new WeakMap(), _Client_botInfoManager = new WeakMap(), _Client_fileManager = new WeakMap(), _Client_reactionManager = new WeakMap(), _Client_videoChatManager = new WeakMap(), _Client_businessConnectionManager = new WeakMap(), _Client_messageManager = new WeakMap(), _Client_storyManager = new WeakMap(), _Client_callbackQueryManager = new WeakMap(), _Client_inlineQueryManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_accountManager = new WeakMap(), _Client_paymentManager = new WeakMap(), _Client_storage_ = new WeakMap(), _Client_messageStorage_ = new WeakMap(), _Client_parseMode = new WeakMap(), _Client_apiId = new WeakMap(), _Client_apiHash = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_persistCache = new WeakMap(), _Client_cdn = new WeakMap(), _Client_L = new WeakMap(), _Client_LsignIn = new WeakMap(), _Client_LpingLoop = new WeakMap(), _Client_LhandleMigrationError = new WeakMap(), _Client_L$initConncetion = new WeakMap(), _Client_reconnecting = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_stateChangeHandler = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_lastConnect = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_connectionInsuranceLoopStarted = new WeakMap(), _Client_connectionInsuranceLoopAbortController = new WeakMap(), _Client_pingLoopAbortController = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_instances = new WeakSet(), _Client_reconnect = async function _Client_reconnect() {
|
|
799
|
+
if (this.connected) {
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
if (this.disconnected) {
|
|
803
|
+
__classPrivateFieldGet(this, _Client_L, "f").debug("not reconnecting");
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
if (__classPrivateFieldGet(this, _Client_reconnecting, "f")) {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
__classPrivateFieldSet(this, _Client_reconnecting, true, "f");
|
|
810
|
+
try {
|
|
811
|
+
let delay = 5;
|
|
812
|
+
while (!this.connected) {
|
|
813
|
+
__classPrivateFieldGet(this, _Client_L, "f").debug("reconnecting");
|
|
814
|
+
__classPrivateFieldGet(this, _Client_pingLoopAbortController, "f")?.abort();
|
|
815
|
+
try {
|
|
816
|
+
await this.connect();
|
|
817
|
+
__classPrivateFieldGet(this, _Client_L, "f").debug("reconnected");
|
|
818
|
+
drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("reconnect"));
|
|
819
|
+
break;
|
|
820
|
+
}
|
|
821
|
+
catch (err) {
|
|
822
|
+
if (delay < 15) {
|
|
823
|
+
delay += 5;
|
|
824
|
+
}
|
|
825
|
+
__classPrivateFieldGet(this, _Client_L, "f").debug(`failed to reconnect, retrying in ${delay}:`, err);
|
|
826
|
+
}
|
|
827
|
+
await new Promise((r) => setTimeout(r, delay * second));
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
finally {
|
|
831
|
+
__classPrivateFieldSet(this, _Client_reconnecting, false, "f");
|
|
832
|
+
}
|
|
833
|
+
}, _Client_getApiId = async function _Client_getApiId() {
|
|
807
834
|
const apiId = __classPrivateFieldGet(this, _Client_apiId, "f") || await this.storage.getApiId();
|
|
808
835
|
if (!apiId) {
|
|
809
836
|
throw new InputError("apiId not set");
|
|
@@ -901,6 +928,8 @@ export class Client extends Composer {
|
|
|
901
928
|
async disconnect() {
|
|
902
929
|
__classPrivateFieldSet(this, _Client_connectionInited, false, "f");
|
|
903
930
|
await __classPrivateFieldGet(this, _Client_client, "f").disconnect();
|
|
931
|
+
__classPrivateFieldGet(this, _Client_pingLoopAbortController, "f")?.abort();
|
|
932
|
+
__classPrivateFieldGet(this, _Client_connectionInsuranceLoopAbortController, "f")?.abort();
|
|
904
933
|
}
|
|
905
934
|
/**
|
|
906
935
|
* Signs in using the provided parameters if not already signed in.
|
|
@@ -1156,6 +1185,32 @@ export class Client extends Composer {
|
|
|
1156
1185
|
throw new Error("Unauthorized");
|
|
1157
1186
|
}
|
|
1158
1187
|
return id;
|
|
1188
|
+
}, _Client_startConnectionInsuranceLoop = function _Client_startConnectionInsuranceLoop() {
|
|
1189
|
+
drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_connectionInsuranceLoop).call(this));
|
|
1190
|
+
}, _Client_connectionInsuranceLoop = async function _Client_connectionInsuranceLoop() {
|
|
1191
|
+
if (__classPrivateFieldGet(this, _Client_connectionInsuranceLoopStarted, "f")) {
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
__classPrivateFieldSet(this, _Client_connectionInsuranceLoopAbortController, new AbortController(), "f");
|
|
1195
|
+
__classPrivateFieldSet(this, _Client_connectionInsuranceLoopStarted, true, "f");
|
|
1196
|
+
while (!this.disconnected) {
|
|
1197
|
+
try {
|
|
1198
|
+
await new Promise((resolve, reject) => {
|
|
1199
|
+
const timeout = setTimeout(resolve, 10 * second);
|
|
1200
|
+
__classPrivateFieldGet(this, _Client_connectionInsuranceLoopAbortController, "f").signal.onabort = () => {
|
|
1201
|
+
reject(__classPrivateFieldGet(this, _Client_connectionInsuranceLoopAbortController, "f")?.signal.reason);
|
|
1202
|
+
clearTimeout(timeout);
|
|
1203
|
+
};
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
1206
|
+
catch {
|
|
1207
|
+
break;
|
|
1208
|
+
}
|
|
1209
|
+
if (!this.connected) {
|
|
1210
|
+
drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_reconnect).call(this));
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
__classPrivateFieldSet(this, _Client_connectionInsuranceLoopStarted, false, "f");
|
|
1159
1214
|
}, _Client_startPingLoop = function _Client_startPingLoop() {
|
|
1160
1215
|
drop(__classPrivateFieldGet(this, _Client_instances, "m", _Client_pingLoop).call(this));
|
|
1161
1216
|
}, _Client_pingLoop = async function _Client_pingLoop() {
|
|
@@ -1163,10 +1218,12 @@ export class Client extends Composer {
|
|
|
1163
1218
|
return;
|
|
1164
1219
|
}
|
|
1165
1220
|
__classPrivateFieldSet(this, _Client_pingLoopAbortController, new AbortController(), "f");
|
|
1221
|
+
let timeElapsed = 0;
|
|
1166
1222
|
while (this.connected) {
|
|
1223
|
+
const then = Date.now();
|
|
1167
1224
|
try {
|
|
1168
1225
|
await new Promise((resolve, reject) => {
|
|
1169
|
-
const timeout = setTimeout(resolve, __classPrivateFieldGet(this, _Client_pingInterval, "f"));
|
|
1226
|
+
const timeout = setTimeout(resolve, __classPrivateFieldGet(this, _Client_pingInterval, "f") - timeElapsed);
|
|
1170
1227
|
__classPrivateFieldGet(this, _Client_pingLoopAbortController, "f").signal.onabort = () => {
|
|
1171
1228
|
reject(__classPrivateFieldGet(this, _Client_pingLoopAbortController, "f")?.signal.reason);
|
|
1172
1229
|
clearTimeout(timeout);
|
|
@@ -1193,6 +1250,9 @@ export class Client extends Composer {
|
|
|
1193
1250
|
}
|
|
1194
1251
|
__classPrivateFieldGet(this, _Client_LpingLoop, "f").error(err);
|
|
1195
1252
|
}
|
|
1253
|
+
finally {
|
|
1254
|
+
timeElapsed = Date.now() - then;
|
|
1255
|
+
}
|
|
1196
1256
|
}
|
|
1197
1257
|
}, _Client_invoke = async function _Client_invoke(function_, noWait) {
|
|
1198
1258
|
let n = 1;
|