@mtcute/core 0.1.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/LICENSE +8 -0
- package/README.md +26 -0
- package/cjs/base-client.d.ts +297 -0
- package/cjs/base-client.js +324 -0
- package/cjs/base-client.js.map +1 -0
- package/cjs/index.d.ts +10 -0
- package/cjs/index.js +30 -0
- package/cjs/index.js.map +1 -0
- package/cjs/network/auth-key.d.ts +21 -0
- package/cjs/network/auth-key.js +101 -0
- package/cjs/network/auth-key.js.map +1 -0
- package/cjs/network/authorization.d.ts +9 -0
- package/cjs/network/authorization.js +332 -0
- package/cjs/network/authorization.js.map +1 -0
- package/cjs/network/config-manager.d.ts +33 -0
- package/cjs/network/config-manager.js +93 -0
- package/cjs/network/config-manager.js.map +1 -0
- package/cjs/network/index.d.ts +4 -0
- package/cjs/network/index.js +20 -0
- package/cjs/network/index.js.map +1 -0
- package/cjs/network/mtproto-session.d.ts +116 -0
- package/cjs/network/mtproto-session.js +209 -0
- package/cjs/network/mtproto-session.js.map +1 -0
- package/cjs/network/multi-session-connection.d.ts +33 -0
- package/cjs/network/multi-session-connection.js +243 -0
- package/cjs/network/multi-session-connection.js.map +1 -0
- package/cjs/network/network-manager.d.ts +190 -0
- package/cjs/network/network-manager.js +547 -0
- package/cjs/network/network-manager.js.map +1 -0
- package/cjs/network/persistent-connection.d.ts +51 -0
- package/cjs/network/persistent-connection.js +173 -0
- package/cjs/network/persistent-connection.js.map +1 -0
- package/cjs/network/reconnection.d.ts +11 -0
- package/cjs/network/reconnection.js +18 -0
- package/cjs/network/reconnection.js.map +1 -0
- package/cjs/network/session-connection.d.ts +72 -0
- package/cjs/network/session-connection.js +1363 -0
- package/cjs/network/session-connection.js.map +1 -0
- package/cjs/network/transports/abstract.d.ts +99 -0
- package/cjs/network/transports/abstract.js +38 -0
- package/cjs/network/transports/abstract.js.map +1 -0
- package/cjs/network/transports/index.d.ts +8 -0
- package/cjs/network/transports/index.js +26 -0
- package/cjs/network/transports/index.js.map +1 -0
- package/cjs/network/transports/intermediate.d.ts +20 -0
- package/cjs/network/transports/intermediate.js +67 -0
- package/cjs/network/transports/intermediate.js.map +1 -0
- package/cjs/network/transports/obfuscated.d.ts +18 -0
- package/cjs/network/transports/obfuscated.js +83 -0
- package/cjs/network/transports/obfuscated.js.map +1 -0
- package/cjs/network/transports/streamed.d.ts +24 -0
- package/cjs/network/transports/streamed.js +32 -0
- package/cjs/network/transports/streamed.js.map +1 -0
- package/cjs/network/transports/tcp.d.ts +33 -0
- package/cjs/network/transports/tcp.js +130 -0
- package/cjs/network/transports/tcp.js.map +1 -0
- package/cjs/network/transports/websocket.d.ts +47 -0
- package/cjs/network/transports/websocket.js +124 -0
- package/cjs/network/transports/websocket.js.map +1 -0
- package/cjs/network/transports/wrapped.d.ts +11 -0
- package/cjs/network/transports/wrapped.js +26 -0
- package/cjs/network/transports/wrapped.js.map +1 -0
- package/cjs/package.json +3 -0
- package/cjs/storage/abstract.d.ts +174 -0
- package/cjs/storage/abstract.js +3 -0
- package/cjs/storage/abstract.js.map +1 -0
- package/cjs/storage/index.d.ts +5 -0
- package/cjs/storage/index.js +22 -0
- package/cjs/storage/index.js.map +1 -0
- package/cjs/storage/json-file.d.ts +31 -0
- package/cjs/storage/json-file.js +90 -0
- package/cjs/storage/json-file.js.map +1 -0
- package/cjs/storage/json.d.ts +9 -0
- package/cjs/storage/json.js +65 -0
- package/cjs/storage/json.js.map +1 -0
- package/cjs/storage/localstorage.d.ts +7 -0
- package/cjs/storage/localstorage.js +25 -0
- package/cjs/storage/localstorage.js.map +1 -0
- package/cjs/storage/memory.d.ts +98 -0
- package/cjs/storage/memory.js +299 -0
- package/cjs/storage/memory.js.map +1 -0
- package/cjs/types/errors.d.ts +53 -0
- package/cjs/types/errors.js +58 -0
- package/cjs/types/errors.js.map +1 -0
- package/cjs/types/index.d.ts +3 -0
- package/cjs/types/index.js +20 -0
- package/cjs/types/index.js.map +1 -0
- package/cjs/types/peers.d.ts +4 -0
- package/cjs/types/peers.js +3 -0
- package/cjs/types/peers.js.map +1 -0
- package/cjs/types/utils.d.ts +6 -0
- package/cjs/types/utils.js +9 -0
- package/cjs/types/utils.js.map +1 -0
- package/cjs/utils/async-lock.d.ts +10 -0
- package/cjs/utils/async-lock.js +43 -0
- package/cjs/utils/async-lock.js.map +1 -0
- package/cjs/utils/bigint-utils.d.ts +40 -0
- package/cjs/utils/bigint-utils.js +104 -0
- package/cjs/utils/bigint-utils.js.map +1 -0
- package/cjs/utils/binary/asn1-parser.d.ts +17 -0
- package/cjs/utils/binary/asn1-parser.js +121 -0
- package/cjs/utils/binary/asn1-parser.js.map +1 -0
- package/cjs/utils/buffer-utils.d.ts +21 -0
- package/cjs/utils/buffer-utils.js +63 -0
- package/cjs/utils/buffer-utils.js.map +1 -0
- package/cjs/utils/condition-variable.d.ts +9 -0
- package/cjs/utils/condition-variable.js +28 -0
- package/cjs/utils/condition-variable.js.map +1 -0
- package/cjs/utils/controllable-promise.d.ts +16 -0
- package/cjs/utils/controllable-promise.js +25 -0
- package/cjs/utils/controllable-promise.js.map +1 -0
- package/cjs/utils/crypto/abstract.d.ts +23 -0
- package/cjs/utils/crypto/abstract.js +19 -0
- package/cjs/utils/crypto/abstract.js.map +1 -0
- package/cjs/utils/crypto/common.d.ts +12 -0
- package/cjs/utils/crypto/common.js +54 -0
- package/cjs/utils/crypto/common.js.map +1 -0
- package/cjs/utils/crypto/factorization.d.ts +5 -0
- package/cjs/utils/crypto/factorization.js +69 -0
- package/cjs/utils/crypto/factorization.js.map +1 -0
- package/cjs/utils/crypto/index.d.ts +5 -0
- package/cjs/utils/crypto/index.js +23 -0
- package/cjs/utils/crypto/index.js.map +1 -0
- package/cjs/utils/crypto/keys.d.ts +27 -0
- package/cjs/utils/crypto/keys.js +70 -0
- package/cjs/utils/crypto/keys.js.map +1 -0
- package/cjs/utils/crypto/miller-rabin.d.ts +2 -0
- package/cjs/utils/crypto/miller-rabin.js +44 -0
- package/cjs/utils/crypto/miller-rabin.js.map +1 -0
- package/cjs/utils/crypto/mtproto.d.ts +31 -0
- package/cjs/utils/crypto/mtproto.js +66 -0
- package/cjs/utils/crypto/mtproto.js.map +1 -0
- package/cjs/utils/crypto/node-crypto.d.ts +10 -0
- package/cjs/utils/crypto/node-crypto.js +46 -0
- package/cjs/utils/crypto/node-crypto.js.map +1 -0
- package/cjs/utils/crypto/password.d.ts +29 -0
- package/cjs/utils/crypto/password.js +106 -0
- package/cjs/utils/crypto/password.js.map +1 -0
- package/cjs/utils/crypto/subtle.d.ts +12 -0
- package/cjs/utils/crypto/subtle.js +86 -0
- package/cjs/utils/crypto/subtle.js.map +1 -0
- package/cjs/utils/crypto/utils.d.ts +14 -0
- package/cjs/utils/crypto/utils.js +30 -0
- package/cjs/utils/crypto/utils.js.map +1 -0
- package/cjs/utils/default-dcs.d.ts +7 -0
- package/cjs/utils/default-dcs.js +76 -0
- package/cjs/utils/default-dcs.js.map +1 -0
- package/cjs/utils/deque.d.ts +29 -0
- package/cjs/utils/deque.js +210 -0
- package/cjs/utils/deque.js.map +1 -0
- package/cjs/utils/early-timer.d.ts +42 -0
- package/cjs/utils/early-timer.js +79 -0
- package/cjs/utils/early-timer.js.map +1 -0
- package/cjs/utils/flood-control.d.ts +14 -0
- package/cjs/utils/flood-control.js +65 -0
- package/cjs/utils/flood-control.js.map +1 -0
- package/cjs/utils/function-utils.d.ts +13 -0
- package/cjs/utils/function-utils.js +30 -0
- package/cjs/utils/function-utils.js.map +1 -0
- package/cjs/utils/index.d.ts +24 -0
- package/cjs/utils/index.js +41 -0
- package/cjs/utils/index.js.map +1 -0
- package/cjs/utils/linked-list.d.ts +21 -0
- package/cjs/utils/linked-list.js +73 -0
- package/cjs/utils/linked-list.js.map +1 -0
- package/cjs/utils/links/bots.d.ts +71 -0
- package/cjs/utils/links/bots.js +259 -0
- package/cjs/utils/links/bots.js.map +1 -0
- package/cjs/utils/links/bundle.d.ts +7 -0
- package/cjs/utils/links/bundle.js +24 -0
- package/cjs/utils/links/bundle.js.map +1 -0
- package/cjs/utils/links/calls.d.ts +16 -0
- package/cjs/utils/links/calls.js +59 -0
- package/cjs/utils/links/calls.js.map +1 -0
- package/cjs/utils/links/chat.d.ts +46 -0
- package/cjs/utils/links/chat.js +160 -0
- package/cjs/utils/links/chat.js.map +1 -0
- package/cjs/utils/links/common.d.ts +31 -0
- package/cjs/utils/links/common.js +60 -0
- package/cjs/utils/links/common.js.map +1 -0
- package/cjs/utils/links/index.d.ts +2 -0
- package/cjs/utils/links/index.js +29 -0
- package/cjs/utils/links/index.js.map +1 -0
- package/cjs/utils/links/misc.d.ts +19 -0
- package/cjs/utils/links/misc.js +77 -0
- package/cjs/utils/links/misc.js.map +1 -0
- package/cjs/utils/links/proxy.d.ts +17 -0
- package/cjs/utils/links/proxy.js +61 -0
- package/cjs/utils/links/proxy.js.map +1 -0
- package/cjs/utils/links/stickers.d.ts +9 -0
- package/cjs/utils/links/stickers.js +28 -0
- package/cjs/utils/links/stickers.js.map +1 -0
- package/cjs/utils/links/user.d.ts +27 -0
- package/cjs/utils/links/user.js +81 -0
- package/cjs/utils/links/user.js.map +1 -0
- package/cjs/utils/logger.d.ts +54 -0
- package/cjs/utils/logger.js +158 -0
- package/cjs/utils/logger.js.map +1 -0
- package/cjs/utils/long-utils.d.ts +75 -0
- package/cjs/utils/long-utils.js +161 -0
- package/cjs/utils/long-utils.js.map +1 -0
- package/cjs/utils/lru-map.d.ts +21 -0
- package/cjs/utils/lru-map.js +107 -0
- package/cjs/utils/lru-map.js.map +1 -0
- package/cjs/utils/lru-set.d.ts +22 -0
- package/cjs/utils/lru-set.js +48 -0
- package/cjs/utils/lru-set.js.map +1 -0
- package/cjs/utils/misc-utils.d.ts +7 -0
- package/cjs/utils/misc-utils.js +15 -0
- package/cjs/utils/misc-utils.js.map +1 -0
- package/cjs/utils/peer-utils.d.ts +35 -0
- package/cjs/utils/peer-utils.js +188 -0
- package/cjs/utils/peer-utils.js.map +1 -0
- package/cjs/utils/platform/crypto.d.ts +1 -0
- package/cjs/utils/platform/crypto.js +8 -0
- package/cjs/utils/platform/crypto.js.map +1 -0
- package/cjs/utils/platform/crypto.web.d.ts +1 -0
- package/cjs/utils/platform/crypto.web.js +14 -0
- package/cjs/utils/platform/crypto.web.js.map +1 -0
- package/cjs/utils/platform/error-reporting.d.ts +3 -0
- package/cjs/utils/platform/error-reporting.js +22 -0
- package/cjs/utils/platform/error-reporting.js.map +1 -0
- package/cjs/utils/platform/logging.d.ts +1 -0
- package/cjs/utils/platform/logging.js +35 -0
- package/cjs/utils/platform/logging.js.map +1 -0
- package/cjs/utils/platform/logging.web.d.ts +1 -0
- package/cjs/utils/platform/logging.web.js +35 -0
- package/cjs/utils/platform/logging.web.js.map +1 -0
- package/cjs/utils/platform/random.d.ts +1 -0
- package/cjs/utils/platform/random.js +7 -0
- package/cjs/utils/platform/random.js.map +1 -0
- package/cjs/utils/platform/random.web.d.ts +1 -0
- package/cjs/utils/platform/random.web.js +10 -0
- package/cjs/utils/platform/random.web.js.map +1 -0
- package/cjs/utils/platform/transport.d.ts +1 -0
- package/cjs/utils/platform/transport.js +8 -0
- package/cjs/utils/platform/transport.js.map +1 -0
- package/cjs/utils/platform/transport.web.d.ts +1 -0
- package/cjs/utils/platform/transport.web.js +15 -0
- package/cjs/utils/platform/transport.web.js.map +1 -0
- package/cjs/utils/sorted-array.d.ts +17 -0
- package/cjs/utils/sorted-array.js +83 -0
- package/cjs/utils/sorted-array.js.map +1 -0
- package/cjs/utils/string-session.d.ts +11 -0
- package/cjs/utils/string-session.js +73 -0
- package/cjs/utils/string-session.js.map +1 -0
- package/cjs/utils/tl-json.d.ts +13 -0
- package/cjs/utils/tl-json.js +62 -0
- package/cjs/utils/tl-json.js.map +1 -0
- package/cjs/utils/type-assertions.d.ts +37 -0
- package/cjs/utils/type-assertions.js +70 -0
- package/cjs/utils/type-assertions.js.map +1 -0
- package/esm/base-client.d.ts +297 -0
- package/esm/base-client.js +317 -0
- package/esm/base-client.js.map +1 -0
- package/esm/index.d.ts +10 -0
- package/esm/index.js +11 -0
- package/esm/index.js.map +1 -0
- package/esm/network/auth-key.d.ts +21 -0
- package/esm/network/auth-key.js +97 -0
- package/esm/network/auth-key.js.map +1 -0
- package/esm/network/authorization.d.ts +9 -0
- package/esm/network/authorization.js +325 -0
- package/esm/network/authorization.js.map +1 -0
- package/esm/network/config-manager.d.ts +33 -0
- package/esm/network/config-manager.js +89 -0
- package/esm/network/config-manager.js.map +1 -0
- package/esm/network/index.d.ts +4 -0
- package/esm/network/index.js +4 -0
- package/esm/network/index.js.map +1 -0
- package/esm/network/mtproto-session.d.ts +116 -0
- package/esm/network/mtproto-session.js +202 -0
- package/esm/network/mtproto-session.js.map +1 -0
- package/esm/network/multi-session-connection.d.ts +33 -0
- package/esm/network/multi-session-connection.js +236 -0
- package/esm/network/multi-session-connection.js.map +1 -0
- package/esm/network/network-manager.d.ts +190 -0
- package/esm/network/network-manager.js +542 -0
- package/esm/network/network-manager.js.map +1 -0
- package/esm/network/persistent-connection.d.ts +51 -0
- package/esm/network/persistent-connection.js +166 -0
- package/esm/network/persistent-connection.js.map +1 -0
- package/esm/network/reconnection.d.ts +11 -0
- package/esm/network/reconnection.js +14 -0
- package/esm/network/reconnection.js.map +1 -0
- package/esm/network/session-connection.d.ts +72 -0
- package/esm/network/session-connection.js +1356 -0
- package/esm/network/session-connection.js.map +1 -0
- package/esm/network/transports/abstract.d.ts +99 -0
- package/esm/network/transports/abstract.js +34 -0
- package/esm/network/transports/abstract.js.map +1 -0
- package/esm/network/transports/index.d.ts +8 -0
- package/esm/network/transports/index.js +9 -0
- package/esm/network/transports/index.js.map +1 -0
- package/esm/network/transports/intermediate.d.ts +20 -0
- package/esm/network/transports/intermediate.js +62 -0
- package/esm/network/transports/intermediate.js.map +1 -0
- package/esm/network/transports/obfuscated.d.ts +18 -0
- package/esm/network/transports/obfuscated.js +79 -0
- package/esm/network/transports/obfuscated.js.map +1 -0
- package/esm/network/transports/streamed.d.ts +24 -0
- package/esm/network/transports/streamed.js +25 -0
- package/esm/network/transports/streamed.js.map +1 -0
- package/esm/network/transports/tcp.d.ts +33 -0
- package/esm/network/transports/tcp.js +122 -0
- package/esm/network/transports/tcp.js.map +1 -0
- package/esm/network/transports/websocket.d.ts +47 -0
- package/esm/network/transports/websocket.js +116 -0
- package/esm/network/transports/websocket.js.map +1 -0
- package/esm/network/transports/wrapped.d.ts +11 -0
- package/esm/network/transports/wrapped.js +19 -0
- package/esm/network/transports/wrapped.js.map +1 -0
- package/esm/storage/abstract.d.ts +174 -0
- package/esm/storage/abstract.js +2 -0
- package/esm/storage/abstract.js.map +1 -0
- package/esm/storage/index.d.ts +5 -0
- package/esm/storage/index.js +6 -0
- package/esm/storage/index.js.map +1 -0
- package/esm/storage/json-file.d.ts +31 -0
- package/esm/storage/json-file.js +63 -0
- package/esm/storage/json-file.js.map +1 -0
- package/esm/storage/json.d.ts +9 -0
- package/esm/storage/json.js +61 -0
- package/esm/storage/json.js.map +1 -0
- package/esm/storage/localstorage.d.ts +7 -0
- package/esm/storage/localstorage.js +21 -0
- package/esm/storage/localstorage.js.map +1 -0
- package/esm/storage/memory.d.ts +98 -0
- package/esm/storage/memory.js +295 -0
- package/esm/storage/memory.js.map +1 -0
- package/esm/types/errors.d.ts +53 -0
- package/esm/types/errors.js +49 -0
- package/esm/types/errors.js.map +1 -0
- package/esm/types/index.d.ts +3 -0
- package/esm/types/index.js +4 -0
- package/esm/types/index.js.map +1 -0
- package/esm/types/peers.d.ts +4 -0
- package/esm/types/peers.js +2 -0
- package/esm/types/peers.js.map +1 -0
- package/esm/types/utils.d.ts +6 -0
- package/esm/types/utils.js +5 -0
- package/esm/types/utils.js.map +1 -0
- package/esm/utils/async-lock.d.ts +10 -0
- package/esm/utils/async-lock.js +39 -0
- package/esm/utils/async-lock.js.map +1 -0
- package/esm/utils/bigint-utils.d.ts +40 -0
- package/esm/utils/bigint-utils.js +92 -0
- package/esm/utils/bigint-utils.js.map +1 -0
- package/esm/utils/binary/asn1-parser.d.ts +17 -0
- package/esm/utils/binary/asn1-parser.js +116 -0
- package/esm/utils/binary/asn1-parser.js.map +1 -0
- package/esm/utils/buffer-utils.d.ts +21 -0
- package/esm/utils/buffer-utils.js +55 -0
- package/esm/utils/buffer-utils.js.map +1 -0
- package/esm/utils/condition-variable.d.ts +9 -0
- package/esm/utils/condition-variable.js +24 -0
- package/esm/utils/condition-variable.js.map +1 -0
- package/esm/utils/controllable-promise.d.ts +16 -0
- package/esm/utils/controllable-promise.js +20 -0
- package/esm/utils/controllable-promise.js.map +1 -0
- package/esm/utils/crypto/abstract.d.ts +23 -0
- package/esm/utils/crypto/abstract.js +15 -0
- package/esm/utils/crypto/abstract.js.map +1 -0
- package/esm/utils/crypto/common.d.ts +12 -0
- package/esm/utils/crypto/common.js +50 -0
- package/esm/utils/crypto/common.js.map +1 -0
- package/esm/utils/crypto/factorization.d.ts +5 -0
- package/esm/utils/crypto/factorization.js +62 -0
- package/esm/utils/crypto/factorization.js.map +1 -0
- package/esm/utils/crypto/index.d.ts +5 -0
- package/esm/utils/crypto/index.js +6 -0
- package/esm/utils/crypto/index.js.map +1 -0
- package/esm/utils/crypto/keys.d.ts +27 -0
- package/esm/utils/crypto/keys.js +64 -0
- package/esm/utils/crypto/keys.js.map +1 -0
- package/esm/utils/crypto/miller-rabin.d.ts +2 -0
- package/esm/utils/crypto/miller-rabin.js +37 -0
- package/esm/utils/crypto/miller-rabin.js.map +1 -0
- package/esm/utils/crypto/mtproto.d.ts +31 -0
- package/esm/utils/crypto/mtproto.js +60 -0
- package/esm/utils/crypto/mtproto.js.map +1 -0
- package/esm/utils/crypto/node-crypto.d.ts +10 -0
- package/esm/utils/crypto/node-crypto.js +42 -0
- package/esm/utils/crypto/node-crypto.js.map +1 -0
- package/esm/utils/crypto/password.d.ts +29 -0
- package/esm/utils/crypto/password.js +97 -0
- package/esm/utils/crypto/password.js.map +1 -0
- package/esm/utils/crypto/subtle.d.ts +12 -0
- package/esm/utils/crypto/subtle.js +59 -0
- package/esm/utils/crypto/subtle.js.map +1 -0
- package/esm/utils/crypto/utils.d.ts +14 -0
- package/esm/utils/crypto/utils.js +25 -0
- package/esm/utils/crypto/utils.js.map +1 -0
- package/esm/utils/default-dcs.d.ts +7 -0
- package/esm/utils/default-dcs.js +73 -0
- package/esm/utils/default-dcs.js.map +1 -0
- package/esm/utils/deque.d.ts +29 -0
- package/esm/utils/deque.js +206 -0
- package/esm/utils/deque.js.map +1 -0
- package/esm/utils/early-timer.d.ts +42 -0
- package/esm/utils/early-timer.js +75 -0
- package/esm/utils/early-timer.js.map +1 -0
- package/esm/utils/flood-control.d.ts +14 -0
- package/esm/utils/flood-control.js +61 -0
- package/esm/utils/flood-control.js.map +1 -0
- package/esm/utils/function-utils.d.ts +13 -0
- package/esm/utils/function-utils.js +26 -0
- package/esm/utils/function-utils.js.map +1 -0
- package/esm/utils/index.d.ts +24 -0
- package/esm/utils/index.js +25 -0
- package/esm/utils/index.js.map +1 -0
- package/esm/utils/linked-list.d.ts +21 -0
- package/esm/utils/linked-list.js +69 -0
- package/esm/utils/linked-list.js.map +1 -0
- package/esm/utils/links/bots.d.ts +71 -0
- package/esm/utils/links/bots.js +256 -0
- package/esm/utils/links/bots.js.map +1 -0
- package/esm/utils/links/bundle.d.ts +7 -0
- package/esm/utils/links/bundle.js +8 -0
- package/esm/utils/links/bundle.js.map +1 -0
- package/esm/utils/links/calls.d.ts +16 -0
- package/esm/utils/links/calls.js +56 -0
- package/esm/utils/links/calls.js.map +1 -0
- package/esm/utils/links/chat.d.ts +46 -0
- package/esm/utils/links/chat.js +157 -0
- package/esm/utils/links/chat.js.map +1 -0
- package/esm/utils/links/common.d.ts +31 -0
- package/esm/utils/links/common.js +56 -0
- package/esm/utils/links/common.js.map +1 -0
- package/esm/utils/links/index.d.ts +2 -0
- package/esm/utils/links/index.js +3 -0
- package/esm/utils/links/index.js.map +1 -0
- package/esm/utils/links/misc.d.ts +19 -0
- package/esm/utils/links/misc.js +74 -0
- package/esm/utils/links/misc.js.map +1 -0
- package/esm/utils/links/proxy.d.ts +17 -0
- package/esm/utils/links/proxy.js +58 -0
- package/esm/utils/links/proxy.js.map +1 -0
- package/esm/utils/links/stickers.d.ts +9 -0
- package/esm/utils/links/stickers.js +25 -0
- package/esm/utils/links/stickers.js.map +1 -0
- package/esm/utils/links/user.d.ts +27 -0
- package/esm/utils/links/user.js +78 -0
- package/esm/utils/links/user.js.map +1 -0
- package/esm/utils/logger.d.ts +54 -0
- package/esm/utils/logger.js +154 -0
- package/esm/utils/logger.js.map +1 -0
- package/esm/utils/long-utils.d.ts +75 -0
- package/esm/utils/long-utils.js +148 -0
- package/esm/utils/long-utils.js.map +1 -0
- package/esm/utils/lru-map.d.ts +21 -0
- package/esm/utils/lru-map.js +103 -0
- package/esm/utils/lru-map.js.map +1 -0
- package/esm/utils/lru-set.d.ts +22 -0
- package/esm/utils/lru-set.js +44 -0
- package/esm/utils/lru-set.js.map +1 -0
- package/esm/utils/misc-utils.d.ts +7 -0
- package/esm/utils/misc-utils.js +10 -0
- package/esm/utils/misc-utils.js.map +1 -0
- package/esm/utils/peer-utils.d.ts +35 -0
- package/esm/utils/peer-utils.js +179 -0
- package/esm/utils/peer-utils.js.map +1 -0
- package/esm/utils/platform/crypto.d.ts +1 -0
- package/esm/utils/platform/crypto.js +4 -0
- package/esm/utils/platform/crypto.js.map +1 -0
- package/esm/utils/platform/crypto.web.d.ts +1 -0
- package/esm/utils/platform/crypto.web.js +10 -0
- package/esm/utils/platform/crypto.web.js.map +1 -0
- package/esm/utils/platform/error-reporting.d.ts +3 -0
- package/esm/utils/platform/error-reporting.js +18 -0
- package/esm/utils/platform/error-reporting.js.map +1 -0
- package/esm/utils/platform/logging.d.ts +1 -0
- package/esm/utils/platform/logging.js +32 -0
- package/esm/utils/platform/logging.js.map +1 -0
- package/esm/utils/platform/logging.web.d.ts +1 -0
- package/esm/utils/platform/logging.web.js +31 -0
- package/esm/utils/platform/logging.web.js.map +1 -0
- package/esm/utils/platform/random.d.ts +1 -0
- package/esm/utils/platform/random.js +4 -0
- package/esm/utils/platform/random.js.map +1 -0
- package/esm/utils/platform/random.web.d.ts +1 -0
- package/esm/utils/platform/random.web.js +6 -0
- package/esm/utils/platform/random.web.js.map +1 -0
- package/esm/utils/platform/transport.d.ts +1 -0
- package/esm/utils/platform/transport.js +4 -0
- package/esm/utils/platform/transport.js.map +1 -0
- package/esm/utils/platform/transport.web.d.ts +1 -0
- package/esm/utils/platform/transport.web.js +12 -0
- package/esm/utils/platform/transport.web.js.map +1 -0
- package/esm/utils/sorted-array.d.ts +17 -0
- package/esm/utils/sorted-array.js +79 -0
- package/esm/utils/sorted-array.js.map +1 -0
- package/esm/utils/string-session.d.ts +11 -0
- package/esm/utils/string-session.js +68 -0
- package/esm/utils/string-session.js.map +1 -0
- package/esm/utils/tl-json.d.ts +13 -0
- package/esm/utils/tl-json.js +57 -0
- package/esm/utils/tl-json.js.map +1 -0
- package/esm/utils/type-assertions.d.ts +37 -0
- package/esm/utils/type-assertions.js +61 -0
- package/esm/utils/type-assertions.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
|
+
import { tl } from '@mtcute/tl';
|
|
4
|
+
import { ICryptoProvider, Logger } from '../utils/index.js';
|
|
5
|
+
import { ReconnectionStrategy } from './reconnection.js';
|
|
6
|
+
import { ITelegramTransport, TransportFactory } from './transports/index.js';
|
|
7
|
+
export interface PersistentConnectionParams {
|
|
8
|
+
crypto: ICryptoProvider;
|
|
9
|
+
transportFactory: TransportFactory;
|
|
10
|
+
dc: tl.RawDcOption;
|
|
11
|
+
testMode: boolean;
|
|
12
|
+
reconnectionStrategy: ReconnectionStrategy<PersistentConnectionParams>;
|
|
13
|
+
inactivityTimeout?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Base class for persistent connections.
|
|
17
|
+
* Only used for {@link PersistentConnection} and used as a mean of code splitting.
|
|
18
|
+
* This class doesn't know anything about MTProto, it just manages the transport.
|
|
19
|
+
*/
|
|
20
|
+
export declare abstract class PersistentConnection extends EventEmitter {
|
|
21
|
+
readonly log: Logger;
|
|
22
|
+
private _uid;
|
|
23
|
+
readonly params: PersistentConnectionParams;
|
|
24
|
+
protected _transport: ITelegramTransport;
|
|
25
|
+
private _sendOnceConnected;
|
|
26
|
+
private _lastError;
|
|
27
|
+
private _consequentFails;
|
|
28
|
+
private _previousWait;
|
|
29
|
+
private _reconnectionTimeout;
|
|
30
|
+
private _inactivityTimeout;
|
|
31
|
+
private _inactive;
|
|
32
|
+
_destroyed: boolean;
|
|
33
|
+
_usable: boolean;
|
|
34
|
+
protected abstract onConnected(): void;
|
|
35
|
+
protected abstract onError(err: Error): void;
|
|
36
|
+
protected abstract onMessage(data: Uint8Array): void;
|
|
37
|
+
protected constructor(params: PersistentConnectionParams, log: Logger);
|
|
38
|
+
get isConnected(): boolean;
|
|
39
|
+
changeTransport(factory: TransportFactory): void;
|
|
40
|
+
onTransportReady(): void;
|
|
41
|
+
protected onConnectionUsable(): void;
|
|
42
|
+
onTransportError(err: Error): void;
|
|
43
|
+
onTransportClose(): void;
|
|
44
|
+
connect(): void;
|
|
45
|
+
reconnect(): void;
|
|
46
|
+
destroy(): void;
|
|
47
|
+
protected _rescheduleInactivity(): void;
|
|
48
|
+
protected _onInactivityTimeout(): void;
|
|
49
|
+
setInactivityTimeout(timeout?: number): void;
|
|
50
|
+
send(data: Uint8Array): Promise<void>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { MtcuteError } from '../types/index.js';
|
|
3
|
+
import { TransportState } from './transports/index.js';
|
|
4
|
+
let nextConnectionUid = 0;
|
|
5
|
+
/**
|
|
6
|
+
* Base class for persistent connections.
|
|
7
|
+
* Only used for {@link PersistentConnection} and used as a mean of code splitting.
|
|
8
|
+
* This class doesn't know anything about MTProto, it just manages the transport.
|
|
9
|
+
*/
|
|
10
|
+
export class PersistentConnection extends EventEmitter {
|
|
11
|
+
constructor(params, log) {
|
|
12
|
+
super();
|
|
13
|
+
this.log = log;
|
|
14
|
+
this._uid = nextConnectionUid++;
|
|
15
|
+
this._sendOnceConnected = [];
|
|
16
|
+
// reconnection
|
|
17
|
+
this._lastError = null;
|
|
18
|
+
this._consequentFails = 0;
|
|
19
|
+
this._previousWait = null;
|
|
20
|
+
this._reconnectionTimeout = null;
|
|
21
|
+
// inactivity timeout
|
|
22
|
+
this._inactivityTimeout = null;
|
|
23
|
+
this._inactive = true;
|
|
24
|
+
this._destroyed = false;
|
|
25
|
+
this._usable = false;
|
|
26
|
+
this.params = params;
|
|
27
|
+
this.changeTransport(params.transportFactory);
|
|
28
|
+
this.log.prefix = `[UID ${this._uid}] `;
|
|
29
|
+
this._onInactivityTimeout = this._onInactivityTimeout.bind(this);
|
|
30
|
+
}
|
|
31
|
+
get isConnected() {
|
|
32
|
+
return this._transport.state() !== TransportState.Idle;
|
|
33
|
+
}
|
|
34
|
+
changeTransport(factory) {
|
|
35
|
+
if (this._transport) {
|
|
36
|
+
this._transport.close();
|
|
37
|
+
}
|
|
38
|
+
this._transport = factory();
|
|
39
|
+
this._transport.setup?.(this.params.crypto, this.log);
|
|
40
|
+
this._transport.on('ready', this.onTransportReady.bind(this));
|
|
41
|
+
this._transport.on('message', this.onMessage.bind(this));
|
|
42
|
+
this._transport.on('error', this.onTransportError.bind(this));
|
|
43
|
+
this._transport.on('close', this.onTransportClose.bind(this));
|
|
44
|
+
}
|
|
45
|
+
onTransportReady() {
|
|
46
|
+
// transport ready does not mean actual mtproto is ready
|
|
47
|
+
if (this._sendOnceConnected.length) {
|
|
48
|
+
const sendNext = () => {
|
|
49
|
+
if (!this._sendOnceConnected.length) {
|
|
50
|
+
this.onConnected();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const data = this._sendOnceConnected.shift();
|
|
54
|
+
this._transport
|
|
55
|
+
.send(data)
|
|
56
|
+
.then(sendNext)
|
|
57
|
+
.catch((err) => {
|
|
58
|
+
this.log.error('error sending queued data: %s', err);
|
|
59
|
+
this._sendOnceConnected.unshift(data);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
sendNext();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.onConnected();
|
|
66
|
+
}
|
|
67
|
+
onConnectionUsable() {
|
|
68
|
+
const isReconnection = this._consequentFails > 0;
|
|
69
|
+
// reset reconnection related state
|
|
70
|
+
this._lastError = null;
|
|
71
|
+
this._consequentFails = 0;
|
|
72
|
+
this._previousWait = null;
|
|
73
|
+
this._usable = true;
|
|
74
|
+
this.emit('usable', isReconnection);
|
|
75
|
+
this._rescheduleInactivity();
|
|
76
|
+
}
|
|
77
|
+
onTransportError(err) {
|
|
78
|
+
this._lastError = err;
|
|
79
|
+
this.onError(err);
|
|
80
|
+
// transport is expected to emit `close` after `error`
|
|
81
|
+
}
|
|
82
|
+
onTransportClose() {
|
|
83
|
+
// transport closed because of inactivity
|
|
84
|
+
// obviously we dont want to reconnect then
|
|
85
|
+
if (this._inactive)
|
|
86
|
+
return;
|
|
87
|
+
this._consequentFails += 1;
|
|
88
|
+
const wait = this.params.reconnectionStrategy(this.params, this._lastError, this._consequentFails, this._previousWait);
|
|
89
|
+
if (wait === false) {
|
|
90
|
+
this.destroy();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.emit('wait', wait);
|
|
94
|
+
this._previousWait = wait;
|
|
95
|
+
if (this._reconnectionTimeout != null) {
|
|
96
|
+
clearTimeout(this._reconnectionTimeout);
|
|
97
|
+
}
|
|
98
|
+
this._reconnectionTimeout = setTimeout(() => {
|
|
99
|
+
if (this._destroyed)
|
|
100
|
+
return;
|
|
101
|
+
this._reconnectionTimeout = null;
|
|
102
|
+
this.connect();
|
|
103
|
+
}, wait);
|
|
104
|
+
}
|
|
105
|
+
connect() {
|
|
106
|
+
if (this.isConnected) {
|
|
107
|
+
throw new MtcuteError('Connection is already opened!');
|
|
108
|
+
}
|
|
109
|
+
if (this._destroyed) {
|
|
110
|
+
throw new MtcuteError('Connection is already destroyed!');
|
|
111
|
+
}
|
|
112
|
+
if (this._reconnectionTimeout != null) {
|
|
113
|
+
clearTimeout(this._reconnectionTimeout);
|
|
114
|
+
}
|
|
115
|
+
this._inactive = false;
|
|
116
|
+
this._transport.connect(this.params.dc, this.params.testMode);
|
|
117
|
+
}
|
|
118
|
+
reconnect() {
|
|
119
|
+
this._transport.close();
|
|
120
|
+
}
|
|
121
|
+
destroy() {
|
|
122
|
+
if (this._reconnectionTimeout != null) {
|
|
123
|
+
clearTimeout(this._reconnectionTimeout);
|
|
124
|
+
}
|
|
125
|
+
if (this._inactivityTimeout != null) {
|
|
126
|
+
clearTimeout(this._inactivityTimeout);
|
|
127
|
+
}
|
|
128
|
+
this._transport.close();
|
|
129
|
+
this._transport.removeAllListeners();
|
|
130
|
+
this._destroyed = true;
|
|
131
|
+
}
|
|
132
|
+
_rescheduleInactivity() {
|
|
133
|
+
if (!this.params.inactivityTimeout)
|
|
134
|
+
return;
|
|
135
|
+
if (this._inactivityTimeout)
|
|
136
|
+
clearTimeout(this._inactivityTimeout);
|
|
137
|
+
this._inactivityTimeout = setTimeout(this._onInactivityTimeout, this.params.inactivityTimeout);
|
|
138
|
+
}
|
|
139
|
+
_onInactivityTimeout() {
|
|
140
|
+
this.log.info('disconnected because of inactivity for %d', this.params.inactivityTimeout);
|
|
141
|
+
this._inactive = true;
|
|
142
|
+
this._inactivityTimeout = null;
|
|
143
|
+
this._transport.close();
|
|
144
|
+
}
|
|
145
|
+
setInactivityTimeout(timeout) {
|
|
146
|
+
this.params.inactivityTimeout = timeout;
|
|
147
|
+
if (this._inactivityTimeout) {
|
|
148
|
+
clearTimeout(this._inactivityTimeout);
|
|
149
|
+
}
|
|
150
|
+
if (timeout) {
|
|
151
|
+
this._rescheduleInactivity();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async send(data) {
|
|
155
|
+
if (this._inactive) {
|
|
156
|
+
this.connect();
|
|
157
|
+
}
|
|
158
|
+
if (this._transport.state() === TransportState.Ready) {
|
|
159
|
+
await this._transport.send(data);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
this._sendOnceConnected.push(data);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=persistent-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistent-connection.js","sourceRoot":"","sources":["../../../src/network/persistent-connection.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAA;AAIjC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,OAAO,EAAwC,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAW5F,IAAI,iBAAiB,GAAG,CAAC,CAAA;AAEzB;;;;GAIG;AACH,MAAM,OAAgB,oBAAqB,SAAQ,YAAY;IA2B3D,YACI,MAAkC,EACzB,GAAW;QAEpB,KAAK,EAAE,CAAA;QAFE,QAAG,GAAH,GAAG,CAAQ;QA5BhB,SAAI,GAAG,iBAAiB,EAAE,CAAA;QAK1B,uBAAkB,GAAiB,EAAE,CAAA;QAE7C,eAAe;QACP,eAAU,GAAiB,IAAI,CAAA;QAC/B,qBAAgB,GAAG,CAAC,CAAA;QACpB,kBAAa,GAAkB,IAAI,CAAA;QACnC,yBAAoB,GAA0B,IAAI,CAAA;QAE1D,qBAAqB;QACb,uBAAkB,GAA0B,IAAI,CAAA;QAChD,cAAS,GAAG,IAAI,CAAA;QAExB,eAAU,GAAG,KAAK,CAAA;QAClB,YAAO,GAAG,KAAK,CAAA;QAaX,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA;QAE7C,IA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ED,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,cAAc,CAAC,KAAK,EAAE;YAClD,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;SACnC;aAAM;YACH,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;SACrC;IACL,CAAC;CACJ","sourcesContent":["import EventEmitter from 'events'\n\nimport { tl } from '@mtcute/tl'\n\nimport { MtcuteError } from '../types/index.js'\nimport { ICryptoProvider, Logger } from '../utils/index.js'\nimport { ReconnectionStrategy } from './reconnection.js'\nimport { ITelegramTransport, TransportFactory, TransportState } from './transports/index.js'\n\nexport interface PersistentConnectionParams {\n crypto: ICryptoProvider\n transportFactory: TransportFactory\n dc: tl.RawDcOption\n testMode: boolean\n reconnectionStrategy: ReconnectionStrategy<PersistentConnectionParams>\n inactivityTimeout?: number\n}\n\nlet nextConnectionUid = 0\n\n/**\n * Base class for persistent connections.\n * Only used for {@link PersistentConnection} and used as a mean of code splitting.\n * This class doesn't know anything about MTProto, it just manages the transport.\n */\nexport abstract class PersistentConnection extends EventEmitter {\n private _uid = nextConnectionUid++\n\n readonly params: PersistentConnectionParams\n protected _transport!: ITelegramTransport\n\n private _sendOnceConnected: Uint8Array[] = []\n\n // reconnection\n private _lastError: Error | null = null\n private _consequentFails = 0\n private _previousWait: number | null = null\n private _reconnectionTimeout: NodeJS.Timeout | null = null\n\n // inactivity timeout\n private _inactivityTimeout: NodeJS.Timeout | null = null\n private _inactive = true\n\n _destroyed = false\n _usable = false\n\n protected abstract onConnected(): void\n\n protected abstract onError(err: Error): void\n\n protected abstract onMessage(data: Uint8Array): void\n\n protected constructor(\n params: PersistentConnectionParams,\n readonly log: Logger,\n ) {\n super()\n this.params = params\n this.changeTransport(params.transportFactory)\n\n this.log.prefix = `[UID ${this._uid}] `\n\n this._onInactivityTimeout = this._onInactivityTimeout.bind(this)\n }\n\n get isConnected(): boolean {\n return this._transport.state() !== TransportState.Idle\n }\n\n changeTransport(factory: TransportFactory): void {\n if (this._transport) {\n this._transport.close()\n }\n\n this._transport = factory()\n this._transport.setup?.(this.params.crypto, this.log)\n\n this._transport.on('ready', this.onTransportReady.bind(this))\n this._transport.on('message', this.onMessage.bind(this))\n this._transport.on('error', this.onTransportError.bind(this))\n this._transport.on('close', this.onTransportClose.bind(this))\n }\n\n onTransportReady(): void {\n // transport ready does not mean actual mtproto is ready\n if (this._sendOnceConnected.length) {\n const sendNext = () => {\n if (!this._sendOnceConnected.length) {\n this.onConnected()\n\n return\n }\n\n const data = this._sendOnceConnected.shift()!\n this._transport\n .send(data)\n .then(sendNext)\n .catch((err) => {\n this.log.error('error sending queued data: %s', err)\n this._sendOnceConnected.unshift(data)\n })\n }\n\n sendNext()\n\n return\n }\n\n this.onConnected()\n }\n\n protected onConnectionUsable(): void {\n const isReconnection = this._consequentFails > 0\n\n // reset reconnection related state\n this._lastError = null\n this._consequentFails = 0\n this._previousWait = null\n this._usable = true\n this.emit('usable', isReconnection)\n this._rescheduleInactivity()\n }\n\n onTransportError(err: Error): void {\n this._lastError = err\n this.onError(err)\n // transport is expected to emit `close` after `error`\n }\n\n onTransportClose(): void {\n // transport closed because of inactivity\n // obviously we dont want to reconnect then\n if (this._inactive) return\n\n this._consequentFails += 1\n\n const wait = this.params.reconnectionStrategy(\n this.params,\n this._lastError,\n this._consequentFails,\n this._previousWait,\n )\n\n if (wait === false) {\n this.destroy()\n\n return\n }\n\n this.emit('wait', wait)\n\n this._previousWait = wait\n\n if (this._reconnectionTimeout != null) {\n clearTimeout(this._reconnectionTimeout)\n }\n this._reconnectionTimeout = setTimeout(() => {\n if (this._destroyed) return\n this._reconnectionTimeout = null\n this.connect()\n }, wait)\n }\n\n connect(): void {\n if (this.isConnected) {\n throw new MtcuteError('Connection is already opened!')\n }\n if (this._destroyed) {\n throw new MtcuteError('Connection is already destroyed!')\n }\n\n if (this._reconnectionTimeout != null) {\n clearTimeout(this._reconnectionTimeout)\n }\n\n this._inactive = false\n this._transport.connect(this.params.dc, this.params.testMode)\n }\n\n reconnect(): void {\n this._transport.close()\n }\n\n destroy(): void {\n if (this._reconnectionTimeout != null) {\n clearTimeout(this._reconnectionTimeout)\n }\n if (this._inactivityTimeout != null) {\n clearTimeout(this._inactivityTimeout)\n }\n\n this._transport.close()\n this._transport.removeAllListeners()\n this._destroyed = true\n }\n\n protected _rescheduleInactivity(): void {\n if (!this.params.inactivityTimeout) return\n if (this._inactivityTimeout) clearTimeout(this._inactivityTimeout)\n this._inactivityTimeout = setTimeout(this._onInactivityTimeout, this.params.inactivityTimeout)\n }\n\n protected _onInactivityTimeout(): void {\n this.log.info('disconnected because of inactivity for %d', this.params.inactivityTimeout)\n this._inactive = true\n this._inactivityTimeout = null\n this._transport.close()\n }\n\n setInactivityTimeout(timeout?: number): void {\n this.params.inactivityTimeout = timeout\n\n if (this._inactivityTimeout) {\n clearTimeout(this._inactivityTimeout)\n }\n\n if (timeout) {\n this._rescheduleInactivity()\n }\n }\n\n async send(data: Uint8Array): Promise<void> {\n if (this._inactive) {\n this.connect()\n }\n\n if (this._transport.state() === TransportState.Ready) {\n await this._transport.send(data)\n } else {\n this._sendOnceConnected.push(data)\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declares a strategy to handle reconnection.
|
|
3
|
+
* When a number is returned, that number of MS will be waited before trying to reconnect.
|
|
4
|
+
* When `false` is returned, connection is not reconnected
|
|
5
|
+
*/
|
|
6
|
+
export type ReconnectionStrategy<T> = (params: T, lastError: Error | null, consequentFails: number, previousWait: number | null) => number | false;
|
|
7
|
+
/**
|
|
8
|
+
* default reconnection strategy: first - immediate reconnection,
|
|
9
|
+
* then 1s with linear increase up to 5s (with 1s step)
|
|
10
|
+
*/
|
|
11
|
+
export declare const defaultReconnectionStrategy: ReconnectionStrategy<object>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* default reconnection strategy: first - immediate reconnection,
|
|
3
|
+
* then 1s with linear increase up to 5s (with 1s step)
|
|
4
|
+
*/
|
|
5
|
+
export const defaultReconnectionStrategy = (params, lastError, consequentFails, previousWait) => {
|
|
6
|
+
if (previousWait === null)
|
|
7
|
+
return 0;
|
|
8
|
+
if (previousWait === 0)
|
|
9
|
+
return 1000;
|
|
10
|
+
if (previousWait >= 5000)
|
|
11
|
+
return 5000;
|
|
12
|
+
return Math.min(5000, previousWait + 1000);
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=reconnection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconnection.js","sourceRoot":"","sources":["../../../src/network/reconnection.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAiC,CACrE,MAAM,EACN,SAAS,EACT,eAAe,EACf,YAAY,EACd,EAAE;IACA,IAAI,YAAY,KAAK,IAAI;QAAE,OAAO,CAAC,CAAA;IACnC,IAAI,YAAY,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACnC,IAAI,YAAY,IAAI,IAAI;QAAE,OAAO,IAAI,CAAA;IAErC,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAAC,CAAA;AAC9C,CAAC,CAAA","sourcesContent":["/**\n * Declares a strategy to handle reconnection.\n * When a number is returned, that number of MS will be waited before trying to reconnect.\n * When `false` is returned, connection is not reconnected\n */\nexport type ReconnectionStrategy<T> = (\n params: T,\n lastError: Error | null,\n consequentFails: number,\n previousWait: number | null,\n) => number | false\n\n/**\n * default reconnection strategy: first - immediate reconnection,\n * then 1s with linear increase up to 5s (with 1s step)\n */\nexport const defaultReconnectionStrategy: ReconnectionStrategy<object> = (\n params,\n lastError,\n consequentFails,\n previousWait,\n) => {\n if (previousWait === null) return 0\n if (previousWait === 0) return 1000\n if (previousWait >= 5000) return 5000\n\n return Math.min(5000, previousWait + 1000)\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { tl } from '@mtcute/tl';
|
|
2
|
+
import { TlReaderMap, TlWriterMap } from '@mtcute/tl-runtime';
|
|
3
|
+
import { MtprotoSession } from './mtproto-session.js';
|
|
4
|
+
import { PersistentConnection, PersistentConnectionParams } from './persistent-connection.js';
|
|
5
|
+
export interface SessionConnectionParams extends PersistentConnectionParams {
|
|
6
|
+
initConnection: tl.RawInitConnectionRequest;
|
|
7
|
+
inactivityTimeout?: number;
|
|
8
|
+
niceStacks?: boolean;
|
|
9
|
+
enableErrorReporting: boolean;
|
|
10
|
+
layer: number;
|
|
11
|
+
disableUpdates?: boolean;
|
|
12
|
+
withUpdates?: boolean;
|
|
13
|
+
isMainConnection: boolean;
|
|
14
|
+
isMainDcConnection: boolean;
|
|
15
|
+
usePfs?: boolean;
|
|
16
|
+
readerMap: TlReaderMap;
|
|
17
|
+
writerMap: TlWriterMap;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A connection to a single DC.
|
|
21
|
+
*/
|
|
22
|
+
export declare class SessionConnection extends PersistentConnection {
|
|
23
|
+
readonly _session: MtprotoSession;
|
|
24
|
+
readonly params: SessionConnectionParams;
|
|
25
|
+
private _flushTimer;
|
|
26
|
+
private _queuedDestroySession;
|
|
27
|
+
private _pendingWaitForUnencrypted;
|
|
28
|
+
private _usePfs;
|
|
29
|
+
private _isPfsBindingPending;
|
|
30
|
+
private _isPfsBindingPendingInBackground;
|
|
31
|
+
private _pfsUpdateTimeout?;
|
|
32
|
+
private _inactivityPendingFlush;
|
|
33
|
+
private _readerMap;
|
|
34
|
+
private _writerMap;
|
|
35
|
+
constructor(params: SessionConnectionParams, _session: MtprotoSession);
|
|
36
|
+
getAuthKey(temp?: boolean): Uint8Array | null;
|
|
37
|
+
setUsePfs(usePfs: boolean): void;
|
|
38
|
+
onTransportClose(): void;
|
|
39
|
+
destroy(): void;
|
|
40
|
+
reset(forever?: boolean): void;
|
|
41
|
+
onConnected(): void;
|
|
42
|
+
protected onError(error: Error): void;
|
|
43
|
+
protected onConnectionUsable(): void;
|
|
44
|
+
_authorize(): void;
|
|
45
|
+
private _authorizePfs;
|
|
46
|
+
waitForUnencryptedMessage(timeout?: number): Promise<Uint8Array>;
|
|
47
|
+
protected onMessage(data: Uint8Array): Promise<void>;
|
|
48
|
+
private _handleRawMessage;
|
|
49
|
+
private _handleMessage;
|
|
50
|
+
private _onRpcResult;
|
|
51
|
+
private _onMessageAcked;
|
|
52
|
+
private _onAllFailed;
|
|
53
|
+
private _onMessageFailed;
|
|
54
|
+
private _registerOutgoingMsgId;
|
|
55
|
+
private _onPong;
|
|
56
|
+
private _onBadServerSalt;
|
|
57
|
+
private _onBadMsgNotification;
|
|
58
|
+
private _onNewSessionCreated;
|
|
59
|
+
private _onMessageInfo;
|
|
60
|
+
private _onMessagesInfo;
|
|
61
|
+
private _onMsgsStateInfo;
|
|
62
|
+
private _onDestroySessionResult;
|
|
63
|
+
private _enqueueRpc;
|
|
64
|
+
_resetSession(): void;
|
|
65
|
+
private _sendAck;
|
|
66
|
+
sendRpc<T extends tl.RpcMethod>(request: T, stack?: string, timeout?: number, abortSignal?: AbortSignal): Promise<tl.RpcCallReturn[T['_']]>;
|
|
67
|
+
private _cancelRpc;
|
|
68
|
+
protected _onInactivityTimeout(): void;
|
|
69
|
+
flushWhenIdle(): void;
|
|
70
|
+
private _flush;
|
|
71
|
+
private _doFlush;
|
|
72
|
+
}
|