@mtkruto/browser 0.0.985 → 0.0.987
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 +30 -19
- package/esm/client/3_client.js +319 -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/tl/0_tl_raw_reader.d.ts +2 -0
- package/esm/tl/0_tl_raw_reader.js +3 -1
- package/esm/tl/3_tl_reader.js +2 -2
- 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 +30 -19
- package/script/client/3_client.js +318 -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/tl/0_tl_raw_reader.d.ts +2 -0
- package/script/tl/0_tl_raw_reader.js +5 -2
- package/script/tl/3_tl_reader.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>;
|
|
@@ -7,6 +7,12 @@ const d = (0, deps_js_1.debug)("ConnectionWebSocket");
|
|
|
7
7
|
class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
8
8
|
constructor(url) {
|
|
9
9
|
super();
|
|
10
|
+
Object.defineProperty(this, "url", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: url
|
|
15
|
+
});
|
|
10
16
|
Object.defineProperty(this, "webSocket", {
|
|
11
17
|
enumerable: true,
|
|
12
18
|
configurable: true,
|
|
@@ -37,6 +43,12 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
|
37
43
|
writable: true,
|
|
38
44
|
value: null
|
|
39
45
|
});
|
|
46
|
+
Object.defineProperty(this, "wasConnected", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: false
|
|
51
|
+
});
|
|
40
52
|
Object.defineProperty(this, "isConnecting", {
|
|
41
53
|
enumerable: true,
|
|
42
54
|
configurable: true,
|
|
@@ -49,16 +61,17 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
|
49
61
|
writable: true,
|
|
50
62
|
value: null
|
|
51
63
|
});
|
|
52
|
-
this.webSocket = this.
|
|
53
|
-
this.webSocket.addEventListener("close", (e) => {
|
|
54
|
-
if (e.code != 1000 && e.reason != "method") {
|
|
55
|
-
this.webSocket = this.reinitWs(url);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
64
|
+
this.webSocket = this.initWs();
|
|
58
65
|
}
|
|
59
|
-
|
|
60
|
-
const webSocket = new WebSocket(url, "binary");
|
|
66
|
+
initWs() {
|
|
67
|
+
const webSocket = new WebSocket(this.url, "binary");
|
|
61
68
|
const mutex = new deps_js_1.Mutex();
|
|
69
|
+
webSocket.addEventListener("close", () => {
|
|
70
|
+
this.stateChangeHandler?.(false);
|
|
71
|
+
});
|
|
72
|
+
webSocket.addEventListener("open", () => {
|
|
73
|
+
this.stateChangeHandler?.(true);
|
|
74
|
+
});
|
|
62
75
|
webSocket.addEventListener("message", async (e) => {
|
|
63
76
|
if (typeof e.data === "string") {
|
|
64
77
|
return;
|
|
@@ -79,7 +92,9 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
|
79
92
|
// @ts-ignore: Node.js
|
|
80
93
|
this.connectionError = err;
|
|
81
94
|
}
|
|
82
|
-
|
|
95
|
+
if (this.connected) {
|
|
96
|
+
d("WebSocket error: %o", err);
|
|
97
|
+
}
|
|
83
98
|
});
|
|
84
99
|
return webSocket;
|
|
85
100
|
}
|
|
@@ -91,6 +106,9 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
|
91
106
|
throw new Error("Already connecting");
|
|
92
107
|
}
|
|
93
108
|
this.isConnecting = true;
|
|
109
|
+
if (!this.connected && this.wasConnected) {
|
|
110
|
+
this.webSocket = this.initWs();
|
|
111
|
+
}
|
|
94
112
|
try {
|
|
95
113
|
while (this.webSocket.readyState != WebSocket.OPEN) {
|
|
96
114
|
if (this.webSocket.readyState == WebSocket.CLOSED) {
|
|
@@ -105,6 +123,7 @@ class ConnectionWebSocket extends _0_connection_js_1.ConnectionUnframed {
|
|
|
105
123
|
await new Promise((r) => setTimeout(r, 5));
|
|
106
124
|
}
|
|
107
125
|
}
|
|
126
|
+
this.wasConnected = true;
|
|
108
127
|
}
|
|
109
128
|
finally {
|
|
110
129
|
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.987";
|
|
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
|
@@ -56,7 +56,7 @@ exports.PUBLIC_KEYS = Object.freeze([
|
|
|
56
56
|
exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
57
57
|
exports.INITIAL_DC = "2-test";
|
|
58
58
|
exports.LAYER = 161;
|
|
59
|
-
exports.APP_VERSION = "MTKruto 0.0.
|
|
59
|
+
exports.APP_VERSION = "MTKruto 0.0.987";
|
|
60
60
|
// @ts-ignore: lib
|
|
61
61
|
exports.DEVICE_MODEL = typeof Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : Deno.build.os + "-" + Deno.build.arch;
|
|
62
62
|
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; } });
|
|
@@ -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
|
|
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);
|
package/script/tl/3_tl_reader.js
CHANGED
|
@@ -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
|
|
25
|
+
throw new _0_tl_raw_reader_js_1.TLError(`Unknown constructor ${id.toString(16)}`);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
exports.TLReader = TLReader;
|
|
@@ -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;
|