@sumaris-net/ngx-components 1.8.1 → 1.8.2

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.
@@ -15419,6 +15419,7 @@
15419
15419
  _this.onChange = new rxjs.Subject();
15420
15420
  _this.onAuthTokenChange = new rxjs.Subject();
15421
15421
  _this.onAuthBasicChange = new rxjs.Subject();
15422
+ _this._stopWatching$ = new rxjs.Subject();
15422
15423
  _this._cache = {
15423
15424
  loaded: false,
15424
15425
  keypair: null,
@@ -15945,6 +15946,7 @@
15945
15946
  if (hadAuthBasic)
15946
15947
  this.onAuthBasicChange.next(undefined);
15947
15948
  this.onChange.next(undefined);
15949
+ this._stopWatching$.next();
15948
15950
  return [2 /*return*/];
15949
15951
  }
15950
15952
  });
@@ -16104,13 +16106,18 @@
16104
16106
  });
16105
16107
  });
16106
16108
  };
16107
- AccountService.prototype.listenChanges = function () {
16109
+ AccountService.prototype.watch = function () {
16108
16110
  var _this = this;
16109
16111
  if (!this._cache.pubkey)
16110
- return rxjs.Subscription.EMPTY;
16111
- var self = this;
16112
- console.debug('[account] [WS] Listening changes');
16113
- var subscription = this.graphql.subscribe({
16112
+ throw new Error('Not logged in');
16113
+ if (!this.started) {
16114
+ // Wait service ready, then loop
16115
+ return rxjs.from(this.ready())
16116
+ .pipe(operators.switchMap(function () { return _this.watch(); }));
16117
+ }
16118
+ this._stopWatching$.next(); // Stop previous listening
16119
+ console.debug('[account] [WS] Watching changes');
16120
+ return this.graphql.subscribe({
16114
16121
  query: AccountSubscriptions.listenChanges,
16115
16122
  variables: {
16116
16123
  interval: 10
@@ -16119,57 +16126,40 @@
16119
16126
  code: ErrorCodes$2.SUBSCRIBE_ACCOUNT_ERROR,
16120
16127
  message: 'ERROR.ACCOUNT.SUBSCRIBE_ACCOUNT_ERROR'
16121
16128
  }
16122
- }).subscribe({
16123
- next: function (_b) {
16124
- var data = _b.data;
16125
- return __awaiter(_this, void 0, void 0, function () {
16126
- var _a, existingUpdateDate;
16127
- return __generator(this, function (_b) {
16128
- switch (_b.label) {
16129
- case 0:
16130
- if (!data)
16131
- return [2 /*return*/];
16132
- existingUpdateDate = toDateISOString((_a = self._data) === null || _a === void 0 ? void 0 : _a.updateDate);
16133
- if (!(existingUpdateDate !== data.updateDate)) return [3 /*break*/, 2];
16134
- console.debug("[account] [WS] Detected update on {" + data.updateDate + "}");
16135
- return [4 /*yield*/, self.refresh()];
16136
- case 1:
16137
- _b.sent();
16138
- _b.label = 2;
16139
- case 2: return [2 /*return*/];
16140
- }
16141
- });
16142
- });
16143
- },
16144
- error: function (err) { return __awaiter(_this, void 0, void 0, function () {
16145
- return __generator(this, function (_b) {
16146
- switch (_b.label) {
16147
- case 0:
16148
- if (!(err && +err.code === ServerErrorCodes.NOT_FOUND)) return [3 /*break*/, 2];
16149
- console.info('[account] Account not exists anymore: force user to logout...', err);
16150
- return [4 /*yield*/, self.logout()];
16151
- case 1:
16152
- _b.sent();
16153
- return [3 /*break*/, 5];
16154
- case 2:
16155
- if (!(err && +err.code === ServerErrorCodes.UNAUTHORIZED)) return [3 /*break*/, 4];
16156
- console.info('[account] Account not authorized: force user to logout...', err);
16157
- return [4 /*yield*/, self.logout()];
16158
- case 3:
16159
- _b.sent();
16160
- return [3 /*break*/, 5];
16161
- case 4:
16162
- console.warn('[account] [WS] Received error:', err);
16163
- _b.label = 5;
16164
- case 5: return [2 /*return*/];
16165
- }
16166
- });
16167
- }); },
16168
- complete: function () {
16169
- console.debug('[account] [WS] Completed');
16129
+ })
16130
+ .pipe(
16131
+ // Stop this pipe next time we call watch()
16132
+ operators.takeUntil(this._stopWatching$), operators.map(function (_b) {
16133
+ var data = _b.data;
16134
+ var _a;
16135
+ if (!data)
16136
+ return;
16137
+ var existingUpdateDate = toDateISOString((_a = _this._data) === null || _a === void 0 ? void 0 : _a.updateDate);
16138
+ if (existingUpdateDate === data.updateDate)
16139
+ return;
16140
+ console.debug("[account] [WS] Detected update on {" + data.updateDate + "}");
16141
+ return exports.Account.fromObject(data);
16142
+ }), operators.filter(isNotNil));
16143
+ };
16144
+ AccountService.prototype.listenChanges = function () {
16145
+ var self = this;
16146
+ var subscription = this.watch()
16147
+ .subscribe({
16148
+ next: function (data) { return self.refresh(); },
16149
+ error: function (err) {
16150
+ if (err && +err.code === ServerErrorCodes.NOT_FOUND) {
16151
+ console.info('[account] Account not exists anymore: force user to logout...', err);
16152
+ self.logout();
16153
+ }
16154
+ else if (err && +err.code === ServerErrorCodes.UNAUTHORIZED) {
16155
+ console.info('[account] Account not authorized: force user to logout...', err);
16156
+ self.logout();
16157
+ }
16158
+ else {
16159
+ console.warn('[account] [WS] Received error:', err);
16160
+ }
16170
16161
  }
16171
16162
  });
16172
- // Add log when closing WS
16173
16163
  subscription.add(function () { return console.debug('[account] [WS] Stop listening changes'); });
16174
16164
  return subscription;
16175
16165
  };