@mtkruto/node 0.0.985 → 0.0.986

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.
@@ -26,6 +26,7 @@ import { ClientPlain } from "./2_client_plain.js";
26
26
  import { drop, mustPrompt, mustPromptOneOf } from "../utilities/1_misc.js";
27
27
  import { getChannelChatId, peerToChatId } from "./0_utilities.js";
28
28
  import { constructUser } from "../types/1_user.js";
29
+ import { TLError } from "../tl/0_tl_raw_reader.js";
29
30
  const d = debug("Client");
30
31
  const dGap = debug("Client/recoverUpdateGap");
31
32
  const dGapC = debug("Client/recoverChannelUpdateGap");
@@ -596,6 +597,10 @@ export class Client extends ClientAbstract {
596
597
  if (!this.connected) {
597
598
  break;
598
599
  }
600
+ else if (err instanceof TLError) {
601
+ dRecv("failed to deserialize: %o", err);
602
+ drop(this.recoverUpdateGap("deserialize"));
603
+ }
599
604
  else {
600
605
  throw err;
601
606
  }
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 161;
8
- export declare const APP_VERSION = "MTKruto 0.0.985";
8
+ export declare const APP_VERSION = "MTKruto 0.0.986";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
package/esm/constants.js CHANGED
@@ -54,7 +54,7 @@ export const PUBLIC_KEYS = Object.freeze([
54
54
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
55
55
  export const INITIAL_DC = "2-test";
56
56
  export const LAYER = 161;
57
- export const APP_VERSION = "MTKruto 0.0.985";
57
+ export const APP_VERSION = "MTKruto 0.0.986";
58
58
  // @ts-ignore: lib
59
59
  export const DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
60
60
  export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -1,3 +1,5 @@
1
+ export declare class TLError extends Error {
2
+ }
1
3
  export declare class TLRawReader {
2
4
  protected _buffer: Uint8Array;
3
5
  constructor(_buffer: Uint8Array);
@@ -1,4 +1,6 @@
1
1
  import { bigIntFromBuffer } from "../utilities/0_bigint.js";
2
+ export class TLError extends Error {
3
+ }
2
4
  export class TLRawReader {
3
5
  constructor(_buffer) {
4
6
  Object.defineProperty(this, "_buffer", {
@@ -13,7 +15,7 @@ export class TLRawReader {
13
15
  }
14
16
  read(count) {
15
17
  if (this._buffer.length < count) {
16
- throw new Error("No data remaining");
18
+ throw new TLError("No data remaining");
17
19
  }
18
20
  const buffer = this._buffer.slice(0, count);
19
21
  this._buffer = this._buffer.slice(count);
@@ -1,4 +1,4 @@
1
- import { TLRawReader } from "./0_tl_raw_reader.js";
1
+ import { TLError, TLRawReader } from "./0_tl_raw_reader.js";
2
2
  import { paramDesc } from "./1_tl_object.js";
3
3
  import { map } from "./2_types.js";
4
4
  import { deserialize } from "./3_deserialize.js";
@@ -19,6 +19,6 @@ export class TLReader extends TLRawReader {
19
19
  if (constructor) {
20
20
  return deserialize(this, constructor[paramDesc], constructor);
21
21
  }
22
- throw new Error(`Unknown constructor ${id.toString(16)}`);
22
+ throw new TLError(`Unknown constructor ${id.toString(16)}`);
23
23
  }
24
24
  }
@@ -18,7 +18,7 @@ export const webSocketTransportProvider = ({ initialDc, wss }) => {
18
18
  initialDc,
19
19
  createTransport: ({ dc, cdn }) => {
20
20
  dc ??= initialDc;
21
- wss ??= typeof location !== "undefined" && location.protocol == "http:" ? false : true;
21
+ wss ??= typeof location !== "undefined" && location.protocol == "http:" && location.hostname != "localhost" ? false : true;
22
22
  const url = `${wss ? "wss" : "ws"}://${dcToNameMap[dc]}${cdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
23
23
  const connection = new ConnectionWebSocket(url);
24
24
  const transport = new TransportIntermediate(connection, true);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.985",
5
+ "version": "0.0.986",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -52,6 +52,7 @@ const _2_client_plain_js_1 = require("./2_client_plain.js");
52
52
  const _1_misc_js_1 = require("../utilities/1_misc.js");
53
53
  const _0_utilities_js_1 = require("./0_utilities.js");
54
54
  const _1_user_js_1 = require("../types/1_user.js");
55
+ const _0_tl_raw_reader_js_1 = require("../tl/0_tl_raw_reader.js");
55
56
  const d = (0, deps_js_1.debug)("Client");
56
57
  const dGap = (0, deps_js_1.debug)("Client/recoverUpdateGap");
57
58
  const dGapC = (0, deps_js_1.debug)("Client/recoverChannelUpdateGap");
@@ -622,6 +623,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
622
623
  if (!this.connected) {
623
624
  break;
624
625
  }
626
+ else if (err instanceof _0_tl_raw_reader_js_1.TLError) {
627
+ dRecv("failed to deserialize: %o", err);
628
+ (0, _1_misc_js_1.drop)(this.recoverUpdateGap("deserialize"));
629
+ }
625
630
  else {
626
631
  throw err;
627
632
  }
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 161;
8
- export declare const APP_VERSION = "MTKruto 0.0.985";
8
+ export declare const APP_VERSION = "MTKruto 0.0.986";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
@@ -80,7 +80,7 @@ exports.PUBLIC_KEYS = Object.freeze([
80
80
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
81
81
  exports.INITIAL_DC = "2-test";
82
82
  exports.LAYER = 161;
83
- exports.APP_VERSION = "MTKruto 0.0.985";
83
+ exports.APP_VERSION = "MTKruto 0.0.986";
84
84
  // @ts-ignore: lib
85
85
  exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
86
86
  exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -1,3 +1,5 @@
1
+ export declare class TLError extends Error {
2
+ }
1
3
  export declare class TLRawReader {
2
4
  protected _buffer: Uint8Array;
3
5
  constructor(_buffer: Uint8Array);
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TLRawReader = void 0;
3
+ exports.TLRawReader = exports.TLError = void 0;
4
4
  const _0_bigint_js_1 = require("../utilities/0_bigint.js");
5
+ class TLError extends Error {
6
+ }
7
+ exports.TLError = TLError;
5
8
  class TLRawReader {
6
9
  constructor(_buffer) {
7
10
  Object.defineProperty(this, "_buffer", {
@@ -16,7 +19,7 @@ class TLRawReader {
16
19
  }
17
20
  read(count) {
18
21
  if (this._buffer.length < count) {
19
- throw new Error("No data remaining");
22
+ throw new TLError("No data remaining");
20
23
  }
21
24
  const buffer = this._buffer.slice(0, count);
22
25
  this._buffer = this._buffer.slice(count);
@@ -22,7 +22,7 @@ class TLReader extends _0_tl_raw_reader_js_1.TLRawReader {
22
22
  if (constructor) {
23
23
  return (0, _3_deserialize_js_1.deserialize)(this, constructor[_1_tl_object_js_1.paramDesc], constructor);
24
24
  }
25
- throw new Error(`Unknown constructor ${id.toString(16)}`);
25
+ throw new _0_tl_raw_reader_js_1.TLError(`Unknown constructor ${id.toString(16)}`);
26
26
  }
27
27
  }
28
28
  exports.TLReader = TLReader;
@@ -21,7 +21,7 @@ const webSocketTransportProvider = ({ initialDc, wss }) => {
21
21
  initialDc,
22
22
  createTransport: ({ dc, cdn }) => {
23
23
  dc ??= initialDc;
24
- wss ??= typeof location !== "undefined" && location.protocol == "http:" ? false : true;
24
+ wss ??= typeof location !== "undefined" && location.protocol == "http:" && location.hostname != "localhost" ? false : true;
25
25
  const url = `${wss ? "wss" : "ws"}://${dcToNameMap[dc]}${cdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
26
26
  const connection = new _1_connection_web_socket_js_1.ConnectionWebSocket(url);
27
27
  const transport = new _1_transport_intermediate_js_1.TransportIntermediate(connection, true);