@mtcute/core 0.30.3 → 0.32.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/client.cjs +85 -0
- package/client.js +85 -0
- package/highlevel/client.d.cts +411 -116
- package/highlevel/client.d.ts +411 -116
- package/highlevel/methods/auth/sign-in-qr.cjs +2 -0
- package/highlevel/methods/auth/sign-in-qr.js +2 -0
- package/highlevel/methods/auth/sign-in-qr.test.d.cts +1 -0
- package/highlevel/methods/auth/sign-in-qr.test.d.ts +1 -0
- package/highlevel/methods/chats/build-peers-index.cjs +45 -0
- package/highlevel/methods/chats/build-peers-index.d.cts +13 -0
- package/highlevel/methods/chats/build-peers-index.d.ts +13 -0
- package/highlevel/methods/chats/build-peers-index.js +40 -0
- package/highlevel/methods/chats/join-chat.cjs +1 -1
- package/highlevel/methods/chats/join-chat.d.cts +2 -1
- package/highlevel/methods/chats/join-chat.d.ts +2 -1
- package/highlevel/methods/chats/join-chat.js +1 -1
- package/highlevel/methods/chats/transfer-chat-ownership.cjs +6 -17
- package/highlevel/methods/chats/transfer-chat-ownership.js +6 -17
- package/highlevel/methods/communities/ban-community-participant.cjs +30 -0
- package/highlevel/methods/communities/ban-community-participant.d.cts +20 -0
- package/highlevel/methods/communities/ban-community-participant.d.ts +20 -0
- package/highlevel/methods/communities/ban-community-participant.js +25 -0
- package/highlevel/methods/communities/create-community.cjs +29 -0
- package/highlevel/methods/communities/create-community.d.cts +22 -0
- package/highlevel/methods/communities/create-community.d.ts +22 -0
- package/highlevel/methods/communities/create-community.js +24 -0
- package/highlevel/methods/communities/get-community-link-requests.cjs +27 -0
- package/highlevel/methods/communities/get-community-link-requests.d.cts +17 -0
- package/highlevel/methods/communities/get-community-link-requests.d.ts +17 -0
- package/highlevel/methods/communities/get-community-link-requests.js +22 -0
- package/highlevel/methods/communities/get-community-participant-chats.cjs +24 -0
- package/highlevel/methods/communities/get-community-participant-chats.d.cts +17 -0
- package/highlevel/methods/communities/get-community-participant-chats.d.ts +17 -0
- package/highlevel/methods/communities/get-community-participant-chats.js +19 -0
- package/highlevel/methods/communities/get-joined-communities.cjs +21 -0
- package/highlevel/methods/communities/get-joined-communities.d.cts +6 -0
- package/highlevel/methods/communities/get-joined-communities.d.ts +6 -0
- package/highlevel/methods/communities/get-joined-communities.js +16 -0
- package/highlevel/methods/communities/hide-community-link-request.cjs +30 -0
- package/highlevel/methods/communities/hide-community-link-request.d.cts +22 -0
- package/highlevel/methods/communities/hide-community-link-request.d.ts +22 -0
- package/highlevel/methods/communities/hide-community-link-request.js +25 -0
- package/highlevel/methods/communities/link-community-peer.cjs +32 -0
- package/highlevel/methods/communities/link-community-peer.d.cts +22 -0
- package/highlevel/methods/communities/link-community-peer.d.ts +22 -0
- package/highlevel/methods/communities/link-community-peer.js +27 -0
- package/highlevel/methods/communities/toggle-community-collapsed.cjs +18 -0
- package/highlevel/methods/communities/toggle-community-collapsed.d.cts +16 -0
- package/highlevel/methods/communities/toggle-community-collapsed.d.ts +16 -0
- package/highlevel/methods/communities/toggle-community-collapsed.js +13 -0
- package/highlevel/methods/ephemeral/delete-all-welcome-messages.cjs +17 -0
- package/highlevel/methods/ephemeral/delete-all-welcome-messages.d.cts +8 -0
- package/highlevel/methods/ephemeral/delete-all-welcome-messages.d.ts +8 -0
- package/highlevel/methods/ephemeral/delete-all-welcome-messages.js +12 -0
- package/highlevel/methods/ephemeral/delete-ephemeral-message.cjs +20 -0
- package/highlevel/methods/ephemeral/delete-ephemeral-message.d.cts +13 -0
- package/highlevel/methods/ephemeral/delete-ephemeral-message.d.ts +13 -0
- package/highlevel/methods/ephemeral/delete-ephemeral-message.js +15 -0
- package/highlevel/methods/ephemeral/delete-welcome-message.cjs +18 -0
- package/highlevel/methods/ephemeral/delete-welcome-message.d.cts +9 -0
- package/highlevel/methods/ephemeral/delete-welcome-message.d.ts +9 -0
- package/highlevel/methods/ephemeral/delete-welcome-message.js +13 -0
- package/highlevel/methods/ephemeral/edit-ephemeral-message.cjs +41 -0
- package/highlevel/methods/ephemeral/edit-ephemeral-message.d.cts +39 -0
- package/highlevel/methods/ephemeral/edit-ephemeral-message.d.ts +39 -0
- package/highlevel/methods/ephemeral/edit-ephemeral-message.js +36 -0
- package/highlevel/methods/ephemeral/find-in-update.cjs +27 -0
- package/highlevel/methods/ephemeral/find-in-update.d.cts +8 -0
- package/highlevel/methods/ephemeral/find-in-update.d.ts +8 -0
- package/highlevel/methods/ephemeral/find-in-update.js +22 -0
- package/highlevel/methods/ephemeral/get-ephemeral-callback-answer.cjs +31 -0
- package/highlevel/methods/ephemeral/get-ephemeral-callback-answer.d.cts +29 -0
- package/highlevel/methods/ephemeral/get-ephemeral-callback-answer.d.ts +29 -0
- package/highlevel/methods/ephemeral/get-ephemeral-callback-answer.js +26 -0
- package/highlevel/methods/ephemeral/get-welcome-messages.cjs +29 -0
- package/highlevel/methods/ephemeral/get-welcome-messages.d.cts +8 -0
- package/highlevel/methods/ephemeral/get-welcome-messages.d.ts +8 -0
- package/highlevel/methods/ephemeral/get-welcome-messages.js +24 -0
- package/highlevel/methods/ephemeral/send-ephemeral-message.cjs +48 -0
- package/highlevel/methods/ephemeral/send-ephemeral-message.d.cts +47 -0
- package/highlevel/methods/ephemeral/send-ephemeral-message.d.ts +47 -0
- package/highlevel/methods/ephemeral/send-ephemeral-message.js +43 -0
- package/highlevel/methods/files/download-iterable.cjs +7 -2
- package/highlevel/methods/files/download-iterable.js +7 -2
- package/highlevel/methods/files/download-iterable.test.d.cts +1 -0
- package/highlevel/methods/files/download-iterable.test.d.ts +1 -0
- package/highlevel/methods/files/download-stream.cjs +5 -6
- package/highlevel/methods/files/download-stream.js +5 -6
- package/highlevel/methods/files/normalize-input-media.cjs +25 -4
- package/highlevel/methods/files/normalize-input-media.js +25 -4
- package/highlevel/methods/forums/create-forum-topic.d.cts +7 -0
- package/highlevel/methods/forums/create-forum-topic.d.ts +7 -0
- package/highlevel/methods/forums/delete-forum-topic-history.d.cts +1 -1
- package/highlevel/methods/forums/delete-forum-topic-history.d.ts +1 -1
- package/highlevel/methods/forums/edit-forum-topic.cjs +2 -2
- package/highlevel/methods/forums/edit-forum-topic.d.cts +2 -2
- package/highlevel/methods/forums/edit-forum-topic.d.ts +2 -2
- package/highlevel/methods/forums/edit-forum-topic.js +2 -2
- package/highlevel/methods/forums/get-forum-topics-by-id.cjs +5 -1
- package/highlevel/methods/forums/get-forum-topics-by-id.d.cts +9 -1
- package/highlevel/methods/forums/get-forum-topics-by-id.d.ts +9 -1
- package/highlevel/methods/forums/get-forum-topics-by-id.js +5 -1
- package/highlevel/methods/forums/get-forum-topics-by-id.test.d.cts +1 -0
- package/highlevel/methods/forums/get-forum-topics-by-id.test.d.ts +1 -0
- package/highlevel/methods/forums/get-forum-topics.cjs +1 -1
- package/highlevel/methods/forums/get-forum-topics.js +1 -1
- package/highlevel/methods/forums/toggle-forum-topic-closed.cjs +1 -1
- package/highlevel/methods/forums/toggle-forum-topic-closed.d.cts +1 -1
- package/highlevel/methods/forums/toggle-forum-topic-closed.d.ts +1 -1
- package/highlevel/methods/forums/toggle-forum-topic-closed.js +1 -1
- package/highlevel/methods/forums/toggle-forum-topic-pinned.d.cts +1 -1
- package/highlevel/methods/forums/toggle-forum-topic-pinned.d.ts +1 -1
- package/highlevel/methods/forums/toggle-general-topic-hidden.cjs +3 -3
- package/highlevel/methods/forums/toggle-general-topic-hidden.js +4 -4
- package/highlevel/methods/gifts/buy-resale-gift.cjs +5 -2
- package/highlevel/methods/gifts/buy-resale-gift.d.cts +11 -1
- package/highlevel/methods/gifts/buy-resale-gift.d.ts +11 -1
- package/highlevel/methods/gifts/buy-resale-gift.js +5 -2
- package/highlevel/methods/messages/forward-messages.cjs +1 -0
- package/highlevel/methods/messages/forward-messages.d.cts +2 -0
- package/highlevel/methods/messages/forward-messages.d.ts +2 -0
- package/highlevel/methods/messages/forward-messages.js +1 -0
- package/highlevel/methods/messages/normalize-rich-message.cjs +3 -0
- package/highlevel/methods/messages/normalize-rich-message.js +3 -0
- package/highlevel/methods/messages/send-common.d.cts +7 -1
- package/highlevel/methods/messages/send-common.d.ts +7 -1
- package/highlevel/methods/messages/send-text.cjs +70 -35
- package/highlevel/methods/messages/send-text.js +70 -35
- package/highlevel/methods/messages/send-typing.d.cts +3 -3
- package/highlevel/methods/messages/send-typing.d.ts +3 -3
- package/highlevel/methods/messages/set-typing.cjs +1 -1
- package/highlevel/methods/messages/set-typing.d.cts +2 -2
- package/highlevel/methods/messages/set-typing.d.ts +2 -2
- package/highlevel/methods/messages/set-typing.js +1 -1
- package/highlevel/methods/users/resolve-peer.cjs +11 -1
- package/highlevel/methods/users/resolve-peer.js +11 -1
- package/highlevel/methods.d.cts +19 -0
- package/highlevel/methods.d.ts +19 -0
- package/highlevel/storage/service/peers.cjs +25 -0
- package/highlevel/storage/service/peers.js +25 -0
- package/highlevel/storage/service/peers.test.d.cts +1 -0
- package/highlevel/storage/service/peers.test.d.ts +1 -0
- package/highlevel/types/bots/keyboards/builder.cjs +5 -5
- package/highlevel/types/bots/keyboards/builder.d.cts +8 -9
- package/highlevel/types/bots/keyboards/builder.d.ts +8 -9
- package/highlevel/types/bots/keyboards/builder.js +5 -5
- package/highlevel/types/bots/keyboards/factories.cjs +51 -103
- package/highlevel/types/bots/keyboards/factories.d.cts +58 -89
- package/highlevel/types/bots/keyboards/factories.d.ts +58 -89
- package/highlevel/types/bots/keyboards/factories.js +51 -103
- package/highlevel/types/bots/keyboards/index.d.cts +3 -3
- package/highlevel/types/bots/keyboards/index.d.ts +3 -3
- package/highlevel/types/bots/keyboards/normalize.cjs +131 -0
- package/highlevel/types/bots/keyboards/normalize.d.cts +10 -0
- package/highlevel/types/bots/keyboards/normalize.d.ts +10 -0
- package/highlevel/types/bots/keyboards/normalize.js +126 -0
- package/highlevel/types/bots/keyboards/types.d.cts +160 -4
- package/highlevel/types/bots/keyboards/types.d.ts +160 -4
- package/highlevel/types/conversation.cjs +8 -0
- package/highlevel/types/conversation.d.cts +1 -0
- package/highlevel/types/conversation.d.ts +1 -0
- package/highlevel/types/conversation.js +10 -2
- package/highlevel/types/conversation.test.d.cts +1 -0
- package/highlevel/types/conversation.test.d.ts +1 -0
- package/highlevel/types/messages/dialog.cjs +8 -1
- package/highlevel/types/messages/dialog.d.cts +3 -0
- package/highlevel/types/messages/dialog.d.ts +3 -0
- package/highlevel/types/messages/dialog.js +8 -1
- package/highlevel/types/messages/dialog.test.d.cts +1 -0
- package/highlevel/types/messages/dialog.test.d.ts +1 -0
- package/highlevel/types/messages/ephemeral-message.cjs +135 -0
- package/highlevel/types/messages/ephemeral-message.d.cts +75 -0
- package/highlevel/types/messages/ephemeral-message.d.ts +75 -0
- package/highlevel/types/messages/ephemeral-message.js +130 -0
- package/highlevel/types/messages/index.d.cts +1 -0
- package/highlevel/types/messages/index.d.ts +1 -0
- package/highlevel/types/messages/message-action.cjs +14 -1
- package/highlevel/types/messages/message-action.d.cts +18 -1
- package/highlevel/types/messages/message-action.d.ts +18 -1
- package/highlevel/types/messages/message-action.js +14 -1
- package/highlevel/types/messages/message.cjs +7 -2
- package/highlevel/types/messages/message.d.cts +2 -2
- package/highlevel/types/messages/message.d.ts +2 -2
- package/highlevel/types/messages/message.js +8 -3
- package/highlevel/types/messages/replied-message.cjs +5 -1
- package/highlevel/types/messages/replied-message.d.cts +5 -1
- package/highlevel/types/messages/replied-message.d.ts +5 -1
- package/highlevel/types/messages/replied-message.js +5 -1
- package/highlevel/types/messages/rich/inner.cjs +37 -0
- package/highlevel/types/messages/rich/inner.d.cts +19 -0
- package/highlevel/types/messages/rich/inner.d.ts +19 -0
- package/highlevel/types/messages/rich/inner.js +37 -0
- package/highlevel/types/peers/chat.cjs +23 -3
- package/highlevel/types/peers/chat.d.cts +8 -3
- package/highlevel/types/peers/chat.d.ts +8 -3
- package/highlevel/types/peers/chat.js +24 -4
- package/highlevel/types/peers/community-peer.cjs +60 -0
- package/highlevel/types/peers/community-peer.d.cts +37 -0
- package/highlevel/types/peers/community-peer.d.ts +37 -0
- package/highlevel/types/peers/community-peer.js +55 -0
- package/highlevel/types/peers/full-chat.cjs +24 -5
- package/highlevel/types/peers/full-chat.d.cts +7 -0
- package/highlevel/types/peers/full-chat.d.ts +7 -0
- package/highlevel/types/peers/full-chat.js +24 -5
- package/highlevel/types/peers/index.d.cts +1 -0
- package/highlevel/types/peers/index.d.ts +1 -0
- package/highlevel/types/peers/peer.cjs +2 -0
- package/highlevel/types/peers/peer.js +2 -0
- package/highlevel/types/peers/typing-status.d.cts +4 -1
- package/highlevel/types/peers/typing-status.d.ts +4 -1
- package/highlevel/types/peers/user.cjs +6 -0
- package/highlevel/types/peers/user.d.cts +2 -0
- package/highlevel/types/peers/user.d.ts +2 -0
- package/highlevel/types/peers/user.js +6 -0
- package/highlevel/types/updates/delete-ephemeral-messages-update.cjs +27 -0
- package/highlevel/types/updates/delete-ephemeral-messages-update.d.cts +15 -0
- package/highlevel/types/updates/delete-ephemeral-messages-update.d.ts +15 -0
- package/highlevel/types/updates/delete-ephemeral-messages-update.js +22 -0
- package/highlevel/types/updates/ephemeral-callback-query.cjs +69 -0
- package/highlevel/types/updates/ephemeral-callback-query.d.cts +44 -0
- package/highlevel/types/updates/ephemeral-callback-query.d.ts +44 -0
- package/highlevel/types/updates/ephemeral-callback-query.js +64 -0
- package/highlevel/types/updates/index.d.cts +16 -2
- package/highlevel/types/updates/index.d.ts +16 -2
- package/highlevel/types/updates/parse-update.cjs +12 -1
- package/highlevel/types/updates/parse-update.js +12 -1
- package/highlevel/types/updates/user-typing-update.cjs +18 -0
- package/highlevel/types/updates/user-typing-update.d.cts +9 -0
- package/highlevel/types/updates/user-typing-update.d.ts +9 -0
- package/highlevel/types/updates/user-typing-update.js +18 -0
- package/highlevel/updates/manager.cjs +71 -41
- package/highlevel/updates/manager.d.cts +1 -0
- package/highlevel/updates/manager.d.ts +1 -0
- package/highlevel/updates/manager.js +71 -41
- package/highlevel/updates/manager.test.d.cts +1 -0
- package/highlevel/updates/manager.test.d.ts +1 -0
- package/highlevel/utils/stream-utils.cjs +8 -4
- package/highlevel/utils/stream-utils.js +8 -4
- package/highlevel/utils/stream-utils.test.d.cts +1 -0
- package/highlevel/utils/stream-utils.test.d.ts +1 -0
- package/highlevel/utils/walk-page-blocks.cjs +9 -0
- package/highlevel/utils/walk-page-blocks.js +9 -0
- package/index.cjs +10 -0
- package/index.js +11 -1
- package/methods.cjs +33 -0
- package/methods.js +33 -0
- package/network/client.cjs +4 -3
- package/network/client.d.cts +1 -0
- package/network/client.d.ts +1 -0
- package/network/client.js +4 -3
- package/network/middlewares/flood-waiter.cjs +2 -2
- package/network/middlewares/flood-waiter.js +2 -2
- package/network/middlewares/internal-errors.cjs +1 -1
- package/network/middlewares/internal-errors.js +1 -1
- package/network/middlewares/media-throttle.cjs +1 -1
- package/network/middlewares/media-throttle.js +1 -1
- package/network/mtproto-session.cjs +9 -2
- package/network/mtproto-session.d.cts +3 -1
- package/network/mtproto-session.d.ts +3 -1
- package/network/mtproto-session.js +9 -2
- package/network/mtproxy/index.cjs +4 -3
- package/network/mtproxy/index.d.cts +2 -2
- package/network/mtproxy/index.d.ts +2 -2
- package/network/mtproxy/index.js +4 -3
- package/network/network-manager.cjs +44 -16
- package/network/network-manager.d.cts +10 -3
- package/network/network-manager.d.ts +10 -3
- package/network/network-manager.js +45 -17
- package/network/network-manager.test.d.cts +1 -0
- package/network/network-manager.test.d.ts +1 -0
- package/network/persistent-connection.cjs +10 -2
- package/network/persistent-connection.js +10 -2
- package/network/session-connection.cjs +15 -6
- package/network/session-connection.js +15 -6
- package/network/session-connection.test.d.cts +1 -0
- package/network/session-connection.test.d.ts +1 -0
- package/network/transports/abstract.cjs +16 -0
- package/network/transports/abstract.d.cts +8 -2
- package/network/transports/abstract.d.ts +8 -2
- package/network/transports/abstract.js +17 -1
- package/network/transports/obfuscated.cjs +3 -1
- package/network/transports/obfuscated.js +3 -1
- package/package.json +6 -6
- package/tl/api-schema.json +1 -1
- package/tl/binary/reader.cjs +221 -103
- package/tl/binary/reader.js +221 -103
- package/tl/binary/writer.cjs +693 -277
- package/tl/binary/writer.js +693 -277
- package/tl/compat/reader.cjs +93 -0
- package/tl/compat/reader.js +93 -0
- package/tl/index.d.cts +12529 -4762
- package/tl/index.d.ts +12529 -4762
- package/tl/inner-tl.cjs +90 -24
- package/tl/inner-tl.js +90 -24
- package/tl/raw-errors.json +1 -1
- package/tl/rpc-error.test.d.cts +1 -0
- package/tl/rpc-error.test.d.ts +1 -0
- package/utils/abort-signal.cjs +1 -12
- package/utils/abort-signal.js +1 -12
- package/utils/abort-signal.test.d.cts +1 -0
- package/utils/abort-signal.test.d.ts +1 -0
- package/utils/binary/compat.cjs +189 -29
- package/utils/binary/compat.js +189 -29
- package/utils/early-timer.cjs +3 -11
- package/utils/early-timer.js +3 -11
- package/utils/early-timer.test.d.cts +1 -0
- package/utils/early-timer.test.d.ts +1 -0
- package/utils/function-utils.cjs +9 -4
- package/utils/function-utils.js +9 -4
- package/utils/links/bots.cjs +10 -2
- package/utils/links/bots.js +10 -2
- package/utils/peer-utils.cjs +8 -0
- package/utils/peer-utils.js +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -23,7 +23,7 @@ class PersistentConnection {
|
|
|
23
23
|
}
|
|
24
24
|
this._onInactivityTimeout = this._onInactivityTimeout.bind(this);
|
|
25
25
|
this._fuman = new net.PersistentConnection({
|
|
26
|
-
connect: async (dc) => {
|
|
26
|
+
connect: async (dc, abortSignal) => {
|
|
27
27
|
if (this._floodControl) {
|
|
28
28
|
if (!this._connectAbort || this._connectAbort.signal.aborted) {
|
|
29
29
|
this._connectAbort = new AbortController();
|
|
@@ -33,7 +33,7 @@ class PersistentConnection {
|
|
|
33
33
|
}
|
|
34
34
|
this._updateLogPrefix();
|
|
35
35
|
this.log.debug("connecting to %j", dc);
|
|
36
|
-
return params.transport.connect(dc);
|
|
36
|
+
return params.transport.connect(dc, abortSignal);
|
|
37
37
|
},
|
|
38
38
|
strategy: params.reconnectionStrategy,
|
|
39
39
|
onOpen: this._onOpen.bind(this),
|
|
@@ -139,10 +139,18 @@ class PersistentConnection {
|
|
|
139
139
|
this._fuman.connect(this.params.dc);
|
|
140
140
|
}
|
|
141
141
|
connect() {
|
|
142
|
+
if (this._destroyed) {
|
|
143
|
+
this.log.warn("tried to connect a destroyed connection, ignoring");
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
142
146
|
this._fuman.connect(this.params.dc);
|
|
143
147
|
this._inactive = false;
|
|
144
148
|
}
|
|
145
149
|
reconnect() {
|
|
150
|
+
if (this._destroyed) {
|
|
151
|
+
this.log.warn("tried to reconnect a destroyed connection, ignoring");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
146
154
|
if (this._disconnectedManually) {
|
|
147
155
|
this._disconnectedManually = false;
|
|
148
156
|
this.connect();
|
|
@@ -16,7 +16,7 @@ class PersistentConnection {
|
|
|
16
16
|
}
|
|
17
17
|
this._onInactivityTimeout = this._onInactivityTimeout.bind(this);
|
|
18
18
|
this._fuman = new PersistentConnection$1({
|
|
19
|
-
connect: async (dc) => {
|
|
19
|
+
connect: async (dc, abortSignal) => {
|
|
20
20
|
if (this._floodControl) {
|
|
21
21
|
if (!this._connectAbort || this._connectAbort.signal.aborted) {
|
|
22
22
|
this._connectAbort = new AbortController();
|
|
@@ -26,7 +26,7 @@ class PersistentConnection {
|
|
|
26
26
|
}
|
|
27
27
|
this._updateLogPrefix();
|
|
28
28
|
this.log.debug("connecting to %j", dc);
|
|
29
|
-
return params.transport.connect(dc);
|
|
29
|
+
return params.transport.connect(dc, abortSignal);
|
|
30
30
|
},
|
|
31
31
|
strategy: params.reconnectionStrategy,
|
|
32
32
|
onOpen: this._onOpen.bind(this),
|
|
@@ -132,10 +132,18 @@ class PersistentConnection {
|
|
|
132
132
|
this._fuman.connect(this.params.dc);
|
|
133
133
|
}
|
|
134
134
|
connect() {
|
|
135
|
+
if (this._destroyed) {
|
|
136
|
+
this.log.warn("tried to connect a destroyed connection, ignoring");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
135
139
|
this._fuman.connect(this.params.dc);
|
|
136
140
|
this._inactive = false;
|
|
137
141
|
}
|
|
138
142
|
reconnect() {
|
|
143
|
+
if (this._destroyed) {
|
|
144
|
+
this.log.warn("tried to reconnect a destroyed connection, ignoring");
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
139
147
|
if (this._disconnectedManually) {
|
|
140
148
|
this._disconnectedManually = false;
|
|
141
149
|
this.connect();
|
|
@@ -123,7 +123,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
123
123
|
this._session.initConnectionCalled = false;
|
|
124
124
|
this._flushTimer.reset();
|
|
125
125
|
this._salts.isFetching = false;
|
|
126
|
-
this._session.
|
|
126
|
+
this._session.forgetPendingPings();
|
|
127
127
|
for (const timeout of this._session.pendingGetStateTimeouts.values()) {
|
|
128
128
|
utils.timers.clearTimeout(timeout);
|
|
129
129
|
}
|
|
@@ -738,7 +738,9 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
738
738
|
break;
|
|
739
739
|
case "ping":
|
|
740
740
|
this.log.debug("ping (msg_id = %l) failed because of %s", msgId, reason);
|
|
741
|
-
this._session.
|
|
741
|
+
if (this._session.lastPingMsgId.eq(msgId)) {
|
|
742
|
+
this._session.resetLastPing(true);
|
|
743
|
+
}
|
|
742
744
|
break;
|
|
743
745
|
case "rpc": {
|
|
744
746
|
const rpc = msgInfo.rpc;
|
|
@@ -811,14 +813,17 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
811
813
|
if (info.pingId.neq(pingId)) {
|
|
812
814
|
this.log.warn("received pong to %l, but expected ping_id = %l (got %l)", msgId, info.pingId, pingId);
|
|
813
815
|
}
|
|
814
|
-
|
|
816
|
+
this._session.pendingMessages.delete(msgId);
|
|
817
|
+
const rtt = performance.now() - info.sentAt;
|
|
815
818
|
this._session.lastPingRtt = rtt;
|
|
816
819
|
if (info.containerId.neq(msgId)) {
|
|
817
820
|
this._onMessageAcked(info.containerId);
|
|
818
821
|
}
|
|
819
822
|
this.log.debug("received pong: msg_id %l, ping_id %l, rtt = %dms", msgId, pingId, rtt);
|
|
820
|
-
this._session.
|
|
821
|
-
|
|
823
|
+
if (this._session.lastPingMsgId.eq(msgId)) {
|
|
824
|
+
this._session.resetLastPing();
|
|
825
|
+
this._flushTimer.emitBefore(this._session.lastPingTime + this._pingMustDelay());
|
|
826
|
+
}
|
|
822
827
|
}
|
|
823
828
|
_onBadServerSalt(msg) {
|
|
824
829
|
this._salts.currentSalt = msg.newServerSalt;
|
|
@@ -1008,6 +1013,9 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
1008
1013
|
}
|
|
1009
1014
|
}
|
|
1010
1015
|
sendRpc(request, timeout, abortSignal, chainId) {
|
|
1016
|
+
if (this._destroyed) {
|
|
1017
|
+
return Promise.reject(new errors.MtcuteError("Connection destroyed"));
|
|
1018
|
+
}
|
|
1011
1019
|
if (this._usable && this.params.inactivityTimeout) {
|
|
1012
1020
|
this._rescheduleInactivity();
|
|
1013
1021
|
}
|
|
@@ -1208,7 +1216,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
1208
1216
|
const active = this._online && this._isActive();
|
|
1209
1217
|
if (active && !this._active) {
|
|
1210
1218
|
this._session.lastActivityTime = now;
|
|
1211
|
-
this._session.resetLastPing(true);
|
|
1219
|
+
this._session.resetLastPing(true, true);
|
|
1212
1220
|
}
|
|
1213
1221
|
this._active = active;
|
|
1214
1222
|
if (this._checkTimeouts(now)) return;
|
|
@@ -1390,6 +1398,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
1390
1398
|
const pingPending = {
|
|
1391
1399
|
_: "ping",
|
|
1392
1400
|
pingId,
|
|
1401
|
+
sentAt: now,
|
|
1393
1402
|
containerId: pingMsgId
|
|
1394
1403
|
};
|
|
1395
1404
|
this._session.pendingMessages.set(pingMsgId, pingPending);
|
|
@@ -116,7 +116,7 @@ class SessionConnection extends PersistentConnection {
|
|
|
116
116
|
this._session.initConnectionCalled = false;
|
|
117
117
|
this._flushTimer.reset();
|
|
118
118
|
this._salts.isFetching = false;
|
|
119
|
-
this._session.
|
|
119
|
+
this._session.forgetPendingPings();
|
|
120
120
|
for (const timeout of this._session.pendingGetStateTimeouts.values()) {
|
|
121
121
|
timers.clearTimeout(timeout);
|
|
122
122
|
}
|
|
@@ -731,7 +731,9 @@ class SessionConnection extends PersistentConnection {
|
|
|
731
731
|
break;
|
|
732
732
|
case "ping":
|
|
733
733
|
this.log.debug("ping (msg_id = %l) failed because of %s", msgId, reason);
|
|
734
|
-
this._session.
|
|
734
|
+
if (this._session.lastPingMsgId.eq(msgId)) {
|
|
735
|
+
this._session.resetLastPing(true);
|
|
736
|
+
}
|
|
735
737
|
break;
|
|
736
738
|
case "rpc": {
|
|
737
739
|
const rpc = msgInfo.rpc;
|
|
@@ -804,14 +806,17 @@ class SessionConnection extends PersistentConnection {
|
|
|
804
806
|
if (info.pingId.neq(pingId)) {
|
|
805
807
|
this.log.warn("received pong to %l, but expected ping_id = %l (got %l)", msgId, info.pingId, pingId);
|
|
806
808
|
}
|
|
807
|
-
|
|
809
|
+
this._session.pendingMessages.delete(msgId);
|
|
810
|
+
const rtt = performance.now() - info.sentAt;
|
|
808
811
|
this._session.lastPingRtt = rtt;
|
|
809
812
|
if (info.containerId.neq(msgId)) {
|
|
810
813
|
this._onMessageAcked(info.containerId);
|
|
811
814
|
}
|
|
812
815
|
this.log.debug("received pong: msg_id %l, ping_id %l, rtt = %dms", msgId, pingId, rtt);
|
|
813
|
-
this._session.
|
|
814
|
-
|
|
816
|
+
if (this._session.lastPingMsgId.eq(msgId)) {
|
|
817
|
+
this._session.resetLastPing();
|
|
818
|
+
this._flushTimer.emitBefore(this._session.lastPingTime + this._pingMustDelay());
|
|
819
|
+
}
|
|
815
820
|
}
|
|
816
821
|
_onBadServerSalt(msg) {
|
|
817
822
|
this._salts.currentSalt = msg.newServerSalt;
|
|
@@ -1001,6 +1006,9 @@ class SessionConnection extends PersistentConnection {
|
|
|
1001
1006
|
}
|
|
1002
1007
|
}
|
|
1003
1008
|
sendRpc(request, timeout, abortSignal, chainId) {
|
|
1009
|
+
if (this._destroyed) {
|
|
1010
|
+
return Promise.reject(new MtcuteError("Connection destroyed"));
|
|
1011
|
+
}
|
|
1004
1012
|
if (this._usable && this.params.inactivityTimeout) {
|
|
1005
1013
|
this._rescheduleInactivity();
|
|
1006
1014
|
}
|
|
@@ -1201,7 +1209,7 @@ class SessionConnection extends PersistentConnection {
|
|
|
1201
1209
|
const active = this._online && this._isActive();
|
|
1202
1210
|
if (active && !this._active) {
|
|
1203
1211
|
this._session.lastActivityTime = now;
|
|
1204
|
-
this._session.resetLastPing(true);
|
|
1212
|
+
this._session.resetLastPing(true, true);
|
|
1205
1213
|
}
|
|
1206
1214
|
this._active = active;
|
|
1207
1215
|
if (this._checkTimeouts(now)) return;
|
|
@@ -1383,6 +1391,7 @@ class SessionConnection extends PersistentConnection {
|
|
|
1383
1391
|
const pingPending = {
|
|
1384
1392
|
_: "ping",
|
|
1385
1393
|
pingId,
|
|
1394
|
+
sentAt: now,
|
|
1386
1395
|
containerId: pingMsgId
|
|
1387
1396
|
};
|
|
1388
1397
|
this._session.pendingMessages.set(pingMsgId, pingPending);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,6 +5,21 @@ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WAR
|
|
|
5
5
|
}
|
|
6
6
|
"use strict";
|
|
7
7
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
async function performHandshakeWithAbort(conn, abortSignal, handshake) {
|
|
9
|
+
if (abortSignal.aborted) {
|
|
10
|
+
conn.close();
|
|
11
|
+
throw abortSignal.reason;
|
|
12
|
+
}
|
|
13
|
+
const onAbort = () => conn.close();
|
|
14
|
+
abortSignal.addEventListener("abort", onAbort);
|
|
15
|
+
try {
|
|
16
|
+
await handshake();
|
|
17
|
+
} finally {
|
|
18
|
+
abortSignal.removeEventListener("abort", onAbort);
|
|
19
|
+
}
|
|
20
|
+
abortSignal.throwIfAborted();
|
|
21
|
+
return conn;
|
|
22
|
+
}
|
|
8
23
|
class TransportError extends Error {
|
|
9
24
|
code;
|
|
10
25
|
constructor(code) {
|
|
@@ -13,3 +28,4 @@ class TransportError extends Error {
|
|
|
13
28
|
}
|
|
14
29
|
}
|
|
15
30
|
exports.TransportError = TransportError;
|
|
31
|
+
exports.performHandshakeWithAbort = performHandshakeWithAbort;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IFrameDecoder, IFrameEncoder } from '@fuman/io';
|
|
1
|
+
import { IClosable, IFrameDecoder, IFrameEncoder } from '@fuman/io';
|
|
2
2
|
import { IConnection } from '@fuman/net';
|
|
3
3
|
import { tl } from '../../tl/index.js';
|
|
4
4
|
import { MaybePromise } from '../../types/index.js';
|
|
@@ -18,9 +18,15 @@ export interface ITelegramConnection extends IConnection<any, any> {
|
|
|
18
18
|
}
|
|
19
19
|
export interface TelegramTransport {
|
|
20
20
|
setup?(crypto: ICryptoProvider, log: Logger): void;
|
|
21
|
-
connect: (dc: BasicDcOption) => Promise<ITelegramConnection>;
|
|
21
|
+
connect: (dc: BasicDcOption, abortSignal: AbortSignal) => Promise<ITelegramConnection>;
|
|
22
22
|
packetCodec: (dc: BasicDcOption) => IPacketCodec;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Run a post-connect handshake, closing the connection if `abortSignal`
|
|
26
|
+
* is aborted before it completes (which in turn makes any pending
|
|
27
|
+
* reads/writes inside the handshake reject)
|
|
28
|
+
*/
|
|
29
|
+
export declare function performHandshakeWithAbort<Connection extends IClosable>(conn: Connection, abortSignal: AbortSignal, handshake: () => Promise<void>): Promise<Connection>;
|
|
24
30
|
/**
|
|
25
31
|
* Interface declaring handling of received packets.
|
|
26
32
|
* When receiving a packet, its content is sent to feed(),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IFrameDecoder, IFrameEncoder } from '@fuman/io';
|
|
1
|
+
import { IClosable, IFrameDecoder, IFrameEncoder } from '@fuman/io';
|
|
2
2
|
import { IConnection } from '@fuman/net';
|
|
3
3
|
import { tl } from '../../tl/index.js';
|
|
4
4
|
import { MaybePromise } from '../../types/index.js';
|
|
@@ -18,9 +18,15 @@ export interface ITelegramConnection extends IConnection<any, any> {
|
|
|
18
18
|
}
|
|
19
19
|
export interface TelegramTransport {
|
|
20
20
|
setup?(crypto: ICryptoProvider, log: Logger): void;
|
|
21
|
-
connect: (dc: BasicDcOption) => Promise<ITelegramConnection>;
|
|
21
|
+
connect: (dc: BasicDcOption, abortSignal: AbortSignal) => Promise<ITelegramConnection>;
|
|
22
22
|
packetCodec: (dc: BasicDcOption) => IPacketCodec;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Run a post-connect handshake, closing the connection if `abortSignal`
|
|
26
|
+
* is aborted before it completes (which in turn makes any pending
|
|
27
|
+
* reads/writes inside the handshake reject)
|
|
28
|
+
*/
|
|
29
|
+
export declare function performHandshakeWithAbort<Connection extends IClosable>(conn: Connection, abortSignal: AbortSignal, handshake: () => Promise<void>): Promise<Connection>;
|
|
24
30
|
/**
|
|
25
31
|
* Interface declaring handling of received packets.
|
|
26
32
|
* When receiving a packet, its content is sent to feed(),
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
async function performHandshakeWithAbort(conn, abortSignal, handshake) {
|
|
2
|
+
if (abortSignal.aborted) {
|
|
3
|
+
conn.close();
|
|
4
|
+
throw abortSignal.reason;
|
|
5
|
+
}
|
|
6
|
+
const onAbort = () => conn.close();
|
|
7
|
+
abortSignal.addEventListener("abort", onAbort);
|
|
8
|
+
try {
|
|
9
|
+
await handshake();
|
|
10
|
+
} finally {
|
|
11
|
+
abortSignal.removeEventListener("abort", onAbort);
|
|
12
|
+
}
|
|
13
|
+
abortSignal.throwIfAborted();
|
|
14
|
+
return conn;
|
|
15
|
+
}
|
|
1
16
|
class TransportError extends Error {
|
|
2
17
|
code;
|
|
3
18
|
constructor(code) {
|
|
@@ -6,5 +21,6 @@ class TransportError extends Error {
|
|
|
6
21
|
}
|
|
7
22
|
}
|
|
8
23
|
export {
|
|
9
|
-
TransportError
|
|
24
|
+
TransportError,
|
|
25
|
+
performHandshakeWithAbort
|
|
10
26
|
};
|
|
@@ -74,7 +74,9 @@ class ObfuscatedPacketCodec {
|
|
|
74
74
|
const into = this._decodeBuf.writeSync(reader.available);
|
|
75
75
|
into.set(this._decryptor.process(reader.readSync(reader.available)));
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
const packet = await this._inner.decode(this._decodeBuf, eof);
|
|
78
|
+
this._decodeBuf.reclaim();
|
|
79
|
+
return packet;
|
|
78
80
|
}
|
|
79
81
|
reset() {
|
|
80
82
|
this._inner.reset();
|
|
@@ -67,7 +67,9 @@ class ObfuscatedPacketCodec {
|
|
|
67
67
|
const into = this._decodeBuf.writeSync(reader.available);
|
|
68
68
|
into.set(this._decryptor.process(reader.readSync(reader.available)));
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
const packet = await this._inner.decode(this._decodeBuf, eof);
|
|
71
|
+
this._decodeBuf.reclaim();
|
|
72
|
+
return packet;
|
|
71
73
|
}
|
|
72
74
|
reset() {
|
|
73
75
|
this._inner.reset();
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtcute/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.32.0",
|
|
5
5
|
"description": "Type-safe library for MTProto (Telegram API)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@fuman/io": "0.0.
|
|
10
|
-
"@fuman/net": "0.0.
|
|
11
|
-
"@fuman/utils": "0.0.
|
|
12
|
-
"@mtcute/file-id": "^0.
|
|
13
|
-
"@mtcute/tl-runtime": "^0.
|
|
9
|
+
"@fuman/io": "0.0.21",
|
|
10
|
+
"@fuman/net": "0.0.21",
|
|
11
|
+
"@fuman/utils": "0.0.21",
|
|
12
|
+
"@mtcute/file-id": "^0.32.0",
|
|
13
|
+
"@mtcute/tl-runtime": "^0.32.0",
|
|
14
14
|
"@types/events": "3.0.0",
|
|
15
15
|
"long": "^5.3.2"
|
|
16
16
|
},
|