@mtkruto/node 0.0.986 → 0.0.988
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/client/0_utilities.d.ts +2 -0
- package/esm/client/0_utilities.js +22 -0
- package/esm/client/1_client_abstract.d.ts +15 -10
- package/esm/client/1_client_abstract.js +26 -27
- package/esm/client/2_client_plain.d.ts +9 -3
- package/esm/client/2_client_plain.js +9 -5
- package/esm/client/3_client.d.ts +28 -19
- package/esm/client/3_client.js +314 -291
- package/esm/connection/0_connection.d.ts +1 -0
- package/esm/connection/0_connection.js +8 -0
- package/esm/connection/1_connection_web_socket.d.ts +3 -1
- package/esm/connection/1_connection_web_socket.js +28 -9
- package/esm/constants.d.ts +1 -1
- package/esm/constants.js +1 -1
- package/esm/deps.js +1 -1
- package/esm/transport/2_transport_provider.d.ts +7 -14
- package/esm/transport/2_transport_provider.js +9 -12
- package/esm/utilities/0_queue.d.ts +6 -0
- package/esm/utilities/0_queue.js +38 -0
- package/package.json +1 -1
- package/script/client/0_utilities.d.ts +2 -0
- package/script/client/0_utilities.js +25 -1
- package/script/client/1_client_abstract.d.ts +15 -10
- package/script/client/1_client_abstract.js +26 -27
- package/script/client/2_client_plain.d.ts +9 -3
- package/script/client/2_client_plain.js +9 -5
- package/script/client/3_client.d.ts +28 -19
- package/script/client/3_client.js +313 -290
- package/script/connection/0_connection.d.ts +1 -0
- package/script/connection/0_connection.js +8 -0
- package/script/connection/1_connection_web_socket.d.ts +3 -1
- package/script/connection/1_connection_web_socket.js +28 -9
- package/script/constants.d.ts +1 -1
- package/script/constants.js +1 -1
- package/script/deps.js +1 -1
- package/script/transport/2_transport_provider.d.ts +7 -14
- package/script/transport/2_transport_provider.js +9 -12
- package/script/utilities/0_queue.d.ts +6 -0
- package/script/utilities/0_queue.js +42 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
2
|
declare abstract class Foundation {
|
|
3
3
|
abstract get connected(): boolean;
|
|
4
|
+
stateChangeHandler?: (connected: boolean) => void;
|
|
4
5
|
abstract open(): MaybePromise<void>;
|
|
5
6
|
abstract write(p: Uint8Array): MaybePromise<void>;
|
|
6
7
|
abstract close(): MaybePromise<void>;
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConnectionFramed = exports.ConnectionUnframed = void 0;
|
|
4
4
|
class Foundation {
|
|
5
|
+
constructor() {
|
|
6
|
+
Object.defineProperty(this, "stateChangeHandler", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: void 0
|
|
11
|
+
});
|
|
12
|
+
}
|
|
5
13
|
}
|
|
6
14
|
class ConnectionUnframed extends Foundation {
|
|
7
15
|
constructor() {
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { ConnectionUnframed } from "./0_connection.js";
|
|
2
2
|
export declare class ConnectionWebSocket extends ConnectionUnframed implements ConnectionUnframed {
|
|
3
|
+
private readonly url;
|
|
3
4
|
private webSocket;
|
|
4
5
|
private rMutex;
|
|
5
6
|
private wMutex;
|
|
6
7
|
private buffer;
|
|
7
8
|
private nextResolve;
|
|
8
9
|
constructor(url: string | URL);
|
|
9
|
-
private
|
|
10
|
+
private initWs;
|
|
10
11
|
get connected(): boolean;
|
|
12
|
+
private wasConnected;
|
|
11
13
|
private isConnecting;
|
|
12
14
|
private connectionError;
|
|
13
15
|
open(): Promise<void>;
|
|
@@ -31,6 +31,12 @@ const d = (0, deps_js_1.debug)("ConnectionWebSocket");
|
|
|
31
31
|
class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
32
32
|
constructor(url) {
|
|
33
33
|
super();
|
|
34
|
+
Object.defineProperty(this, "url", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: url
|
|
39
|
+
});
|
|
34
40
|
Object.defineProperty(this, "webSocket", {
|
|
35
41
|
enumerable: true,
|
|
36
42
|
configurable: true,
|
|
@@ -61,6 +67,12 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
|
61
67
|
writable: true,
|
|
62
68
|
value: null
|
|
63
69
|
});
|
|
70
|
+
Object.defineProperty(this, "wasConnected", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
value: false
|
|
75
|
+
});
|
|
64
76
|
Object.defineProperty(this, "isConnecting", {
|
|
65
77
|
enumerable: true,
|
|
66
78
|
configurable: true,
|
|
@@ -73,16 +85,17 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
|
73
85
|
writable: true,
|
|
74
86
|
value: null
|
|
75
87
|
});
|
|
76
|
-
this.webSocket = this.
|
|
77
|
-
this.webSocket.addEventListener("close", (e) => {
|
|
78
|
-
if (e.code != 1000 && e.reason != "method") {
|
|
79
|
-
this.webSocket = this.reinitWs(url);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
88
|
+
this.webSocket = this.initWs();
|
|
82
89
|
}
|
|
83
|
-
|
|
84
|
-
const webSocket = new dntShim.WebSocket(url, "binary");
|
|
90
|
+
initWs() {
|
|
91
|
+
const webSocket = new dntShim.WebSocket(this.url, "binary");
|
|
85
92
|
const mutex = new deps_js_1.Mutex();
|
|
93
|
+
webSocket.addEventListener("close", () => {
|
|
94
|
+
this.stateChangeHandler?.(false);
|
|
95
|
+
});
|
|
96
|
+
webSocket.addEventListener("open", () => {
|
|
97
|
+
this.stateChangeHandler?.(true);
|
|
98
|
+
});
|
|
86
99
|
webSocket.addEventListener("message", async (e) => {
|
|
87
100
|
if (typeof e.data === "string") {
|
|
88
101
|
return;
|
|
@@ -103,7 +116,9 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
|
103
116
|
// @ts-ignore: Node.js
|
|
104
117
|
this.connectionError = err;
|
|
105
118
|
}
|
|
106
|
-
|
|
119
|
+
if (this.connected) {
|
|
120
|
+
d("WebSocket error: %o", err);
|
|
121
|
+
}
|
|
107
122
|
});
|
|
108
123
|
return webSocket;
|
|
109
124
|
}
|
|
@@ -115,6 +130,9 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
|
115
130
|
throw new Error("Already connecting");
|
|
116
131
|
}
|
|
117
132
|
this.isConnecting = true;
|
|
133
|
+
if (!this.connected && this.wasConnected) {
|
|
134
|
+
this.webSocket = this.initWs();
|
|
135
|
+
}
|
|
118
136
|
try {
|
|
119
137
|
while (this.webSocket.readyState != dntShim.WebSocket.OPEN) {
|
|
120
138
|
if (this.webSocket.readyState == dntShim.WebSocket.CLOSED) {
|
|
@@ -129,6 +147,7 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
|
129
147
|
await new Promise((r) => setTimeout(r, 5));
|
|
130
148
|
}
|
|
131
149
|
}
|
|
150
|
+
this.wasConnected = true;
|
|
132
151
|
}
|
|
133
152
|
finally {
|
|
134
153
|
this.isConnecting = false;
|
package/script/constants.d.ts
CHANGED
|
@@ -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.
|
|
8
|
+
export declare const APP_VERSION = "MTKruto 0.0.988";
|
|
9
9
|
export declare const DEVICE_MODEL: string;
|
|
10
10
|
export declare const LANG_CODE: string;
|
|
11
11
|
export declare const LANG_PACK = "";
|
package/script/constants.js
CHANGED
|
@@ -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.
|
|
83
|
+
exports.APP_VERSION = "MTKruto 0.0.988";
|
|
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];
|
package/script/deps.js
CHANGED
|
@@ -31,7 +31,7 @@ Object.defineProperty(exports, "Mutex", { enumerable: true, get: function () { r
|
|
|
31
31
|
var mod_js_2 = require("./deps/deno.land/x/html_parser@v0.1.3/src/mod.js");
|
|
32
32
|
Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return mod_js_2.Parser; } });
|
|
33
33
|
const mod_js_3 = require("./deps/raw.githubusercontent.com/MTKruto/debug/main/mod.js");
|
|
34
|
-
const debug = (v) => (0, mod_js_3.debug)(
|
|
34
|
+
const debug = (v) => (0, mod_js_3.debug)(v);
|
|
35
35
|
exports.debug = debug;
|
|
36
36
|
var base64_js_1 = require("./deps/deno.land/std@0.200.0/encoding/base64.js");
|
|
37
37
|
Object.defineProperty(exports, "base64Decode", { enumerable: true, get: function () { return base64_js_1.decode; } });
|
|
@@ -2,21 +2,14 @@ import { Connection } from "../connection/0_connection.js";
|
|
|
2
2
|
import { Transport } from "./0_transport.js";
|
|
3
3
|
export type DC = "1" | "2" | "3" | "4" | "5" | "1-test" | "2-test" | "3-test";
|
|
4
4
|
export interface TransportProviderParams {
|
|
5
|
-
dc
|
|
5
|
+
dc: DC;
|
|
6
6
|
cdn: boolean;
|
|
7
7
|
}
|
|
8
|
-
export type TransportProvider = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
transport: Transport;
|
|
13
|
-
dcId: number;
|
|
14
|
-
};
|
|
8
|
+
export type TransportProvider = (params: TransportProviderParams) => {
|
|
9
|
+
connection: Connection;
|
|
10
|
+
transport: Transport;
|
|
11
|
+
dcId: number;
|
|
15
12
|
};
|
|
16
|
-
export
|
|
17
|
-
initialDc: DC;
|
|
18
|
-
}
|
|
19
|
-
export type TransportProviderCreator<E = Record<never, never>> = (params: TransportProviderCreatorParams & E) => TransportProvider;
|
|
20
|
-
export declare const webSocketTransportProvider: TransportProviderCreator<{
|
|
13
|
+
export declare const webSocketTransportProvider: (params?: {
|
|
21
14
|
wss?: boolean;
|
|
22
|
-
}
|
|
15
|
+
}) => TransportProvider;
|
|
@@ -16,18 +16,15 @@ const dcToNameMap = {
|
|
|
16
16
|
function getDcId(dc, cdn) {
|
|
17
17
|
return Number(dc[0]) + (dc.endsWith("-test") ? 10000 : 0) * (cdn ? -1 : 1);
|
|
18
18
|
}
|
|
19
|
-
const webSocketTransportProvider = (
|
|
20
|
-
return {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const dcId = getDcId(dc, cdn);
|
|
29
|
-
return { connection, transport, dcId };
|
|
30
|
-
},
|
|
19
|
+
const webSocketTransportProvider = (params) => {
|
|
20
|
+
return ({ dc, cdn }) => {
|
|
21
|
+
params ??= {};
|
|
22
|
+
params.wss ??= typeof location !== "undefined" && location.protocol == "http:" && location.hostname != "localhost" ? false : true;
|
|
23
|
+
const url = `${params.wss ? "wss" : "ws"}://${dcToNameMap[dc]}${cdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
|
|
24
|
+
const connection = new _1_connection_web_socket_js_1.ConnectionWebSocket(url);
|
|
25
|
+
const transport = new _1_transport_intermediate_js_1.TransportIntermediate(connection, true);
|
|
26
|
+
const dcId = getDcId(dc, cdn);
|
|
27
|
+
return { connection, transport, dcId };
|
|
31
28
|
};
|
|
32
29
|
};
|
|
33
30
|
exports.webSocketTransportProvider = webSocketTransportProvider;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Queue = void 0;
|
|
4
|
+
class Queue {
|
|
5
|
+
constructor() {
|
|
6
|
+
Object.defineProperty(this, "functions", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: new Array()
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(this, "busy", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: false
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
add(fn) {
|
|
20
|
+
this.functions.push(fn);
|
|
21
|
+
this.check();
|
|
22
|
+
}
|
|
23
|
+
check() {
|
|
24
|
+
if (this.busy) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.busy = true;
|
|
29
|
+
}
|
|
30
|
+
const fn = this.functions.shift();
|
|
31
|
+
if (fn !== undefined) {
|
|
32
|
+
fn().finally(() => {
|
|
33
|
+
this.busy = false;
|
|
34
|
+
this.check();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.busy = false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Queue = Queue;
|