@mtkruto/node 0.0.962 → 0.0.964

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.
@@ -6,6 +6,7 @@ export declare class ConnectionWebSocket implements Connection {
6
6
  private buffer;
7
7
  private nextResolve;
8
8
  constructor(url: string | URL);
9
+ private reinitWs;
9
10
  get connected(): boolean;
10
11
  open(): Promise<void>;
11
12
  read(p: Uint8Array): Promise<void>;
@@ -33,8 +33,15 @@ export class ConnectionWebSocket {
33
33
  writable: true,
34
34
  value: null
35
35
  });
36
- this.webSocket = new dntShim.WebSocket(url, "binary");
37
- this.webSocket.onmessage = async (e) => {
36
+ this.webSocket = this.reinitWs(url);
37
+ // TODO
38
+ this.webSocket.onclose = () => {
39
+ this.webSocket = this.reinitWs(url);
40
+ };
41
+ }
42
+ reinitWs(url) {
43
+ const webSocket = new dntShim.WebSocket(url, "binary");
44
+ webSocket.onmessage = async (e) => {
38
45
  // deno-lint-ignore no-explicit-any
39
46
  const data = e.data instanceof Blob ? new Uint8Array(await e.data.arrayBuffer()) : new Uint8Array(e.data);
40
47
  for (const byte of data) {
@@ -45,9 +52,10 @@ export class ConnectionWebSocket {
45
52
  this.nextResolve = null;
46
53
  }
47
54
  };
48
- this.webSocket.onerror = (err) => {
55
+ webSocket.onerror = (err) => {
49
56
  d("WebSocket error: %o", err);
50
57
  };
58
+ return webSocket;
51
59
  }
52
60
  get connected() {
53
61
  return this.webSocket.readyState == dntShim.WebSocket.OPEN;
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.962";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.964";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
package/esm/constants.js CHANGED
@@ -62,7 +62,7 @@ export const publicKeys = new Map([
62
62
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
63
63
  export const DEFAULT_INITIAL_DC = "2-test";
64
64
  export const LAYER = 158;
65
- export const DEFAULT_APP_VERSION = "MTKruto 0.0.962";
65
+ export const DEFAULT_APP_VERSION = "MTKruto 0.0.964";
66
66
  // @ts-ignore: lib
67
67
  export const DEFAULT_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;
68
68
  export const DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -91,8 +91,11 @@ function serializeSingleParam(writer, value, type, ntype) {
91
91
  writer.writeBytes(value);
92
92
  }
93
93
  else {
94
- throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
94
+ writer.writeString("");
95
95
  }
96
+ // else {
97
+ // throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
98
+ // }
96
99
  break;
97
100
  case "true":
98
101
  if (value !== true) {
@@ -380,6 +380,9 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
380
380
  else if (message_.media instanceof types.MessageMediaGeo || message_.media instanceof types.MessageMediaGeoLive) {
381
381
  message.location = constructLocation(message_.media);
382
382
  }
383
+ else if (message_.media instanceof types.MessageMediaWebPage) {
384
+ //
385
+ }
383
386
  else {
384
387
  // not implemented
385
388
  UNREACHABLE();
@@ -1,9 +1,11 @@
1
1
  import { base64Decode, base64Encode } from "../deps.js";
2
- // TODO: test
3
2
  export function base64EncodeUrlSafe(data) {
4
3
  return base64Encode(data).replace(/=*$/, "").replaceAll("+", "-").replaceAll("/", "_");
5
4
  }
6
5
  export function base64DecodeUrlSafe(data) {
7
6
  data = data.replaceAll("_", "/").replaceAll("-", "+");
8
- return base64Decode(data + "=".repeat(data.length % 4));
7
+ if (data.length != 4) {
8
+ data += "=".repeat(4 - data.length % 4);
9
+ }
10
+ return base64Decode(data);
9
11
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,9 @@
1
1
  export function concat(...buffers) {
2
2
  const bytes = new Array();
3
3
  for (const buffer of buffers) {
4
- bytes.push(...buffer);
4
+ for (const byte of buffer) {
5
+ bytes.push(byte);
6
+ }
5
7
  }
6
8
  const buffer = new Uint8Array(bytes);
7
9
  return buffer;
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.962",
5
+ "version": "0.0.964",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -6,6 +6,7 @@ export declare class ConnectionWebSocket implements Connection {
6
6
  private buffer;
7
7
  private nextResolve;
8
8
  constructor(url: string | URL);
9
+ private reinitWs;
9
10
  get connected(): boolean;
10
11
  open(): Promise<void>;
11
12
  read(p: Uint8Array): Promise<void>;
@@ -59,8 +59,15 @@ class ConnectionWebSocket {
59
59
  writable: true,
60
60
  value: null
61
61
  });
62
- this.webSocket = new dntShim.WebSocket(url, "binary");
63
- this.webSocket.onmessage = async (e) => {
62
+ this.webSocket = this.reinitWs(url);
63
+ // TODO
64
+ this.webSocket.onclose = () => {
65
+ this.webSocket = this.reinitWs(url);
66
+ };
67
+ }
68
+ reinitWs(url) {
69
+ const webSocket = new dntShim.WebSocket(url, "binary");
70
+ webSocket.onmessage = async (e) => {
64
71
  // deno-lint-ignore no-explicit-any
65
72
  const data = e.data instanceof Blob ? new Uint8Array(await e.data.arrayBuffer()) : new Uint8Array(e.data);
66
73
  for (const byte of data) {
@@ -71,9 +78,10 @@ class ConnectionWebSocket {
71
78
  this.nextResolve = null;
72
79
  }
73
80
  };
74
- this.webSocket.onerror = (err) => {
81
+ webSocket.onerror = (err) => {
75
82
  d("WebSocket error: %o", err);
76
83
  };
84
+ return webSocket;
77
85
  }
78
86
  get connected() {
79
87
  return this.webSocket.readyState == dntShim.WebSocket.OPEN;
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.962";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.964";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
@@ -88,7 +88,7 @@ exports.publicKeys = new Map([
88
88
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
89
89
  exports.DEFAULT_INITIAL_DC = "2-test";
90
90
  exports.LAYER = 158;
91
- exports.DEFAULT_APP_VERSION = "MTKruto 0.0.962";
91
+ exports.DEFAULT_APP_VERSION = "MTKruto 0.0.964";
92
92
  // @ts-ignore: lib
93
93
  exports.DEFAULT_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;
94
94
  exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -96,8 +96,11 @@ function serializeSingleParam(writer, value, type, ntype) {
96
96
  writer.writeBytes(value);
97
97
  }
98
98
  else {
99
- throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
99
+ writer.writeString("");
100
100
  }
101
+ // else {
102
+ // throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
103
+ // }
101
104
  break;
102
105
  case "true":
103
106
  if (value !== true) {
@@ -406,6 +406,9 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
406
406
  else if (message_.media instanceof types.MessageMediaGeo || message_.media instanceof types.MessageMediaGeoLive) {
407
407
  message.location = (0, _0_location_js_1.constructLocation)(message_.media);
408
408
  }
409
+ else if (message_.media instanceof types.MessageMediaWebPage) {
410
+ //
411
+ }
409
412
  else {
410
413
  // not implemented
411
414
  (0, _0_control_js_1.UNREACHABLE)();
@@ -2,13 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.base64DecodeUrlSafe = exports.base64EncodeUrlSafe = void 0;
4
4
  const deps_js_1 = require("../deps.js");
5
- // TODO: test
6
5
  function base64EncodeUrlSafe(data) {
7
6
  return (0, deps_js_1.base64Encode)(data).replace(/=*$/, "").replaceAll("+", "-").replaceAll("/", "_");
8
7
  }
9
8
  exports.base64EncodeUrlSafe = base64EncodeUrlSafe;
10
9
  function base64DecodeUrlSafe(data) {
11
10
  data = data.replaceAll("_", "/").replaceAll("-", "+");
12
- return (0, deps_js_1.base64Decode)(data + "=".repeat(data.length % 4));
11
+ if (data.length != 4) {
12
+ data += "=".repeat(4 - data.length % 4);
13
+ }
14
+ return (0, deps_js_1.base64Decode)(data);
13
15
  }
14
16
  exports.base64DecodeUrlSafe = base64DecodeUrlSafe;
@@ -0,0 +1 @@
1
+ export {};
@@ -4,7 +4,9 @@ exports.bufferFromBigInt = exports.concat = void 0;
4
4
  function concat(...buffers) {
5
5
  const bytes = new Array();
6
6
  for (const buffer of buffers) {
7
- bytes.push(...buffer);
7
+ for (const byte of buffer) {
8
+ bytes.push(byte);
9
+ }
8
10
  }
9
11
  const buffer = new Uint8Array(bytes);
10
12
  return buffer;