core-3nweb-client-lib 0.43.5 → 0.43.6

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.
@@ -29,18 +29,13 @@ export declare class InboxEvents {
29
29
  private readonly newMsg$;
30
30
  private readonly connectionEvents;
31
31
  readonly connectionEvent$: Observable<InboxConnectionStatus>;
32
- private listeningProc;
33
- private networkActive;
32
+ private readonly wsProc;
34
33
  private disconnectedAt;
35
34
  constructor(msgReceiver: MailRecipient, getMsg: (msgId: string) => Promise<IncomingMessage>, listNewMsgs: (fromTS: number) => Promise<MsgInfo[]>, rmMsg: (msgId: string) => Promise<void>, logError: LogError);
36
- private startListening;
37
- private sleepAndRestart;
35
+ private makeProc;
38
36
  private getMessage;
39
37
  subscribe<T>(event: InboxEventType, observer: Observer<T>): () => void;
40
38
  close(): void;
41
- get isListening(): boolean;
42
- private shouldRestartAfterErr;
43
- private stopListening;
44
39
  suspendNetworkActivity(): void;
45
40
  resumeNetworkActivity(): void;
46
41
  private listMsgsFromDisconnectedPeriod;
@@ -22,7 +22,6 @@ const retrieval_1 = require("../../../lib-common/service-api/asmail/retrieval");
22
22
  const operators_1 = require("rxjs/operators");
23
23
  const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
24
24
  const ws_ipc_1 = require("../../../lib-common/ipc/ws-ipc");
25
- const sleep_1 = require("../../../lib-common/processes/sleep");
26
25
  function toInboxConnectionStatus(status, params) {
27
26
  return (0, ws_ipc_1.addToStatus)(status, {
28
27
  service: 'inbox',
@@ -52,54 +51,30 @@ class InboxEvents {
52
51
  this.newMsg$ = this.newMsgs.asObservable().pipe((0, operators_1.share)());
53
52
  this.connectionEvents = new rxjs_1.Subject();
54
53
  this.connectionEvent$ = this.connectionEvents.asObservable().pipe((0, operators_1.share)());
55
- this.listeningProc = undefined;
56
- this.networkActive = true;
57
54
  this.disconnectedAt = undefined;
58
- this.startListening();
55
+ this.wsProc = new ws_ipc_1.WebSocketListening(SERVER_EVENTS_RESTART_WAIT_SECS, this.makeProc.bind(this));
56
+ this.wsProc.startListening();
59
57
  Object.seal(this);
60
58
  }
61
- startListening() {
62
- if (this.listeningProc || !this.networkActive) {
63
- return;
64
- }
65
- const clearListeningProc = () => {
66
- if (this.listeningProc === sub) {
67
- this.listeningProc = undefined;
68
- }
69
- if (!this.disconnectedAt) {
70
- this.disconnectedAt = Date.now();
71
- }
72
- };
73
- const sub = (0, rxjs_1.from)(this.msgReceiver.openEventSource().then(({ client, heartbeat }) => {
59
+ makeProc() {
60
+ const proc$ = (0, rxjs_1.from)(this.msgReceiver.openEventSource().then(({ client, heartbeat }) => {
74
61
  const channel = retrieval_1.msgRecievedCompletely.EVENT_NAME;
75
62
  heartbeat.subscribe({
76
63
  next: ev => this.connectionEvents.next(toInboxConnectionStatus(ev))
77
64
  });
78
65
  return new rxjs_1.Observable(obs => client.subscribe(channel, obs));
79
66
  }))
80
- .pipe((0, operators_1.mergeMap)(events => events), (0, operators_1.mergeMap)(async (ev) => this.getMessage(ev.msgId), 5))
81
- .subscribe({
82
- next: msg => {
83
- if (msg) {
84
- this.newMsgs.next(msg);
85
- }
86
- },
87
- complete: () => {
88
- clearListeningProc();
89
- },
90
- error: async (exc) => {
91
- clearListeningProc();
92
- if (this.shouldRestartAfterErr(exc)) {
93
- this.sleepAndRestart();
67
+ .pipe((0, operators_1.mergeMap)(events => events), (0, operators_1.mergeMap)(async (ev) => this.getMessage(ev.msgId), 5), (0, operators_1.filter)(msg => !!msg), (0, operators_1.tap)({
68
+ next: msg => this.newMsgs.next(msg),
69
+ error: () => {
70
+ if (!this.disconnectedAt) {
71
+ this.disconnectedAt = Date.now();
94
72
  }
95
73
  }
96
- });
97
- this.listeningProc = sub;
74
+ }));
75
+ // list messages as a side effect of starting, or at point of starting.
98
76
  this.listMsgsFromDisconnectedPeriod();
99
- }
100
- async sleepAndRestart() {
101
- await (0, sleep_1.sleep)(SERVER_EVENTS_RESTART_WAIT_SECS);
102
- this.startListening();
77
+ return proc$;
103
78
  }
104
79
  async getMessage(msgId) {
105
80
  try {
@@ -123,45 +98,26 @@ class InboxEvents {
123
98
  }
124
99
  close() {
125
100
  this.newMsgs.complete();
101
+ this.wsProc.close();
126
102
  }
127
- get isListening() {
128
- return !!this.listeningProc;
129
- }
130
- shouldRestartAfterErr(exc) {
131
- if (!exc.runtimeException) {
132
- return false;
133
- }
134
- if (exc.type === 'connect') {
135
- return true;
136
- }
137
- else if (exc.type === 'http-request') {
138
- return false;
139
- }
140
- else if (exc.type === 'websocket') {
141
- return true;
142
- }
143
- else {
144
- return false;
145
- }
146
- }
147
- stopListening() {
148
- var _a;
149
- (_a = this.listeningProc) === null || _a === void 0 ? void 0 : _a.unsubscribe();
150
- this.listeningProc = undefined;
151
- }
103
+ // XXX we should go along:
104
+ // - last working connection and ping
105
+ // - may be have an expect suspending of network, with less aggressive attempts to reconnect
106
+ // - instead of talking about presence of network, expose methods to nudge restarting behaviour, as outside
107
+ // may have better clues and able to command behaviour switch
152
108
  suspendNetworkActivity() {
153
- this.networkActive = false;
154
- if (this.isListening) {
155
- if (!this.disconnectedAt) {
156
- this.disconnectedAt = Date.now();
157
- }
158
- this.stopListening();
159
- }
109
+ // XXX code below shutdown for good, but restart sometimes has been failing.
110
+ //
111
+ // if (this.isListening) {
112
+ // if (!this.disconnectedAt) {
113
+ // this.disconnectedAt = Date.now();
114
+ // }
115
+ // this.stopListening();
116
+ // }
160
117
  }
161
118
  resumeNetworkActivity() {
162
- this.networkActive = true;
163
- if (!this.isListening) {
164
- this.startListening();
119
+ if (!this.wsProc.isListening) {
120
+ this.wsProc.startListening();
165
121
  }
166
122
  }
167
123
  async listMsgsFromDisconnectedPeriod() {
@@ -178,9 +134,6 @@ class InboxEvents {
178
134
  this.newMsgs.next(msg);
179
135
  this.disconnectedAt = msg.deliveryTS;
180
136
  }
181
- else if (!this.networkActive) {
182
- return;
183
- }
184
137
  }
185
138
  this.disconnectedAt = undefined;
186
139
  }
@@ -18,9 +18,10 @@ export declare class RemoteEvents {
18
18
  private readonly logError;
19
19
  private readonly connectionEvents;
20
20
  readonly connectionEvent$: Observable<StorageConnectionStatus>;
21
+ private readonly wsProc;
21
22
  constructor(remoteStorage: StorageOwner, files: ObjFiles, broadcastNodeEvent: Storage['broadcastNodeEvent'], logError: LogError);
22
- private absorbingRemoteEventsProc;
23
- startAbsorbingRemoteEvents(): void;
23
+ private makeProc;
24
+ startListening(): void;
24
25
  close(): Promise<void>;
25
26
  private absorbObjChange;
26
27
  private absorbObjRemoval;
@@ -33,6 +33,7 @@ const SERVER_EVENTS_RESTART_WAIT_SECS = 5;
33
33
  * events. Someone down the stream can react to these changes from remote.
34
34
  */
35
35
  class RemoteEvents {
36
+ // private listeningProc: Subscription|undefined = undefined;
36
37
  constructor(remoteStorage, files, broadcastNodeEvent, logError) {
37
38
  this.remoteStorage = remoteStorage;
38
39
  this.files = files;
@@ -40,11 +41,11 @@ class RemoteEvents {
40
41
  this.logError = logError;
41
42
  this.connectionEvents = new rxjs_1.Subject();
42
43
  this.connectionEvent$ = this.connectionEvents.asObservable().pipe((0, operators_1.share)());
43
- this.absorbingRemoteEventsProc = undefined;
44
+ this.wsProc = new ws_ipc_1.WebSocketListening(SERVER_EVENTS_RESTART_WAIT_SECS, this.makeProc.bind(this));
44
45
  Object.seal(this);
45
46
  }
46
- startAbsorbingRemoteEvents() {
47
- this.absorbingRemoteEventsProc = (0, rxjs_1.from)(this.remoteStorage.openEventSource().then(({ client, heartbeat }) => {
47
+ makeProc() {
48
+ return (0, rxjs_1.from)(this.remoteStorage.openEventSource().then(({ client, heartbeat }) => {
48
49
  heartbeat.subscribe({
49
50
  next: ev => this.connectionEvents.next(toStorageConnectionStatus(ev))
50
51
  });
@@ -56,23 +57,14 @@ class RemoteEvents {
56
57
  // this.absorbArchVersionRemoval(client)
57
58
  ];
58
59
  }))
59
- .pipe((0, operators_1.mergeMap)(event$ => event$), (0, operators_1.mergeMap)(event$ => event$))
60
- .subscribe({
61
- next: noop,
62
- error: async (err) => {
63
- await this.logError(err);
64
- this.absorbingRemoteEventsProc = undefined;
65
- },
66
- complete: () => {
67
- this.absorbingRemoteEventsProc = undefined;
68
- }
69
- });
60
+ .pipe((0, operators_1.mergeMap)(event$ => event$), (0, operators_1.mergeMap)(event$ => event$));
61
+ }
62
+ startListening() {
63
+ this.wsProc.startListening();
70
64
  }
71
65
  async close() {
72
- if (this.absorbingRemoteEventsProc) {
73
- this.absorbingRemoteEventsProc.unsubscribe();
74
- this.absorbingRemoteEventsProc = undefined;
75
- }
66
+ this.connectionEvents.complete();
67
+ this.wsProc.close();
76
68
  }
77
69
  absorbObjChange(client) {
78
70
  return (new rxjs_1.Observable(obs => client.subscribe(owner_1.events.objChanged.EVENT_NAME, obs)))
@@ -136,19 +128,22 @@ class RemoteEvents {
136
128
  });
137
129
  }, 1));
138
130
  }
131
+ // XXX we should go along:
132
+ // - last working connection and ping
133
+ // - may be have an expect suspending of network, with less aggressive attempts to reconnect
134
+ // - instead of talking about presence of network, expose methods to nudge restarting behaviour, as outside
135
+ // may have better clues and able to command behaviour switch
139
136
  suspendNetworkActivity() {
140
137
  // XXX
141
- // - set haveNetwork flag to false
142
- // - press breaks on events from server
138
+ // - ...
143
139
  }
144
140
  resumeNetworkActivity() {
145
- // XXX
146
- // - set haveNetwork flag to true
147
- // - restart watching events from server
141
+ if (!this.wsProc.isListening) {
142
+ this.wsProc.startListening();
143
+ }
148
144
  }
149
145
  }
150
146
  exports.RemoteEvents = RemoteEvents;
151
147
  Object.freeze(RemoteEvents.prototype);
152
148
  Object.freeze(RemoteEvents);
153
- function noop() { }
154
149
  Object.freeze(exports);
@@ -51,7 +51,7 @@ class SyncedStore {
51
51
  return {
52
52
  syncedStore: (0, common_1.wrapSyncStorageImplementation)(s),
53
53
  startObjProcs: () => {
54
- s.remoteEvents.startAbsorbingRemoteEvents();
54
+ s.remoteEvents.startListening();
55
55
  }
56
56
  };
57
57
  }
@@ -64,7 +64,7 @@ class SyncedStore {
64
64
  setupRemoteAndStartObjProcs: getSigner => {
65
65
  setMid(getSigner);
66
66
  s.uploader.start();
67
- s.remoteEvents.startAbsorbingRemoteEvents();
67
+ s.remoteEvents.startListening();
68
68
  }
69
69
  };
70
70
  }