@mtkruto/browser 0.119.0 → 0.119.1
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/0_errors.d.ts.map +1 -1
- package/esm/0_errors.js +9 -31
- package/esm/3_errors.js +2 -12
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +0 -99
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +1 -127
- package/esm/client/0_abortable_loop.js +26 -39
- package/esm/client/0_storage_operations.js +179 -218
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/2_account_manager.js +140 -149
- package/esm/client/2_bot_info_manager.js +26 -38
- package/esm/client/2_business_connection_manager.js +10 -23
- package/esm/client/2_client_encrypted.js +198 -215
- package/esm/client/2_file_manager.js +255 -262
- package/esm/client/2_network_statistics_manager.js +31 -44
- package/esm/client/2_payment_manager.js +7 -20
- package/esm/client/2_reaction_manager.js +7 -20
- package/esm/client/2_translations_manager.js +101 -111
- package/esm/client/2_update_manager.js +750 -745
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_message_manager.js +503 -508
- package/esm/client/3_video_chat_manager.js +57 -68
- package/esm/client/4_callback_query_manager.js +18 -30
- package/esm/client/4_chat_list_manager.js +140 -146
- package/esm/client/4_chat_manager.js +161 -169
- package/esm/client/4_checklist_manager.js +26 -39
- package/esm/client/4_context.js +244 -259
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +22 -35
- package/esm/client/4_inline_query_manager.js +16 -28
- package/esm/client/4_link_preview_manager.js +6 -19
- package/esm/client/4_poll_manager.js +44 -57
- package/esm/client/4_story_manager.js +41 -53
- package/esm/client/5_composer.js +13 -26
- package/esm/client/6_client.js +866 -896
- package/esm/client/6_client_dispatcher.js +308 -325
- package/esm/client/7_client_worker.js +16 -29
- package/esm/connection/1_connection_tcp.js +55 -82
- package/esm/connection/1_connection_web_socket.js +75 -91
- package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/esm/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +422 -420
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.js +3 -16
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/1_tl_reader.d.ts +1 -1
- package/esm/tl/1_tl_reader.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +95 -103
- package/esm/tl/1_tl_writer.js +169 -178
- package/esm/transport/0_transport.js +1 -8
- package/esm/transport/1_transport_abridged.js +11 -24
- package/esm/transport/1_transport_intermediate.js +10 -23
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.d.ts.map +1 -1
- package/script/0_errors.js +9 -31
- package/script/3_errors.js +2 -12
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +0 -99
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +0 -128
- package/script/client/0_abortable_loop.js +27 -40
- package/script/client/0_storage_operations.js +179 -218
- package/script/client/1_client_plain.js +4 -22
- package/script/client/2_account_manager.js +140 -149
- package/script/client/2_bot_info_manager.js +26 -38
- package/script/client/2_business_connection_manager.js +10 -23
- package/script/client/2_client_encrypted.js +199 -216
- package/script/client/2_file_manager.js +255 -262
- package/script/client/2_network_statistics_manager.js +32 -45
- package/script/client/2_payment_manager.js +7 -20
- package/script/client/2_reaction_manager.js +7 -20
- package/script/client/2_translations_manager.js +102 -112
- package/script/client/2_update_manager.js +750 -745
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_message_manager.js +503 -508
- package/script/client/3_video_chat_manager.js +57 -68
- package/script/client/4_callback_query_manager.js +18 -30
- package/script/client/4_chat_list_manager.js +140 -146
- package/script/client/4_chat_manager.js +161 -169
- package/script/client/4_checklist_manager.js +26 -39
- package/script/client/4_context.js +244 -259
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +22 -35
- package/script/client/4_inline_query_manager.js +16 -28
- package/script/client/4_link_preview_manager.js +6 -19
- package/script/client/4_poll_manager.js +44 -57
- package/script/client/4_story_manager.js +41 -53
- package/script/client/5_composer.js +13 -26
- package/script/client/6_client.js +866 -896
- package/script/client/6_client_dispatcher.js +308 -325
- package/script/client/7_client_worker.js +16 -29
- package/script/connection/1_connection_tcp.js +55 -82
- package/script/connection/1_connection_web_socket.js +75 -91
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +49 -72
- package/script/session/2_session_encrypted.js +423 -421
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.js +3 -16
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/1_tl_reader.d.ts +1 -1
- package/script/tl/1_tl_reader.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +96 -104
- package/script/tl/1_tl_writer.js +170 -179
- package/script/transport/0_transport.js +1 -8
- package/script/transport/1_transport_abridged.js +11 -24
- package/script/transport/1_transport_intermediate.js +10 -23
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/1_crypto.js +43 -54
- package/script/utilities/2_queue.js +30 -48
|
@@ -18,38 +18,26 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _ClientWorker_worker, _ClientWorker_clients, _ClientWorker_L;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.ClientWorker = void 0;
|
|
35
23
|
const _0_errors_js_1 = require("../0_errors.js");
|
|
36
24
|
const _1_logger_js_1 = require("../utilities/1_logger.js");
|
|
37
25
|
const _6_client_dispatcher_js_1 = require("./6_client_dispatcher.js");
|
|
38
26
|
class ClientWorker {
|
|
27
|
+
#worker;
|
|
28
|
+
#clients = new Map();
|
|
29
|
+
#L = (0, _1_logger_js_1.getLogger)("ClientWorker");
|
|
39
30
|
constructor(worker) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
_ClientWorker_L.set(this, (0, _1_logger_js_1.getLogger)("ClientWorker"));
|
|
43
|
-
__classPrivateFieldSet(this, _ClientWorker_worker, worker, "f");
|
|
44
|
-
__classPrivateFieldGet(this, _ClientWorker_worker, "f").addEventListener("message", async (e) => {
|
|
31
|
+
this.#worker = worker;
|
|
32
|
+
this.#worker.addEventListener("message", async (e) => {
|
|
45
33
|
const message = e.data;
|
|
46
|
-
|
|
34
|
+
this.#L.debug("received message from worker", message);
|
|
47
35
|
if (message.type === "response") {
|
|
48
|
-
|
|
36
|
+
this.#clients.get(message.clientId)?.handleResponse(message);
|
|
49
37
|
}
|
|
50
38
|
else if (message.type === "request") {
|
|
51
39
|
if (message.method === "handleInvokeError") {
|
|
52
|
-
const client =
|
|
40
|
+
const client = this.#clients.get(message.clientId);
|
|
53
41
|
if (client) {
|
|
54
42
|
const result = await client.handleInvokeError(message);
|
|
55
43
|
const response = {
|
|
@@ -59,35 +47,34 @@ class ClientWorker {
|
|
|
59
47
|
isError: false,
|
|
60
48
|
data: result,
|
|
61
49
|
};
|
|
62
|
-
|
|
50
|
+
this.#worker.postMessage(response);
|
|
63
51
|
}
|
|
64
52
|
}
|
|
65
53
|
}
|
|
66
54
|
});
|
|
67
55
|
}
|
|
68
56
|
async createClient(id, params) {
|
|
69
|
-
if (
|
|
57
|
+
if (this.#clients.has(id)) {
|
|
70
58
|
throw new _0_errors_js_1.InputError("Client already created");
|
|
71
59
|
}
|
|
72
|
-
const client = new _6_client_dispatcher_js_1.ClientDispatcher(
|
|
73
|
-
|
|
60
|
+
const client = new _6_client_dispatcher_js_1.ClientDispatcher(this.#worker, id);
|
|
61
|
+
this.#clients.set(id, client);
|
|
74
62
|
try {
|
|
75
63
|
await client.init(params);
|
|
76
64
|
}
|
|
77
65
|
catch (err) {
|
|
78
|
-
|
|
66
|
+
this.#clients.delete(id);
|
|
79
67
|
throw err;
|
|
80
68
|
}
|
|
81
69
|
return client;
|
|
82
70
|
}
|
|
83
71
|
getClient(id) {
|
|
84
|
-
let client =
|
|
72
|
+
let client = this.#clients.get(id);
|
|
85
73
|
if (!client) {
|
|
86
|
-
client = new _6_client_dispatcher_js_1.ClientDispatcher(
|
|
87
|
-
|
|
74
|
+
client = new _6_client_dispatcher_js_1.ClientDispatcher(this.#worker, id);
|
|
75
|
+
this.#clients.set(id, client);
|
|
88
76
|
}
|
|
89
77
|
return client;
|
|
90
78
|
}
|
|
91
79
|
}
|
|
92
80
|
exports.ClientWorker = ClientWorker;
|
|
93
|
-
_ClientWorker_worker = new WeakMap(), _ClientWorker_clients = new WeakMap(), _ClientWorker_L = new WeakMap();
|
|
@@ -18,18 +18,6 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _ConnectionTCP_instances, _ConnectionTCP_hostname, _ConnectionTCP_port, _ConnectionTCP_connection, _ConnectionTCP_rMutex, _ConnectionTCP_wMutex, _ConnectionTCP_buffer, _ConnectionTCP_nextResolve, _ConnectionTCP_canRead, _ConnectionTCP_canWrite, _ConnectionTCP_assertConnected, _ConnectionTCP_rejectRead;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.ConnectionTCP = void 0;
|
|
35
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -37,110 +25,105 @@ const _0_errors_js_1 = require("../0_errors.js");
|
|
|
37
25
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
38
26
|
const L = (0, _1_utilities_js_1.getLogger)("ConnectionTCP");
|
|
39
27
|
class ConnectionTCP {
|
|
28
|
+
#hostname;
|
|
29
|
+
#port;
|
|
30
|
+
#connection;
|
|
31
|
+
#rMutex = new _1_utilities_js_1.Mutex();
|
|
32
|
+
#wMutex = new _1_utilities_js_1.Mutex();
|
|
33
|
+
#buffer = new Uint8Array();
|
|
34
|
+
#nextResolve = null;
|
|
35
|
+
#canRead = false;
|
|
36
|
+
#canWrite = false;
|
|
37
|
+
connect = Deno.connect;
|
|
38
|
+
stateChangeHandler;
|
|
39
|
+
callback;
|
|
40
40
|
constructor(hostname, port) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
_ConnectionTCP_port.set(this, void 0);
|
|
44
|
-
_ConnectionTCP_connection.set(this, void 0);
|
|
45
|
-
_ConnectionTCP_rMutex.set(this, new _1_utilities_js_1.Mutex());
|
|
46
|
-
_ConnectionTCP_wMutex.set(this, new _1_utilities_js_1.Mutex());
|
|
47
|
-
_ConnectionTCP_buffer.set(this, new Uint8Array());
|
|
48
|
-
_ConnectionTCP_nextResolve.set(this, null);
|
|
49
|
-
_ConnectionTCP_canRead.set(this, false);
|
|
50
|
-
_ConnectionTCP_canWrite.set(this, false);
|
|
51
|
-
Object.defineProperty(this, "connect", {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
configurable: true,
|
|
54
|
-
writable: true,
|
|
55
|
-
value: Deno.connect
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(this, "stateChangeHandler", {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true,
|
|
60
|
-
writable: true,
|
|
61
|
-
value: void 0
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(this, "callback", {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true,
|
|
67
|
-
value: void 0
|
|
68
|
-
});
|
|
69
|
-
__classPrivateFieldSet(this, _ConnectionTCP_hostname, hostname, "f");
|
|
70
|
-
__classPrivateFieldSet(this, _ConnectionTCP_port, port, "f");
|
|
41
|
+
this.#hostname = hostname;
|
|
42
|
+
this.#port = port;
|
|
71
43
|
}
|
|
72
44
|
get isConnected() {
|
|
73
|
-
return !!
|
|
45
|
+
return !!this.#connection && this.#canRead && this.#canWrite;
|
|
46
|
+
}
|
|
47
|
+
#assertConnected() {
|
|
48
|
+
if (!this.isConnected) {
|
|
49
|
+
throw new _0_errors_js_1.ConnectionError("The connection is not open.");
|
|
50
|
+
}
|
|
74
51
|
}
|
|
75
52
|
async open() {
|
|
76
53
|
if (this.isConnected) {
|
|
77
54
|
return;
|
|
78
55
|
}
|
|
79
56
|
const connection = await this.connect({
|
|
80
|
-
hostname:
|
|
81
|
-
port:
|
|
57
|
+
hostname: this.#hostname,
|
|
58
|
+
port: this.#port,
|
|
82
59
|
});
|
|
83
60
|
connection.setNoDelay(true);
|
|
84
61
|
connection.setKeepAlive(true);
|
|
85
|
-
|
|
62
|
+
this.#canRead = this.#canWrite = true;
|
|
86
63
|
this.stateChangeHandler?.(true);
|
|
87
|
-
L.debug("connected to",
|
|
64
|
+
L.debug("connected to", this.#hostname, "port", this.#port);
|
|
88
65
|
Promise.resolve().then(async () => {
|
|
89
66
|
do {
|
|
90
67
|
try {
|
|
91
68
|
for await (const chunk of (0, _0_deps_js_1.iterateReader)(connection)) {
|
|
92
69
|
this.callback?.read(chunk.length);
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
70
|
+
this.#buffer = (0, _0_deps_js_1.concat)([this.#buffer, chunk]);
|
|
71
|
+
if (this.#nextResolve !== null && this.#buffer.length >= this.#nextResolve[0]) {
|
|
72
|
+
this.#nextResolve[1].resolve();
|
|
73
|
+
this.#nextResolve = null;
|
|
97
74
|
}
|
|
98
75
|
}
|
|
99
|
-
|
|
76
|
+
this.#canRead = false;
|
|
100
77
|
break;
|
|
101
78
|
}
|
|
102
79
|
catch (err) {
|
|
103
|
-
|
|
80
|
+
this.#canRead = false;
|
|
104
81
|
this.stateChangeHandler?.(false);
|
|
105
|
-
|
|
82
|
+
this.#rejectRead();
|
|
106
83
|
L.error(err);
|
|
107
84
|
}
|
|
108
85
|
} while (this.isConnected);
|
|
109
86
|
this.stateChangeHandler?.(false);
|
|
110
87
|
});
|
|
111
|
-
|
|
88
|
+
this.#connection = connection;
|
|
89
|
+
}
|
|
90
|
+
#rejectRead() {
|
|
91
|
+
if (this.#nextResolve !== null) {
|
|
92
|
+
this.#nextResolve[1].reject(new _0_errors_js_1.ConnectionError("The connection was closed."));
|
|
93
|
+
this.#nextResolve = null;
|
|
94
|
+
}
|
|
112
95
|
}
|
|
113
96
|
async read(p) {
|
|
114
|
-
|
|
115
|
-
const unlock = await
|
|
97
|
+
this.#assertConnected();
|
|
98
|
+
const unlock = await this.#rMutex.lock();
|
|
116
99
|
try {
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
await new Promise((resolve, reject) =>
|
|
100
|
+
this.#assertConnected();
|
|
101
|
+
if (this.#buffer.length < p.length) {
|
|
102
|
+
await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
|
|
120
103
|
}
|
|
121
|
-
const slice =
|
|
104
|
+
const slice = this.#buffer.slice(0, p.length);
|
|
122
105
|
p.set(slice);
|
|
123
|
-
|
|
106
|
+
this.#buffer = this.#buffer.slice(slice.length);
|
|
124
107
|
}
|
|
125
108
|
finally {
|
|
126
109
|
unlock();
|
|
127
110
|
}
|
|
128
111
|
}
|
|
129
112
|
async write(p) {
|
|
130
|
-
|
|
131
|
-
const unlock = await
|
|
113
|
+
this.#assertConnected();
|
|
114
|
+
const unlock = await this.#wMutex.lock();
|
|
132
115
|
try {
|
|
133
|
-
|
|
116
|
+
this.#assertConnected();
|
|
134
117
|
let written = 0;
|
|
135
118
|
while (written < p.length) {
|
|
136
119
|
try {
|
|
137
|
-
const wrote = await
|
|
120
|
+
const wrote = await this.#connection.write(p.subarray(written));
|
|
138
121
|
this.callback?.write(wrote);
|
|
139
122
|
written += wrote;
|
|
140
123
|
}
|
|
141
124
|
catch (err) {
|
|
142
125
|
if (err instanceof Deno.errors.BrokenPipe || err instanceof Deno.errors.ConnectionReset) {
|
|
143
|
-
|
|
126
|
+
this.#canWrite = false;
|
|
144
127
|
}
|
|
145
128
|
if (!this.isConnected) {
|
|
146
129
|
this.stateChangeHandler?.(false);
|
|
@@ -157,21 +140,11 @@ class ConnectionTCP {
|
|
|
157
140
|
}
|
|
158
141
|
}
|
|
159
142
|
close() {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
143
|
+
this.#assertConnected();
|
|
144
|
+
this.#connection.close();
|
|
145
|
+
this.#canRead = this.#canWrite = false;
|
|
146
|
+
this.#connection = undefined;
|
|
147
|
+
this.#rejectRead();
|
|
165
148
|
}
|
|
166
149
|
}
|
|
167
150
|
exports.ConnectionTCP = ConnectionTCP;
|
|
168
|
-
_ConnectionTCP_hostname = new WeakMap(), _ConnectionTCP_port = new WeakMap(), _ConnectionTCP_connection = new WeakMap(), _ConnectionTCP_rMutex = new WeakMap(), _ConnectionTCP_wMutex = new WeakMap(), _ConnectionTCP_buffer = new WeakMap(), _ConnectionTCP_nextResolve = new WeakMap(), _ConnectionTCP_canRead = new WeakMap(), _ConnectionTCP_canWrite = new WeakMap(), _ConnectionTCP_instances = new WeakSet(), _ConnectionTCP_assertConnected = function _ConnectionTCP_assertConnected() {
|
|
169
|
-
if (!this.isConnected) {
|
|
170
|
-
throw new _0_errors_js_1.ConnectionError("The connection is not open.");
|
|
171
|
-
}
|
|
172
|
-
}, _ConnectionTCP_rejectRead = function _ConnectionTCP_rejectRead() {
|
|
173
|
-
if (__classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f") !== null) {
|
|
174
|
-
__classPrivateFieldGet(this, _ConnectionTCP_nextResolve, "f")[1].reject(new _0_errors_js_1.ConnectionError("The connection was closed."));
|
|
175
|
-
__classPrivateFieldSet(this, _ConnectionTCP_nextResolve, null, "f");
|
|
176
|
-
}
|
|
177
|
-
};
|
|
@@ -18,18 +18,6 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _ConnectionWebSocket_instances, _ConnectionWebSocket_url, _ConnectionWebSocket_webSocket, _ConnectionWebSocket_rMutex, _ConnectionWebSocket_wMutex, _ConnectionWebSocket_buffer, _ConnectionWebSocket_nextResolve, _ConnectionWebSocket_initWs, _ConnectionWebSocket_isConnecting, _ConnectionWebSocket_assertConnected, _ConnectionWebSocket_rejectRead;
|
|
33
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
22
|
exports.ConnectionWebSocket = void 0;
|
|
35
23
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -38,115 +26,111 @@ const _1_utilities_js_1 = require("../1_utilities.js");
|
|
|
38
26
|
const L = (0, _1_utilities_js_1.getLogger)("ConnectionWebSocket");
|
|
39
27
|
const errConnectionNotOpen = new _0_errors_js_1.ConnectionError("The connection is not open.");
|
|
40
28
|
class ConnectionWebSocket {
|
|
29
|
+
#url;
|
|
30
|
+
#webSocket;
|
|
31
|
+
#rMutex = new _1_utilities_js_1.Mutex();
|
|
32
|
+
#wMutex = new _1_utilities_js_1.Mutex();
|
|
33
|
+
#buffer = new Uint8Array();
|
|
34
|
+
#nextResolve = null;
|
|
35
|
+
stateChangeHandler;
|
|
41
36
|
constructor(url) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
37
|
+
this.#url = url;
|
|
38
|
+
}
|
|
39
|
+
#initWs() {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const webSocket = new WebSocket(this.#url, "binary");
|
|
42
|
+
const mutex = new _1_utilities_js_1.Mutex();
|
|
43
|
+
webSocket.addEventListener("close", () => {
|
|
44
|
+
this.#rejectRead();
|
|
45
|
+
this.stateChangeHandler?.(false);
|
|
46
|
+
});
|
|
47
|
+
webSocket.addEventListener("open", () => {
|
|
48
|
+
this.stateChangeHandler?.(true);
|
|
49
|
+
resolve(webSocket);
|
|
50
|
+
L.debug("connected to", this.#url);
|
|
51
|
+
});
|
|
52
|
+
webSocket.addEventListener("message", async (e) => {
|
|
53
|
+
if (typeof e.data === "string") {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const unlock = await mutex.lock();
|
|
57
|
+
const data = new Uint8Array(await new Blob([e.data].map((v) => v instanceof Blob || v instanceof Uint8Array ? v : v instanceof ArrayBuffer ? v : (0, _0_deps_js_1.unreachable)())).arrayBuffer());
|
|
58
|
+
this.#buffer = (0, _0_deps_js_1.concat)([this.#buffer, data]);
|
|
59
|
+
if (this.#nextResolve !== null && this.#buffer.length >= this.#nextResolve[0]) {
|
|
60
|
+
this.#nextResolve[1].resolve();
|
|
61
|
+
this.#nextResolve = null;
|
|
62
|
+
}
|
|
63
|
+
unlock();
|
|
64
|
+
});
|
|
65
|
+
webSocket.addEventListener("error", (err) => {
|
|
66
|
+
if (this.#isConnecting) {
|
|
67
|
+
reject("message" in err ? new _0_errors_js_1.ConnectionError(err.message) : new _0_errors_js_1.ConnectionError("Failed to connect."));
|
|
68
|
+
}
|
|
69
|
+
if (this.isConnected) {
|
|
70
|
+
L.error(err);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
54
73
|
});
|
|
55
|
-
_ConnectionWebSocket_isConnecting.set(this, false);
|
|
56
|
-
__classPrivateFieldSet(this, _ConnectionWebSocket_url, url, "f");
|
|
57
74
|
}
|
|
58
75
|
get isConnected() {
|
|
59
|
-
return !!
|
|
76
|
+
return !!this.#webSocket && this.#webSocket.readyState === WebSocket.OPEN;
|
|
60
77
|
}
|
|
78
|
+
#isConnecting = false;
|
|
61
79
|
async open() {
|
|
62
|
-
if (
|
|
80
|
+
if (this.#isConnecting) {
|
|
63
81
|
return;
|
|
64
82
|
}
|
|
65
|
-
|
|
83
|
+
this.#isConnecting = true;
|
|
66
84
|
try {
|
|
67
|
-
|
|
85
|
+
this.#webSocket = await this.#initWs();
|
|
68
86
|
}
|
|
69
87
|
finally {
|
|
70
|
-
|
|
88
|
+
this.#isConnecting = false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
#assertConnected() {
|
|
92
|
+
if (!this.isConnected) {
|
|
93
|
+
throw errConnectionNotOpen;
|
|
71
94
|
}
|
|
72
95
|
}
|
|
73
96
|
async read(p) {
|
|
74
|
-
|
|
75
|
-
const unlock = await
|
|
97
|
+
this.#assertConnected();
|
|
98
|
+
const unlock = await this.#rMutex.lock();
|
|
76
99
|
try {
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
await new Promise((resolve, reject) =>
|
|
100
|
+
this.#assertConnected();
|
|
101
|
+
if (this.#buffer.length < p.length) {
|
|
102
|
+
await new Promise((resolve, reject) => this.#nextResolve = [p.length, { resolve, reject }]);
|
|
80
103
|
}
|
|
81
|
-
const slice =
|
|
104
|
+
const slice = this.#buffer.slice(0, p.length);
|
|
82
105
|
p.set(slice);
|
|
83
|
-
|
|
106
|
+
this.#buffer = this.#buffer.slice(slice.length);
|
|
84
107
|
}
|
|
85
108
|
finally {
|
|
86
109
|
unlock();
|
|
87
110
|
}
|
|
88
111
|
}
|
|
89
112
|
async write(p) {
|
|
90
|
-
|
|
91
|
-
const unlock = await
|
|
113
|
+
this.#assertConnected();
|
|
114
|
+
const unlock = await this.#wMutex.lock();
|
|
92
115
|
try {
|
|
93
|
-
|
|
94
|
-
|
|
116
|
+
this.#assertConnected();
|
|
117
|
+
this.#webSocket.send(p);
|
|
95
118
|
}
|
|
96
119
|
finally {
|
|
97
120
|
unlock();
|
|
98
121
|
}
|
|
99
122
|
}
|
|
123
|
+
#rejectRead() {
|
|
124
|
+
if (this.#nextResolve !== null) {
|
|
125
|
+
this.#nextResolve[1].reject(errConnectionNotOpen);
|
|
126
|
+
this.#nextResolve = null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
100
129
|
close() {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
130
|
+
this.#assertConnected();
|
|
131
|
+
this.#webSocket.close(1000, "method");
|
|
132
|
+
this.#webSocket = undefined;
|
|
133
|
+
this.#rejectRead();
|
|
105
134
|
}
|
|
106
135
|
}
|
|
107
136
|
exports.ConnectionWebSocket = ConnectionWebSocket;
|
|
108
|
-
_ConnectionWebSocket_url = new WeakMap(), _ConnectionWebSocket_webSocket = new WeakMap(), _ConnectionWebSocket_rMutex = new WeakMap(), _ConnectionWebSocket_wMutex = new WeakMap(), _ConnectionWebSocket_buffer = new WeakMap(), _ConnectionWebSocket_nextResolve = new WeakMap(), _ConnectionWebSocket_isConnecting = new WeakMap(), _ConnectionWebSocket_instances = new WeakSet(), _ConnectionWebSocket_initWs = function _ConnectionWebSocket_initWs() {
|
|
109
|
-
return new Promise((resolve, reject) => {
|
|
110
|
-
const webSocket = new WebSocket(__classPrivateFieldGet(this, _ConnectionWebSocket_url, "f"), "binary");
|
|
111
|
-
const mutex = new _1_utilities_js_1.Mutex();
|
|
112
|
-
webSocket.addEventListener("close", () => {
|
|
113
|
-
__classPrivateFieldGet(this, _ConnectionWebSocket_instances, "m", _ConnectionWebSocket_rejectRead).call(this);
|
|
114
|
-
this.stateChangeHandler?.(false);
|
|
115
|
-
});
|
|
116
|
-
webSocket.addEventListener("open", () => {
|
|
117
|
-
this.stateChangeHandler?.(true);
|
|
118
|
-
resolve(webSocket);
|
|
119
|
-
L.debug("connected to", __classPrivateFieldGet(this, _ConnectionWebSocket_url, "f"));
|
|
120
|
-
});
|
|
121
|
-
webSocket.addEventListener("message", async (e) => {
|
|
122
|
-
if (typeof e.data === "string") {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const unlock = await mutex.lock();
|
|
126
|
-
const data = new Uint8Array(await new Blob([e.data].map((v) => v instanceof Blob || v instanceof Uint8Array ? v : v instanceof ArrayBuffer ? v : (0, _0_deps_js_1.unreachable)())).arrayBuffer());
|
|
127
|
-
__classPrivateFieldSet(this, _ConnectionWebSocket_buffer, (0, _0_deps_js_1.concat)([__classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f"), data]), "f");
|
|
128
|
-
if (__classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f") !== null && __classPrivateFieldGet(this, _ConnectionWebSocket_buffer, "f").length >= __classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[0]) {
|
|
129
|
-
__classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[1].resolve();
|
|
130
|
-
__classPrivateFieldSet(this, _ConnectionWebSocket_nextResolve, null, "f");
|
|
131
|
-
}
|
|
132
|
-
unlock();
|
|
133
|
-
});
|
|
134
|
-
webSocket.addEventListener("error", (err) => {
|
|
135
|
-
if (__classPrivateFieldGet(this, _ConnectionWebSocket_isConnecting, "f")) {
|
|
136
|
-
reject("message" in err ? new _0_errors_js_1.ConnectionError(err.message) : new _0_errors_js_1.ConnectionError("Failed to connect."));
|
|
137
|
-
}
|
|
138
|
-
if (this.isConnected) {
|
|
139
|
-
L.error(err);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
}, _ConnectionWebSocket_assertConnected = function _ConnectionWebSocket_assertConnected() {
|
|
144
|
-
if (!this.isConnected) {
|
|
145
|
-
throw errConnectionNotOpen;
|
|
146
|
-
}
|
|
147
|
-
}, _ConnectionWebSocket_rejectRead = function _ConnectionWebSocket_rejectRead() {
|
|
148
|
-
if (__classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f") !== null) {
|
|
149
|
-
__classPrivateFieldGet(this, _ConnectionWebSocket_nextResolve, "f")[1].reject(errConnectionNotOpen);
|
|
150
|
-
__classPrivateFieldSet(this, _ConnectionWebSocket_nextResolve, null, "f");
|
|
151
|
-
}
|
|
152
|
-
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var Module = (() => {
|
|
4
|
-
var _scriptName =
|
|
4
|
+
var _scriptName = import.meta.url;
|
|
5
5
|
return (function (moduleArg = {}) {
|
|
6
6
|
var moduleRtn;
|
|
7
7
|
var Module = moduleArg;
|
|
@@ -119,16 +119,8 @@ var Module = (() => {
|
|
|
119
119
|
}
|
|
120
120
|
} wasmBinaryFile ??= findWasmBinary(); instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult).catch(readyPromiseReject); return {}; }
|
|
121
121
|
class ExitStatus {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
enumerable: true,
|
|
125
|
-
configurable: true,
|
|
126
|
-
writable: true,
|
|
127
|
-
value: "ExitStatus"
|
|
128
|
-
});
|
|
129
|
-
this.message = `Program terminated with exit(${status})`;
|
|
130
|
-
this.status = status;
|
|
131
|
-
}
|
|
122
|
+
name = "ExitStatus";
|
|
123
|
+
constructor(status) { this.message = `Program terminated with exit(${status})`; this.status = status; }
|
|
132
124
|
}
|
|
133
125
|
var callRuntimeCallbacks = callbacks => { while (callbacks.length > 0) {
|
|
134
126
|
callbacks.shift()(Module);
|