@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.
- package/bundles/sumaris-net.ngx-components.umd.js +44 -54
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/doc/changelog.md +1 -1
- package/esm2015/src/app/core/services/account.service.js +38 -27
- package/esm2015/src/app/shared/services/progress-bar.service.js +1 -1
- package/fesm2015/sumaris-net.ngx-components.js +34 -23
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/src/app/core/services/account.service.d.ts +2 -0
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -13561,6 +13561,7 @@ class AccountService extends BaseGraphqlService {
|
|
|
13561
13561
|
this.onChange = new Subject();
|
|
13562
13562
|
this.onAuthTokenChange = new Subject();
|
|
13563
13563
|
this.onAuthBasicChange = new Subject();
|
|
13564
|
+
this._stopWatching$ = new Subject();
|
|
13564
13565
|
this._cache = {
|
|
13565
13566
|
loaded: false,
|
|
13566
13567
|
keypair: null,
|
|
@@ -13963,6 +13964,7 @@ class AccountService extends BaseGraphqlService {
|
|
|
13963
13964
|
if (hadAuthBasic)
|
|
13964
13965
|
this.onAuthBasicChange.next(undefined);
|
|
13965
13966
|
this.onChange.next(undefined);
|
|
13967
|
+
this._stopWatching$.next();
|
|
13966
13968
|
});
|
|
13967
13969
|
}
|
|
13968
13970
|
/**
|
|
@@ -14079,12 +14081,17 @@ class AccountService extends BaseGraphqlService {
|
|
|
14079
14081
|
return res && res.confirmAccountEmail;
|
|
14080
14082
|
});
|
|
14081
14083
|
}
|
|
14082
|
-
|
|
14084
|
+
watch() {
|
|
14083
14085
|
if (!this._cache.pubkey)
|
|
14084
|
-
|
|
14085
|
-
|
|
14086
|
-
|
|
14087
|
-
|
|
14086
|
+
throw new Error('Not logged in');
|
|
14087
|
+
if (!this.started) {
|
|
14088
|
+
// Wait service ready, then loop
|
|
14089
|
+
return from(this.ready())
|
|
14090
|
+
.pipe(switchMap(() => this.watch()));
|
|
14091
|
+
}
|
|
14092
|
+
this._stopWatching$.next(); // Stop previous listening
|
|
14093
|
+
console.debug('[account] [WS] Watching changes');
|
|
14094
|
+
return this.graphql.subscribe({
|
|
14088
14095
|
query: AccountSubscriptions.listenChanges,
|
|
14089
14096
|
variables: {
|
|
14090
14097
|
interval: 10
|
|
@@ -14093,35 +14100,39 @@ class AccountService extends BaseGraphqlService {
|
|
|
14093
14100
|
code: ErrorCodes$2.SUBSCRIBE_ACCOUNT_ERROR,
|
|
14094
14101
|
message: 'ERROR.ACCOUNT.SUBSCRIBE_ACCOUNT_ERROR'
|
|
14095
14102
|
}
|
|
14096
|
-
})
|
|
14097
|
-
|
|
14098
|
-
|
|
14099
|
-
|
|
14100
|
-
|
|
14101
|
-
|
|
14102
|
-
|
|
14103
|
-
|
|
14104
|
-
|
|
14105
|
-
|
|
14106
|
-
})
|
|
14107
|
-
|
|
14103
|
+
})
|
|
14104
|
+
.pipe(
|
|
14105
|
+
// Stop this pipe next time we call watch()
|
|
14106
|
+
takeUntil(this._stopWatching$), map(({ data }) => {
|
|
14107
|
+
var _a;
|
|
14108
|
+
if (!data)
|
|
14109
|
+
return;
|
|
14110
|
+
const existingUpdateDate = toDateISOString((_a = this._data) === null || _a === void 0 ? void 0 : _a.updateDate);
|
|
14111
|
+
if (existingUpdateDate === data.updateDate)
|
|
14112
|
+
return;
|
|
14113
|
+
console.debug(`[account] [WS] Detected update on {${data.updateDate}}`);
|
|
14114
|
+
return Account.fromObject(data);
|
|
14115
|
+
}), filter(isNotNil));
|
|
14116
|
+
}
|
|
14117
|
+
listenChanges() {
|
|
14118
|
+
const self = this;
|
|
14119
|
+
const subscription = this.watch()
|
|
14120
|
+
.subscribe({
|
|
14121
|
+
next: (data) => self.refresh(),
|
|
14122
|
+
error: (err) => {
|
|
14108
14123
|
if (err && +err.code === ServerErrorCodes.NOT_FOUND) {
|
|
14109
14124
|
console.info('[account] Account not exists anymore: force user to logout...', err);
|
|
14110
|
-
|
|
14125
|
+
self.logout();
|
|
14111
14126
|
}
|
|
14112
14127
|
else if (err && +err.code === ServerErrorCodes.UNAUTHORIZED) {
|
|
14113
14128
|
console.info('[account] Account not authorized: force user to logout...', err);
|
|
14114
|
-
|
|
14129
|
+
self.logout();
|
|
14115
14130
|
}
|
|
14116
14131
|
else {
|
|
14117
14132
|
console.warn('[account] [WS] Received error:', err);
|
|
14118
14133
|
}
|
|
14119
|
-
}),
|
|
14120
|
-
complete: () => {
|
|
14121
|
-
console.debug('[account] [WS] Completed');
|
|
14122
14134
|
}
|
|
14123
14135
|
});
|
|
14124
|
-
// Add log when closing WS
|
|
14125
14136
|
subscription.add(() => console.debug('[account] [WS] Stop listening changes'));
|
|
14126
14137
|
return subscription;
|
|
14127
14138
|
}
|