@senior-gestao-empresarial/angular-components 4.22.1 → 4.22.2-7ecfc706-3270-4664-9d10-a6918ef49acd
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 +176 -100
- 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 -16
- package/esm2015/components/websocket/websocket.service.js +110 -78
- package/esm5/components/websocket/websocket.service.js +174 -100
- package/fesm2015/senior-gestao-empresarial-angular-components.js +109 -76
- package/fesm2015/senior-gestao-empresarial-angular-components.js.map +1 -1
- package/fesm5/senior-gestao-empresarial-angular-components.js +173 -98
- 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, finalize, first, 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,24 +6013,23 @@ 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(() => {
|
|
@@ -6042,52 +6040,68 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6042
6040
|
return this.connect$.asObservable();
|
|
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,13 +6143,22 @@ 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.publishOnConnect();
|
|
6157
|
+
}
|
|
6158
|
+
}, (error) => {
|
|
6138
6159
|
this.setConnected(false);
|
|
6139
|
-
|
|
6160
|
+
this.error$.next(error);
|
|
6161
|
+
this.reconnect();
|
|
6140
6162
|
});
|
|
6141
6163
|
}
|
|
6142
6164
|
publishOnConnect() {
|
|
@@ -6150,27 +6172,23 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6150
6172
|
this.focused = false;
|
|
6151
6173
|
}
|
|
6152
6174
|
disconnect() {
|
|
6153
|
-
|
|
6175
|
+
const observersCount = this.getObserversCount();
|
|
6176
|
+
if (observersCount > 0)
|
|
6177
|
+
return;
|
|
6154
6178
|
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();
|
|
6179
|
+
for (const stompSubscription of primitiveManager.stompSubscriptions) {
|
|
6180
|
+
stompSubscription.unsubscribe();
|
|
6165
6181
|
}
|
|
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
6182
|
}
|
|
6183
|
+
for (const primitiveManager of this.primitiveManagers.values()) {
|
|
6184
|
+
primitiveManager.subject.complete();
|
|
6185
|
+
}
|
|
6186
|
+
this.primitiveManagers.clear();
|
|
6187
|
+
this._stompClient.disconnect();
|
|
6188
|
+
this._stompClient.deactivate();
|
|
6189
|
+
this.setConnected(false);
|
|
6190
|
+
this.isConnecting = false;
|
|
6191
|
+
this.disconnect$.next();
|
|
6174
6192
|
}
|
|
6175
6193
|
isConnected() {
|
|
6176
6194
|
return this.connected;
|
|
@@ -6197,45 +6215,60 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6197
6215
|
createStompClient() {
|
|
6198
6216
|
const ws = new SockJS(`${WebsocketService_1.WEBSOCKET_URL}subscription`, null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
|
|
6199
6217
|
this._stompClient = Stomp.over(ws);
|
|
6218
|
+
// this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
|
|
6200
6219
|
this._stompClient.debug = () => { }; // Para remover os logs.
|
|
6201
6220
|
}
|
|
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
|
-
}
|
|
6221
|
+
reconnect() {
|
|
6222
|
+
if (this.connected)
|
|
6223
|
+
this._stompClient.disconnect();
|
|
6219
6224
|
setTimeout(() => {
|
|
6225
|
+
if (this.getObserversCount() === 0)
|
|
6226
|
+
return;
|
|
6220
6227
|
if (this.focused) {
|
|
6221
6228
|
this.connect();
|
|
6222
6229
|
}
|
|
6223
6230
|
else {
|
|
6224
|
-
this.
|
|
6231
|
+
this.reconnect();
|
|
6225
6232
|
}
|
|
6226
6233
|
}, WebsocketService_1.RECONNECT_TIMER);
|
|
6227
6234
|
}
|
|
6235
|
+
reconnectPrimitives() {
|
|
6236
|
+
for (const primitiveManager of this.primitiveManagers.values()) {
|
|
6237
|
+
for (const stompSubscription of primitiveManager.stompSubscriptions) {
|
|
6238
|
+
stompSubscription.unsubscribe();
|
|
6239
|
+
}
|
|
6240
|
+
this.createStompSubscriptions(primitiveManager);
|
|
6241
|
+
}
|
|
6242
|
+
}
|
|
6243
|
+
getObserversCount() {
|
|
6244
|
+
let observersCount = 0;
|
|
6245
|
+
for (const primitiveManager of this.primitiveManagers.values()) {
|
|
6246
|
+
observersCount += primitiveManager.subject.observers.length;
|
|
6247
|
+
}
|
|
6248
|
+
return observersCount;
|
|
6249
|
+
}
|
|
6250
|
+
disconnectPrimitiveOnFinalize(primitive) {
|
|
6251
|
+
const primitiveManager = this.primitiveManagers.get(primitive);
|
|
6252
|
+
if (!primitiveManager)
|
|
6253
|
+
return;
|
|
6254
|
+
// @IMPORTANT: Replace .observers.length with .observed in rxjs 7.0+
|
|
6255
|
+
const hasObservers = !(primitiveManager.subject.observers.length === 1);
|
|
6256
|
+
if (hasObservers)
|
|
6257
|
+
return;
|
|
6258
|
+
for (const stompSubscription of primitiveManager.stompSubscriptions) {
|
|
6259
|
+
stompSubscription.unsubscribe();
|
|
6260
|
+
}
|
|
6261
|
+
this.primitiveManagers.delete(primitive);
|
|
6262
|
+
this.disconnect();
|
|
6263
|
+
}
|
|
6228
6264
|
};
|
|
6229
6265
|
WebsocketService.RECONNECT_TIMER = 3000;
|
|
6230
|
-
WebsocketService.CONNECTION_TIMEOUT =
|
|
6266
|
+
WebsocketService.CONNECTION_TIMEOUT = 15000;
|
|
6231
6267
|
WebsocketService.BASE_URL_COOKIE = "com.senior.base.url";
|
|
6232
6268
|
WebsocketService.TOKEN_COOKIE = "com.senior.token";
|
|
6233
6269
|
WebsocketService.TOKEN = JSON.parse(get(WebsocketService_1.TOKEN_COOKIE) || "{}");
|
|
6234
6270
|
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" });
|
|
6271
|
+
WebsocketService.ɵprov = ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
|
|
6239
6272
|
WebsocketService = WebsocketService_1 = __decorate([
|
|
6240
6273
|
Injectable({
|
|
6241
6274
|
providedIn: "root",
|