@senior-gestao-empresarial/angular-components 4.22.1 → 4.22.2-7c0b6b2c-1273-4faf-bd8a-91d677cec9bd
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/senior-gestao-empresarial-angular-components.umd.js +179 -106
- package/bundles/senior-gestao-empresarial-angular-components.umd.js.map +1 -1
- package/bundles/senior-gestao-empresarial-angular-components.umd.min.js +2 -2
- package/bundles/senior-gestao-empresarial-angular-components.umd.min.js.map +1 -1
- package/components/websocket/websocket.service.d.ts +26 -17
- package/esm2015/components/websocket/websocket.service.js +113 -84
- package/esm5/components/websocket/websocket.service.js +177 -106
- package/fesm2015/senior-gestao-empresarial-angular-components.js +112 -82
- package/fesm2015/senior-gestao-empresarial-angular-components.js.map +1 -1
- package/fesm5/senior-gestao-empresarial-angular-components.js +176 -104
- package/fesm5/senior-gestao-empresarial-angular-components.js.map +1 -1
- package/package.json +1 -1
- package/senior-gestao-empresarial-angular-components.metadata.json +1 -1
|
@@ -4,7 +4,7 @@ import { CommonModule } from '@angular/common';
|
|
|
4
4
|
import { BreadcrumbModule as BreadcrumbModule$1 } from 'primeng/breadcrumb';
|
|
5
5
|
import { NavigationEnd, PRIMARY_OUTLET, ActivatedRoute, Router, RouterModule } from '@angular/router';
|
|
6
6
|
import { Subject, throwError, interval, of, ReplaySubject } from 'rxjs';
|
|
7
|
-
import { takeUntil, filter, catchError, map, takeWhile, switchMap, first, take } from 'rxjs/operators';
|
|
7
|
+
import { takeUntil, filter, catchError, map, takeWhile, switchMap, first, finalize, take } from 'rxjs/operators';
|
|
8
8
|
import * as moment_ from 'moment';
|
|
9
9
|
import { FormField, FieldType } from '@seniorsistemas/angular-components';
|
|
10
10
|
import { HttpParams, HttpClient } from '@angular/common/http';
|
|
@@ -15,7 +15,6 @@ import { user } from '@seniorsistemas/senior-platform-data';
|
|
|
15
15
|
import { FormControl, FormGroup } from '@angular/forms';
|
|
16
16
|
import { get } from 'js-cookie';
|
|
17
17
|
import { Stomp } from '@stomp/stompjs';
|
|
18
|
-
import { CookieService } from 'ngx-cookie-service';
|
|
19
18
|
import * as SockJS from 'sockjs-client';
|
|
20
19
|
|
|
21
20
|
let BreadcrumbComponent = class BreadcrumbComponent {
|
|
@@ -6014,80 +6013,95 @@ NpsService = __decorate([
|
|
|
6014
6013
|
|
|
6015
6014
|
var WebsocketService_1;
|
|
6016
6015
|
let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
6017
|
-
constructor(
|
|
6018
|
-
this.cookieService = cookieService;
|
|
6019
|
-
this.baseUrl = null;
|
|
6020
|
-
this.username = null;
|
|
6016
|
+
constructor() {
|
|
6021
6017
|
this.focused = true;
|
|
6018
|
+
this.wasConnected = false;
|
|
6022
6019
|
this.connected = false;
|
|
6023
6020
|
this.isConnecting = false;
|
|
6024
|
-
this.stompSubscriptions = new Map();
|
|
6025
6021
|
this.primitiveManagers = new Map();
|
|
6026
|
-
this.disconnectSubject = new Subject();
|
|
6027
6022
|
this.connect$ = new Subject();
|
|
6023
|
+
this.disconnect$ = new Subject();
|
|
6024
|
+
this.reconnect$ = new Subject();
|
|
6025
|
+
this.error$ = new Subject();
|
|
6028
6026
|
window.onfocus = this.onFocus;
|
|
6029
6027
|
window.onblur = this.onBlur;
|
|
6030
6028
|
this.connect();
|
|
6031
6029
|
}
|
|
6032
6030
|
/**
|
|
6033
6031
|
* Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida.
|
|
6034
|
-
* @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida
|
|
6032
|
+
* @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida.
|
|
6035
6033
|
*/
|
|
6036
6034
|
onConnect() {
|
|
6037
6035
|
setTimeout(() => {
|
|
6038
6036
|
if (this.isConnected()) {
|
|
6039
|
-
this.
|
|
6037
|
+
this.connect$.next();
|
|
6040
6038
|
}
|
|
6041
6039
|
}, 0);
|
|
6042
|
-
return this.connect$.
|
|
6040
|
+
return this.connect$.pipe(first());
|
|
6043
6041
|
}
|
|
6044
6042
|
/**
|
|
6045
|
-
* Observable responsável por emitir uma notificação quando a conexão é
|
|
6046
|
-
* @return Um `Observable<void>` que emite uma notificação quando a conexão é
|
|
6043
|
+
* Observable responsável por emitir uma notificação quando a conexão é desconectada.
|
|
6044
|
+
* @return Um `Observable<void>` que emite uma notificação quando a conexão é desconectada.
|
|
6047
6045
|
*/
|
|
6048
6046
|
onDisconnect() {
|
|
6049
|
-
return this.
|
|
6047
|
+
return this.disconnect$.asObservable();
|
|
6048
|
+
}
|
|
6049
|
+
/**
|
|
6050
|
+
* Observable responsável por emitir uma notificação quando a conexão é reconectada.
|
|
6051
|
+
* @return Um `Observable<void>` que emite uma notificação quando a conexão é reconectada.
|
|
6052
|
+
*/
|
|
6053
|
+
onReconnect() {
|
|
6054
|
+
return this.reconnect$.asObservable();
|
|
6055
|
+
}
|
|
6056
|
+
/**
|
|
6057
|
+
* Observable responsável por emitir uma notificação quando ocorre algum erro.
|
|
6058
|
+
* @return Um `Observable<FrameImpl>` que emite uma notificação quando ocorre algum erro.
|
|
6059
|
+
*/
|
|
6060
|
+
onError() {
|
|
6061
|
+
return this.error$.asObservable();
|
|
6050
6062
|
}
|
|
6051
6063
|
/**
|
|
6052
6064
|
* Observable responsável por emitir uma notificação quando um evento é publicado.
|
|
6053
6065
|
* @typeParam `<T>` Tipo do objeto que o retorno do `observable` vai devolver.
|
|
6054
|
-
* @param domain Dominio da
|
|
6066
|
+
* @param domain Dominio da primitiva.
|
|
6055
6067
|
* @param service Service da primitiva.
|
|
6056
6068
|
* @param primitive Primitiva que será "observada" pelo client.
|
|
6057
|
-
* @param identifierPath Caminho até a propriedade considerada o
|
|
6069
|
+
* @param identifierPath Caminho até a propriedade considerada o identificador do registro.
|
|
6058
6070
|
* @return Um `observable` que emite notificações toda vez que o respectivo evento é publicado no sistema.
|
|
6059
6071
|
*/
|
|
6060
6072
|
onEvent(domain, service, primitive, identifierPath) {
|
|
6061
|
-
|
|
6062
|
-
|
|
6063
|
-
return primitiveManager.subject.asObservable();
|
|
6073
|
+
if (this.primitiveManagers.has(primitive)) {
|
|
6074
|
+
return this.primitiveManagers.get(primitive).subject.asObservable();
|
|
6064
6075
|
}
|
|
6065
|
-
primitiveManager = {
|
|
6076
|
+
const primitiveManager = {
|
|
6077
|
+
domain: domain,
|
|
6078
|
+
service: service,
|
|
6079
|
+
primitive: primitive,
|
|
6080
|
+
stompSubscriptions: [],
|
|
6066
6081
|
subject: new Subject(),
|
|
6067
6082
|
identifierPath: identifierPath,
|
|
6068
6083
|
publishedEvents: [],
|
|
6069
6084
|
};
|
|
6085
|
+
this.primitiveManagers.set(primitive, primitiveManager);
|
|
6070
6086
|
if (this.isConnected()) {
|
|
6071
|
-
this.createStompSubscriptions(
|
|
6072
|
-
return primitiveManager.subject.
|
|
6087
|
+
this.createStompSubscriptions(primitiveManager);
|
|
6088
|
+
return primitiveManager.subject.pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitive)));
|
|
6073
6089
|
}
|
|
6074
6090
|
else {
|
|
6075
6091
|
if (!this.isConnecting) {
|
|
6076
6092
|
this.connect();
|
|
6077
6093
|
}
|
|
6078
|
-
this.
|
|
6079
|
-
.
|
|
6080
|
-
.subscribe(() => {
|
|
6081
|
-
this.createStompSubscriptions(domain, service, primitive, primitiveManager);
|
|
6094
|
+
this.connect$.pipe(first()).subscribe(() => {
|
|
6095
|
+
this.createStompSubscriptions(primitiveManager);
|
|
6082
6096
|
});
|
|
6083
|
-
return primitiveManager.subject.
|
|
6097
|
+
return primitiveManager.subject.pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitive)));
|
|
6084
6098
|
}
|
|
6085
6099
|
}
|
|
6086
6100
|
/**
|
|
6087
6101
|
* Retorna todos os eventos ouvidos pela primitiva com os respectivos identificadores.
|
|
6088
6102
|
* @typeParam `<T>` Tipo do evento retornado pela primitiva.
|
|
6089
6103
|
* @param primitive Primitiva que será "observada" pelo client.
|
|
6090
|
-
* @param identifiers Array com os
|
|
6104
|
+
* @param identifiers Array com os identificadores interessados.
|
|
6091
6105
|
* @return Array contendo o último evento recebido de cada identificador fornecido.
|
|
6092
6106
|
*/
|
|
6093
6107
|
getPublishedEvents(primitive, identifiers) {
|
|
@@ -6111,13 +6125,12 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6111
6125
|
primitiveManager.publishedEvents.push(event);
|
|
6112
6126
|
}
|
|
6113
6127
|
}
|
|
6114
|
-
createStompSubscriptions(
|
|
6115
|
-
const withTokenUrl = this.getSubscriptionUrlWithToken(domain, service, primitive);
|
|
6116
|
-
this.primitiveManagers.set(primitive, primitiveManager);
|
|
6128
|
+
createStompSubscriptions(primitiveManager) {
|
|
6129
|
+
const withTokenUrl = this.getSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
|
|
6117
6130
|
const stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
|
|
6118
|
-
const withoutTokenUrl = this.getSubscriptionUrlWithoutToken(domain, service, primitive);
|
|
6131
|
+
const withoutTokenUrl = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
|
|
6119
6132
|
const stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
|
|
6120
|
-
|
|
6133
|
+
primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
|
|
6121
6134
|
}
|
|
6122
6135
|
getIdentifierFromEvent(identifierPath, event) {
|
|
6123
6136
|
const properties = identifierPath.split(".");
|
|
@@ -6130,19 +6143,24 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6130
6143
|
connect() {
|
|
6131
6144
|
this.createStompClient();
|
|
6132
6145
|
this.isConnecting = true;
|
|
6146
|
+
this._stompClient.activate();
|
|
6133
6147
|
this._stompClient.connect({}, () => {
|
|
6134
|
-
this.setConnected(true);
|
|
6135
6148
|
this.isConnecting = false;
|
|
6136
|
-
this.
|
|
6137
|
-
|
|
6149
|
+
this.setConnected(true);
|
|
6150
|
+
if (this.wasConnected) {
|
|
6151
|
+
this.reconnectPrimitives();
|
|
6152
|
+
this.reconnect$.next();
|
|
6153
|
+
}
|
|
6154
|
+
else {
|
|
6155
|
+
this.wasConnected = true;
|
|
6156
|
+
this.connect$.next();
|
|
6157
|
+
}
|
|
6158
|
+
}, (error) => {
|
|
6138
6159
|
this.setConnected(false);
|
|
6139
|
-
|
|
6160
|
+
this.error$.next(error);
|
|
6161
|
+
this.reconnect();
|
|
6140
6162
|
});
|
|
6141
6163
|
}
|
|
6142
|
-
publishOnConnect() {
|
|
6143
|
-
this.connect$.next();
|
|
6144
|
-
this.connect$.observers = [];
|
|
6145
|
-
}
|
|
6146
6164
|
onFocus() {
|
|
6147
6165
|
this.focused = true;
|
|
6148
6166
|
}
|
|
@@ -6150,27 +6168,24 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6150
6168
|
this.focused = false;
|
|
6151
6169
|
}
|
|
6152
6170
|
disconnect() {
|
|
6153
|
-
|
|
6171
|
+
const observersCount = this.getObserversCount();
|
|
6172
|
+
if (observersCount > 0)
|
|
6173
|
+
return;
|
|
6154
6174
|
for (const primitiveManager of this.primitiveManagers.values()) {
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
if (observersCount === 0) {
|
|
6158
|
-
this.stompSubscriptions.forEach(stompSubscriptions => {
|
|
6159
|
-
for (const stompSubscription of stompSubscriptions) {
|
|
6160
|
-
stompSubscription.unsubscribe();
|
|
6161
|
-
}
|
|
6162
|
-
});
|
|
6163
|
-
for (const primitiveManager of this.primitiveManagers.values()) {
|
|
6164
|
-
primitiveManager.subject.complete();
|
|
6175
|
+
for (const stompSubscription of primitiveManager.stompSubscriptions) {
|
|
6176
|
+
stompSubscription.unsubscribe();
|
|
6165
6177
|
}
|
|
6166
|
-
this.stompSubscriptions.clear();
|
|
6167
|
-
this.primitiveManagers.clear();
|
|
6168
|
-
this._stompClient.disconnect();
|
|
6169
|
-
this._stompClient.deactivate();
|
|
6170
|
-
this.setConnected(false);
|
|
6171
|
-
this.isConnecting = false;
|
|
6172
|
-
this.disconnectSubject.next();
|
|
6173
6178
|
}
|
|
6179
|
+
for (const primitiveManager of this.primitiveManagers.values()) {
|
|
6180
|
+
primitiveManager.subject.complete();
|
|
6181
|
+
}
|
|
6182
|
+
this.primitiveManagers.clear();
|
|
6183
|
+
this._stompClient.disconnect();
|
|
6184
|
+
this._stompClient.deactivate();
|
|
6185
|
+
this.setConnected(false);
|
|
6186
|
+
this.isConnecting = false;
|
|
6187
|
+
this.wasConnected = false;
|
|
6188
|
+
this.disconnect$.next();
|
|
6174
6189
|
}
|
|
6175
6190
|
isConnected() {
|
|
6176
6191
|
return this.connected;
|
|
@@ -6197,45 +6212,60 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6197
6212
|
createStompClient() {
|
|
6198
6213
|
const ws = new SockJS(`${WebsocketService_1.WEBSOCKET_URL}subscription`, null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
|
|
6199
6214
|
this._stompClient = Stomp.over(ws);
|
|
6215
|
+
// this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
|
|
6200
6216
|
this._stompClient.debug = () => { }; // Para remover os logs.
|
|
6201
6217
|
}
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
getUserName() {
|
|
6206
|
-
const token = this.cookieService.get("com.senior.token");
|
|
6207
|
-
return token && JSON.parse(token).username;
|
|
6208
|
-
}
|
|
6209
|
-
reconnectWebSocket() {
|
|
6210
|
-
this._stompClient.disconnect();
|
|
6211
|
-
const baseUrl = this.getBaseUrl();
|
|
6212
|
-
if (this.baseUrl !== null && baseUrl != this.baseUrl) {
|
|
6213
|
-
return;
|
|
6214
|
-
}
|
|
6215
|
-
const username = this.getUserName();
|
|
6216
|
-
if (this.username !== null && username != this.username) {
|
|
6217
|
-
return;
|
|
6218
|
-
}
|
|
6218
|
+
reconnect() {
|
|
6219
|
+
if (this.connected)
|
|
6220
|
+
this._stompClient.disconnect();
|
|
6219
6221
|
setTimeout(() => {
|
|
6222
|
+
if (this.getObserversCount() === 0)
|
|
6223
|
+
return;
|
|
6220
6224
|
if (this.focused) {
|
|
6221
6225
|
this.connect();
|
|
6222
6226
|
}
|
|
6223
6227
|
else {
|
|
6224
|
-
this.
|
|
6228
|
+
this.reconnect();
|
|
6225
6229
|
}
|
|
6226
6230
|
}, WebsocketService_1.RECONNECT_TIMER);
|
|
6227
6231
|
}
|
|
6232
|
+
reconnectPrimitives() {
|
|
6233
|
+
for (const primitiveManager of this.primitiveManagers.values()) {
|
|
6234
|
+
for (const stompSubscription of primitiveManager.stompSubscriptions) {
|
|
6235
|
+
stompSubscription.unsubscribe();
|
|
6236
|
+
}
|
|
6237
|
+
this.createStompSubscriptions(primitiveManager);
|
|
6238
|
+
}
|
|
6239
|
+
}
|
|
6240
|
+
getObserversCount() {
|
|
6241
|
+
let observersCount = 0;
|
|
6242
|
+
for (const primitiveManager of this.primitiveManagers.values()) {
|
|
6243
|
+
observersCount += primitiveManager.subject.observers.length;
|
|
6244
|
+
}
|
|
6245
|
+
return observersCount;
|
|
6246
|
+
}
|
|
6247
|
+
disconnectPrimitiveOnFinalize(primitive) {
|
|
6248
|
+
const primitiveManager = this.primitiveManagers.get(primitive);
|
|
6249
|
+
if (!primitiveManager)
|
|
6250
|
+
return;
|
|
6251
|
+
// @IMPORTANT: Replace .observers.length with .observed in rxjs 7.0+
|
|
6252
|
+
const hasObservers = !(primitiveManager.subject.observers.length === 1);
|
|
6253
|
+
if (hasObservers)
|
|
6254
|
+
return;
|
|
6255
|
+
for (const stompSubscription of primitiveManager.stompSubscriptions) {
|
|
6256
|
+
stompSubscription.unsubscribe();
|
|
6257
|
+
}
|
|
6258
|
+
this.primitiveManagers.delete(primitive);
|
|
6259
|
+
this.disconnect();
|
|
6260
|
+
}
|
|
6228
6261
|
};
|
|
6229
6262
|
WebsocketService.RECONNECT_TIMER = 3000;
|
|
6230
|
-
WebsocketService.CONNECTION_TIMEOUT =
|
|
6263
|
+
WebsocketService.CONNECTION_TIMEOUT = 15000;
|
|
6231
6264
|
WebsocketService.BASE_URL_COOKIE = "com.senior.base.url";
|
|
6232
6265
|
WebsocketService.TOKEN_COOKIE = "com.senior.token";
|
|
6233
6266
|
WebsocketService.TOKEN = JSON.parse(get(WebsocketService_1.TOKEN_COOKIE) || "{}");
|
|
6234
6267
|
WebsocketService.WEBSOCKET_URL = get(WebsocketService_1.BASE_URL_COOKIE) + "/websocket/";
|
|
6235
|
-
WebsocketService
|
|
6236
|
-
{ type: CookieService }
|
|
6237
|
-
];
|
|
6238
|
-
WebsocketService.ɵprov = ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(ɵɵinject(CookieService)); }, token: WebsocketService, providedIn: "root" });
|
|
6268
|
+
WebsocketService.ɵprov = ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
|
|
6239
6269
|
WebsocketService = WebsocketService_1 = __decorate([
|
|
6240
6270
|
Injectable({
|
|
6241
6271
|
providedIn: "root",
|