core-3nweb-client-lib 0.41.10 → 0.41.11
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/build/core/asmail/inbox/inbox-events.d.ts +5 -0
- package/build/core/asmail/inbox/inbox-events.js +12 -2
- package/build/core/storage/synced/remote-events.js +1 -1
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/server-events.d.ts +4 -2
- package/build/lib-client/server-events.js +9 -3
- package/build/lib-client/ws-utils.js +2 -2
- package/build/lib-common/ipc/generic-ipc.js +30 -25
- package/build/lib-common/ipc/ws-ipc.d.ts +1 -0
- package/build/lib-common/ipc/ws-ipc.js +9 -17
- package/package.json +1 -1
|
Binary file
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { SubscribingClient } from '../lib-common/ipc/generic-ipc';
|
|
2
2
|
import { Observable } from 'rxjs';
|
|
3
|
+
import { LogError } from './logging/log-to-file';
|
|
3
4
|
export declare class ServerEvents<N extends string, T> {
|
|
4
|
-
private subscribeToServer;
|
|
5
|
+
private readonly subscribeToServer;
|
|
5
6
|
private restartWaitSecs;
|
|
7
|
+
private readonly logError;
|
|
6
8
|
private server;
|
|
7
9
|
private openningServer;
|
|
8
|
-
constructor(subscribeToServer: () => Promise<SubscribingClient>, restartWaitSecs: number);
|
|
10
|
+
constructor(subscribeToServer: () => Promise<SubscribingClient>, restartWaitSecs: number, logError: LogError);
|
|
9
11
|
/**
|
|
10
12
|
* This method creates an observable of server's events.
|
|
11
13
|
* @param event is an event on server, to which to subscribe.
|
|
@@ -23,9 +23,10 @@ const sleep_1 = require("../lib-common/processes/sleep");
|
|
|
23
23
|
const operators_1 = require("rxjs/operators");
|
|
24
24
|
const error_1 = require("../lib-common/exceptions/error");
|
|
25
25
|
class ServerEvents {
|
|
26
|
-
constructor(subscribeToServer, restartWaitSecs) {
|
|
26
|
+
constructor(subscribeToServer, restartWaitSecs, logError) {
|
|
27
27
|
this.subscribeToServer = subscribeToServer;
|
|
28
28
|
this.restartWaitSecs = restartWaitSecs;
|
|
29
|
+
this.logError = logError;
|
|
29
30
|
this.server = undefined;
|
|
30
31
|
this.openningServer = new synced_1.SingleProc();
|
|
31
32
|
Object.seal(this);
|
|
@@ -72,13 +73,18 @@ class ServerEvents {
|
|
|
72
73
|
}
|
|
73
74
|
};
|
|
74
75
|
})
|
|
75
|
-
.pipe(
|
|
76
|
+
.pipe(
|
|
77
|
+
// XXX tap to log more details
|
|
78
|
+
(0, operators_1.tap)({
|
|
79
|
+
complete: () => this.logError({}, `ServerEvents.observe stream completes`),
|
|
80
|
+
error: err => this.logError(err, `ServerEvents.observe stream has error`)
|
|
81
|
+
}), (0, operators_1.catchError)(err => {
|
|
76
82
|
if (this.shouldRestartAfterErr(err)) {
|
|
77
83
|
console.error((0, error_1.stringifyErr)(err));
|
|
78
84
|
return this.restartObservation(event);
|
|
79
85
|
}
|
|
80
86
|
else {
|
|
81
|
-
return (0, rxjs_1.throwError)(err);
|
|
87
|
+
return (0, rxjs_1.throwError)(() => err);
|
|
82
88
|
}
|
|
83
89
|
}));
|
|
84
90
|
return event$;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2017, 2019 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2017, 2019, 2025 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -29,7 +29,7 @@ function openSocket(url, sessionId) {
|
|
|
29
29
|
headers[request_utils_1.SESSION_ID_HEADER] = sessionId;
|
|
30
30
|
const ws = new WebSocket(url, { headers, agent: https_1.globalAgent });
|
|
31
31
|
const opening = (0, deferred_1.defer)();
|
|
32
|
-
const initOnError = err => opening.reject((0, http_1.makeConnectionException)(url, undefined, `Cannot open websocket connection due to error: ${err.message}`));
|
|
32
|
+
const initOnError = (err) => opening.reject((0, http_1.makeConnectionException)(url, undefined, `Cannot open websocket connection due to error: ${err.message}`));
|
|
33
33
|
const onNonOkReply = (req, res) => {
|
|
34
34
|
const errReply = {
|
|
35
35
|
url,
|
|
@@ -13,15 +13,20 @@
|
|
|
13
13
|
See the GNU General Public License for more details.
|
|
14
14
|
|
|
15
15
|
You should have received a copy of the GNU General Public License along with
|
|
16
|
-
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
17
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
19
|
exports.SingleObserverWrap = exports.MultiObserverWrap = void 0;
|
|
19
20
|
exports.makeRequestingClient = makeRequestingClient;
|
|
20
21
|
exports.makeRequestServer = makeRequestServer;
|
|
21
22
|
exports.makeEventfulServer = makeEventfulServer;
|
|
22
23
|
exports.makeSubscribingClient = makeSubscribingClient;
|
|
24
|
+
const runtime_1 = require("../exceptions/runtime");
|
|
23
25
|
const map_of_sets_1 = require("../map-of-sets");
|
|
24
26
|
const synced_1 = require("../processes/synced");
|
|
27
|
+
function makeEventException(params) {
|
|
28
|
+
return (0, runtime_1.makeRuntimeException)('events', params, {});
|
|
29
|
+
}
|
|
25
30
|
function toTransferrableError(e) {
|
|
26
31
|
if (e.runtimeException) {
|
|
27
32
|
return e;
|
|
@@ -142,7 +147,14 @@ class RequestingSide extends MessageHandler {
|
|
|
142
147
|
}
|
|
143
148
|
this.replyDeferreds.clear();
|
|
144
149
|
}
|
|
145
|
-
makeRequest(name, req, notifyCallback) {
|
|
150
|
+
async makeRequest(name, req, notifyCallback) {
|
|
151
|
+
if (!this.rawDuplex) {
|
|
152
|
+
throw makeEventException({
|
|
153
|
+
channel: this.channel,
|
|
154
|
+
duplexDisconnected: true,
|
|
155
|
+
request: name
|
|
156
|
+
});
|
|
157
|
+
}
|
|
146
158
|
this.counter += 1;
|
|
147
159
|
if (this.counter === Number.MAX_SAFE_INTEGER) {
|
|
148
160
|
this.counter = Number.MIN_SAFE_INTEGER;
|
|
@@ -225,26 +237,21 @@ class ReplyingSide extends MessageHandler {
|
|
|
225
237
|
}
|
|
226
238
|
}
|
|
227
239
|
errorReply(env, err) {
|
|
228
|
-
|
|
240
|
+
return {
|
|
229
241
|
type: 'reply',
|
|
230
242
|
reqName: env.name,
|
|
231
243
|
reqCount: env.count,
|
|
232
|
-
rep: null
|
|
244
|
+
rep: null,
|
|
245
|
+
err: (err.runtimeException ?
|
|
246
|
+
err : toTransferrableError(err))
|
|
233
247
|
};
|
|
234
|
-
if (err.runtimeException) {
|
|
235
|
-
reply.err = err;
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
reply.err = toTransferrableError(err);
|
|
239
|
-
}
|
|
240
|
-
return reply;
|
|
241
248
|
}
|
|
242
249
|
normalReply(env, rep, isInProgress = false) {
|
|
243
250
|
const reply = {
|
|
244
251
|
type: 'reply',
|
|
245
252
|
reqName: env.name,
|
|
246
253
|
reqCount: env.count,
|
|
247
|
-
rep
|
|
254
|
+
rep,
|
|
248
255
|
};
|
|
249
256
|
if (isInProgress) {
|
|
250
257
|
reply.isInProgress = true;
|
|
@@ -283,14 +290,6 @@ Object.freeze(ReplyingSide);
|
|
|
283
290
|
function makeRequestServer(channel, comm) {
|
|
284
291
|
return (new ReplyingSide(channel, comm)).wrap();
|
|
285
292
|
}
|
|
286
|
-
function makeUnknownEventException(message) {
|
|
287
|
-
return {
|
|
288
|
-
runtimeException: true,
|
|
289
|
-
type: 'events',
|
|
290
|
-
unknownEvent: true,
|
|
291
|
-
message
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
293
|
const SUBSCRIBE_REQ_NAME = 'subscribe';
|
|
295
294
|
const UNSUBSCRIBE_REQ_NAME = 'unsubscribe';
|
|
296
295
|
class EventsSendingSide extends ReplyingSide {
|
|
@@ -313,7 +312,11 @@ class EventsSendingSide extends ReplyingSide {
|
|
|
313
312
|
const event = env.req;
|
|
314
313
|
const gr = this.findGroup(event);
|
|
315
314
|
if (!gr) {
|
|
316
|
-
throw
|
|
315
|
+
throw makeEventException({
|
|
316
|
+
channel: this.channel,
|
|
317
|
+
unknownEvent: true,
|
|
318
|
+
message: `Events' channel ${event} is not found in handling subscribe`
|
|
319
|
+
});
|
|
317
320
|
}
|
|
318
321
|
this.subscribedEvents.add(event);
|
|
319
322
|
await gr.subscribe(event);
|
|
@@ -322,7 +325,11 @@ class EventsSendingSide extends ReplyingSide {
|
|
|
322
325
|
const event = env.req;
|
|
323
326
|
const gr = this.findGroup(event);
|
|
324
327
|
if (!gr) {
|
|
325
|
-
throw
|
|
328
|
+
throw makeEventException({
|
|
329
|
+
channel: this.channel,
|
|
330
|
+
unknownEvent: true,
|
|
331
|
+
message: `Events' channel ${event} is not found in handling unsubscribe`
|
|
332
|
+
});
|
|
326
333
|
}
|
|
327
334
|
this.subscribedEvents.delete(event);
|
|
328
335
|
if (gr.unsubscribe) {
|
|
@@ -442,9 +449,7 @@ class EventsReceivingSide extends RequestingSide {
|
|
|
442
449
|
* name, to which listener is attached.
|
|
443
450
|
*/
|
|
444
451
|
this.listeners = new map_of_sets_1.MapOfSets();
|
|
445
|
-
this.channels = new IpcEventChannels((ipcChannel) => this.makeRequest(
|
|
446
|
-
.catch(err => this.completeEvent(ipcChannel, err)), (ipcChannel) => this.makeRequest(UNSUBSCRIBE_REQ_NAME, ipcChannel)
|
|
447
|
-
.catch(_ => { }));
|
|
452
|
+
this.channels = new IpcEventChannels(ipcChannel => this.makeRequest(SUBSCRIBE_REQ_NAME, ipcChannel).catch(err => this.completeEvent(ipcChannel, err)), ipcChannel => this.makeRequest(UNSUBSCRIBE_REQ_NAME, ipcChannel).catch(_ => { }));
|
|
448
453
|
}
|
|
449
454
|
handleMsg(env) {
|
|
450
455
|
if (env.type === 'event') {
|
|
@@ -6,4 +6,5 @@ export interface WSException extends web3n.RuntimeException {
|
|
|
6
6
|
socketSlow?: true;
|
|
7
7
|
socketClosed?: true;
|
|
8
8
|
}
|
|
9
|
+
export declare function makeWSException(params: Partial<WSException>, flags?: Partial<WSException>): WSException;
|
|
9
10
|
export declare function makeSubscriber(ws: WebSocket, ipcChannel: string | undefined): SubscribingClient;
|
|
@@ -16,10 +16,15 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.makeEventfulServer = void 0;
|
|
19
|
+
exports.makeWSException = makeWSException;
|
|
19
20
|
exports.makeSubscriber = makeSubscriber;
|
|
21
|
+
const runtime_1 = require("../exceptions/runtime");
|
|
20
22
|
const generic_ipc_1 = require("./generic-ipc");
|
|
21
23
|
var generic_ipc_2 = require("./generic-ipc");
|
|
22
24
|
Object.defineProperty(exports, "makeEventfulServer", { enumerable: true, get: function () { return generic_ipc_2.makeEventfulServer; } });
|
|
25
|
+
function makeWSException(params, flags) {
|
|
26
|
+
return (0, runtime_1.makeRuntimeException)('websocket', params, flags !== null && flags !== void 0 ? flags : {});
|
|
27
|
+
}
|
|
23
28
|
const MAX_TXT_BUFFER = 64 * 1024;
|
|
24
29
|
/**
|
|
25
30
|
* This creates a json communication point on a given web socket.
|
|
@@ -37,12 +42,7 @@ function makeJsonCommPoint(ws) {
|
|
|
37
42
|
subscribe: obs => observers.add(obs),
|
|
38
43
|
postMessage(env) {
|
|
39
44
|
if (ws.bufferedAmount > MAX_TXT_BUFFER) {
|
|
40
|
-
|
|
41
|
-
runtimeException: true,
|
|
42
|
-
type: 'websocket',
|
|
43
|
-
socketSlow: true
|
|
44
|
-
};
|
|
45
|
-
throw exc;
|
|
45
|
+
throw makeWSException({ socketSlow: true });
|
|
46
46
|
}
|
|
47
47
|
ws.send(JSON.stringify(env));
|
|
48
48
|
}
|
|
@@ -84,13 +84,10 @@ function onClose(observers) {
|
|
|
84
84
|
observers.complete();
|
|
85
85
|
}
|
|
86
86
|
else {
|
|
87
|
-
|
|
88
|
-
runtimeException: true,
|
|
89
|
-
type: 'websocket',
|
|
87
|
+
observers.error(makeWSException({
|
|
90
88
|
socketClosed: true,
|
|
91
89
|
cause: { code, reason }
|
|
92
|
-
};
|
|
93
|
-
observers.error(exc);
|
|
90
|
+
}));
|
|
94
91
|
}
|
|
95
92
|
};
|
|
96
93
|
}
|
|
@@ -101,12 +98,7 @@ function onClose(observers) {
|
|
|
101
98
|
*/
|
|
102
99
|
function onError(ws, observers) {
|
|
103
100
|
return (err) => {
|
|
104
|
-
|
|
105
|
-
runtimeException: true,
|
|
106
|
-
type: 'websocket',
|
|
107
|
-
cause: err
|
|
108
|
-
};
|
|
109
|
-
observers.error(exc);
|
|
101
|
+
observers.error(makeWSException({ cause: err }));
|
|
110
102
|
ws.close();
|
|
111
103
|
};
|
|
112
104
|
}
|