@senior-gestao-empresarial/angular-components 6.7.1 → 6.9.0
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 +63 -87
- package/bundles/senior-gestao-empresarial-angular-components.umd.js.map +1 -1
- package/bundles/senior-gestao-empresarial-angular-components.umd.min.js +1 -1
- package/bundles/senior-gestao-empresarial-angular-components.umd.min.js.map +1 -1
- package/components/websocket/websocket.service.d.ts +16 -16
- package/esm2015/components/websocket/websocket.service.js +48 -68
- package/esm5/components/websocket/websocket.service.js +66 -90
- package/fesm2015/senior-gestao-empresarial-angular-components.js +47 -67
- package/fesm2015/senior-gestao-empresarial-angular-components.js.map +1 -1
- package/fesm5/senior-gestao-empresarial-angular-components.js +65 -89
- 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
|
@@ -3,8 +3,8 @@ import { Input, Component, NgModule, Injectable, Inject, ɵɵdefineInjectable,
|
|
|
3
3
|
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
|
-
import { Subject, throwError, interval, of, ReplaySubject } from 'rxjs';
|
|
7
|
-
import { takeUntil, filter, catchError, map, takeWhile, switchMap,
|
|
6
|
+
import { Subject, throwError, interval, of, timer, iif, fromEvent, EMPTY, ReplaySubject } from 'rxjs';
|
|
7
|
+
import { takeUntil, filter, catchError, map, takeWhile, switchMap, take, finalize, first } 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';
|
|
@@ -6554,15 +6554,15 @@ NpsService = __decorate([
|
|
|
6554
6554
|
var WebsocketService_1;
|
|
6555
6555
|
let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
6556
6556
|
constructor() {
|
|
6557
|
-
/** @private */
|
|
6558
|
-
this.focused = true;
|
|
6559
6557
|
/** @private */
|
|
6560
6558
|
this.wasConnected = false;
|
|
6561
6559
|
/** @private */
|
|
6562
|
-
this.
|
|
6560
|
+
this.isConnected = false;
|
|
6563
6561
|
/** @private */
|
|
6564
6562
|
this.isConnecting = false;
|
|
6565
6563
|
/** @private */
|
|
6564
|
+
this.isReconnecting = false;
|
|
6565
|
+
/** @private */
|
|
6566
6566
|
this.primitiveManagers = new Map();
|
|
6567
6567
|
/** @private */
|
|
6568
6568
|
this.connect$ = new Subject();
|
|
@@ -6572,21 +6572,18 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6572
6572
|
this.reconnect$ = new Subject();
|
|
6573
6573
|
/** @private */
|
|
6574
6574
|
this.error$ = new Subject();
|
|
6575
|
-
|
|
6576
|
-
window.onblur = this.onBlur;
|
|
6575
|
+
this.subscribe$ = new Subject();
|
|
6577
6576
|
this.connect();
|
|
6578
6577
|
}
|
|
6579
6578
|
/**
|
|
6580
|
-
* Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida.
|
|
6581
|
-
* @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida.
|
|
6579
|
+
* Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida pela primeira vez.
|
|
6580
|
+
* @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida pela primeira vez.
|
|
6582
6581
|
*/
|
|
6583
6582
|
onConnect() {
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
}, 0);
|
|
6589
|
-
return this.connect$.pipe(first());
|
|
6583
|
+
if (this.isConnected || this.wasConnected) {
|
|
6584
|
+
return of(undefined).pipe(take(1));
|
|
6585
|
+
}
|
|
6586
|
+
return this.connect$.asObservable().pipe(take(1));
|
|
6590
6587
|
}
|
|
6591
6588
|
/**
|
|
6592
6589
|
* Observable responsável por emitir uma notificação quando a conexão é desconectada.
|
|
@@ -6602,6 +6599,16 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6602
6599
|
onReconnect() {
|
|
6603
6600
|
return this.reconnect$.asObservable();
|
|
6604
6601
|
}
|
|
6602
|
+
/**
|
|
6603
|
+
* Observable responsável por emitir uma notificação após o subscribe do evento pela primeira vez.
|
|
6604
|
+
* @return Um `Observable<void>` que emite uma notificação após o subscribe do evento pela primeira vez.
|
|
6605
|
+
*/
|
|
6606
|
+
onSubscribe({ domain, service, primitive }) {
|
|
6607
|
+
const key = this.getPrimitiveManagerKey(domain, service, primitive);
|
|
6608
|
+
return this.onConnect().pipe(switchMap(() => this.primitiveManagers.has(key) && this.primitiveManagers.get(key).isSubscribed
|
|
6609
|
+
? of(void 0).pipe(take(1))
|
|
6610
|
+
: this.subscribe$.pipe(filter(primitiveManager => this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive) === key), take(1), (map(() => void 0)))));
|
|
6611
|
+
}
|
|
6605
6612
|
/**
|
|
6606
6613
|
* Observable responsável por emitir uma notificação quando ocorre algum erro.
|
|
6607
6614
|
* @return Um `Observable<FrameImpl>` que emite uma notificação quando ocorre algum erro.
|
|
@@ -6621,28 +6628,29 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6621
6628
|
const { domain, service, primitive } = options;
|
|
6622
6629
|
const key = this.getPrimitiveManagerKey(domain, service, primitive);
|
|
6623
6630
|
if (this.primitiveManagers.has(key)) {
|
|
6624
|
-
return this.primitiveManagers.get(key).
|
|
6631
|
+
return this.primitiveManagers.get(key).event$.asObservable();
|
|
6625
6632
|
}
|
|
6626
6633
|
const primitiveManager = {
|
|
6627
6634
|
domain: domain,
|
|
6628
6635
|
service: service,
|
|
6629
6636
|
primitive: primitive,
|
|
6630
6637
|
stompSubscriptions: [],
|
|
6631
|
-
|
|
6638
|
+
event$: new Subject(),
|
|
6639
|
+
isSubscribed: false,
|
|
6632
6640
|
};
|
|
6633
6641
|
this.primitiveManagers.set(key, primitiveManager);
|
|
6634
|
-
if (this.isConnected
|
|
6642
|
+
if (this.isConnected) {
|
|
6635
6643
|
this.createStompSubscriptions(primitiveManager);
|
|
6636
|
-
return primitiveManager.
|
|
6644
|
+
return primitiveManager.event$.asObservable().pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitiveManager)));
|
|
6637
6645
|
}
|
|
6638
6646
|
else {
|
|
6639
|
-
if (!this.isConnecting) {
|
|
6647
|
+
if (!this.isReconnecting && !this.isConnecting) {
|
|
6640
6648
|
this.connect();
|
|
6641
6649
|
}
|
|
6642
6650
|
this.connect$.pipe(first()).subscribe(() => {
|
|
6643
6651
|
this.createStompSubscriptions(primitiveManager);
|
|
6644
6652
|
});
|
|
6645
|
-
return primitiveManager.
|
|
6653
|
+
return primitiveManager.event$.asObservable().pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitiveManager)));
|
|
6646
6654
|
}
|
|
6647
6655
|
}
|
|
6648
6656
|
/** @private */
|
|
@@ -6652,17 +6660,20 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6652
6660
|
const withoutTokenUrl = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
|
|
6653
6661
|
const stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
|
|
6654
6662
|
primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
|
|
6663
|
+
primitiveManager.isSubscribed = true;
|
|
6664
|
+
this.subscribe$.next(primitiveManager);
|
|
6655
6665
|
}
|
|
6656
6666
|
/** @private */
|
|
6657
6667
|
connect() {
|
|
6658
6668
|
this.createStompClient();
|
|
6659
6669
|
this.isConnecting = true;
|
|
6660
|
-
this._stompClient.activate();
|
|
6661
6670
|
this._stompClient.connect({}, () => {
|
|
6662
6671
|
this.isConnecting = false;
|
|
6663
|
-
this.
|
|
6672
|
+
this.isReconnecting = false;
|
|
6673
|
+
this.isConnected = true;
|
|
6664
6674
|
if (this.wasConnected) {
|
|
6665
6675
|
this.reconnectPrimitives();
|
|
6676
|
+
this.connect$.next();
|
|
6666
6677
|
this.reconnect$.next();
|
|
6667
6678
|
}
|
|
6668
6679
|
else {
|
|
@@ -6670,19 +6681,14 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6670
6681
|
this.connect$.next();
|
|
6671
6682
|
}
|
|
6672
6683
|
}, (error) => {
|
|
6673
|
-
this.
|
|
6684
|
+
this.isConnected = false;
|
|
6674
6685
|
this.error$.next(error);
|
|
6675
|
-
this.
|
|
6686
|
+
this.isReconnecting = true;
|
|
6687
|
+
timer(WebsocketService_1.RECONNECT_INTERVAL)
|
|
6688
|
+
.pipe(switchMap(() => iif(() => document.hidden, fromEvent(document, "visibilitychange").pipe(first()), EMPTY)))
|
|
6689
|
+
.subscribe({ complete: () => this.connect() });
|
|
6676
6690
|
});
|
|
6677
6691
|
}
|
|
6678
|
-
/** @private */
|
|
6679
|
-
onFocus() {
|
|
6680
|
-
this.focused = true;
|
|
6681
|
-
}
|
|
6682
|
-
/** @private */
|
|
6683
|
-
onBlur() {
|
|
6684
|
-
this.focused = false;
|
|
6685
|
-
}
|
|
6686
6692
|
disconnect() {
|
|
6687
6693
|
const observersCount = this.getObserversCount();
|
|
6688
6694
|
if (observersCount > 0)
|
|
@@ -6693,25 +6699,17 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6693
6699
|
}
|
|
6694
6700
|
}
|
|
6695
6701
|
for (const primitiveManager of this.primitiveManagers.values()) {
|
|
6696
|
-
primitiveManager.
|
|
6702
|
+
primitiveManager.event$.complete();
|
|
6697
6703
|
}
|
|
6698
6704
|
this.primitiveManagers.clear();
|
|
6699
6705
|
this._stompClient.disconnect();
|
|
6700
6706
|
this._stompClient.deactivate();
|
|
6701
|
-
this.
|
|
6707
|
+
this.isConnected = false;
|
|
6702
6708
|
this.isConnecting = false;
|
|
6703
6709
|
this.wasConnected = false;
|
|
6704
6710
|
this.disconnect$.next();
|
|
6705
6711
|
}
|
|
6706
6712
|
/** @private */
|
|
6707
|
-
isConnected() {
|
|
6708
|
-
return this.connected;
|
|
6709
|
-
}
|
|
6710
|
-
/** @private */
|
|
6711
|
-
setConnected(connected) {
|
|
6712
|
-
this.connected = connected;
|
|
6713
|
-
}
|
|
6714
|
-
/** @private */
|
|
6715
6713
|
getSubscriptionUrlWithToken(domain, service, primitive) {
|
|
6716
6714
|
const tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
|
|
6717
6715
|
const token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
|
|
@@ -6726,37 +6724,18 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6726
6724
|
createStompSubscription(destination, primitiveManager) {
|
|
6727
6725
|
return this._stompClient.subscribe(destination, (message) => {
|
|
6728
6726
|
const event = JSON.parse(message.body || "{}");
|
|
6729
|
-
primitiveManager.
|
|
6727
|
+
primitiveManager.event$.next(event);
|
|
6730
6728
|
});
|
|
6731
6729
|
}
|
|
6732
6730
|
/** @private */
|
|
6733
6731
|
createStompClient() {
|
|
6734
6732
|
const ws = new SockJS(`${WebsocketService_1.WEBSOCKET_URL}subscription`, null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
|
|
6735
6733
|
this._stompClient = Stomp.over(ws);
|
|
6736
|
-
|
|
6737
|
-
this._stompClient.debug = () => { }; // Para remover os logs.
|
|
6738
|
-
}
|
|
6739
|
-
/** @private */
|
|
6740
|
-
reconnect() {
|
|
6741
|
-
if (this.connected)
|
|
6742
|
-
this._stompClient.disconnect();
|
|
6743
|
-
setTimeout(() => {
|
|
6744
|
-
if (this.getObserversCount() === 0)
|
|
6745
|
-
return;
|
|
6746
|
-
if (this.focused) {
|
|
6747
|
-
this.connect();
|
|
6748
|
-
}
|
|
6749
|
-
else {
|
|
6750
|
-
this.reconnect();
|
|
6751
|
-
}
|
|
6752
|
-
}, WebsocketService_1.RECONNECT_TIMER);
|
|
6734
|
+
this._stompClient.debug = () => null;
|
|
6753
6735
|
}
|
|
6754
6736
|
/** @private */
|
|
6755
6737
|
reconnectPrimitives() {
|
|
6756
6738
|
for (const primitiveManager of this.primitiveManagers.values()) {
|
|
6757
|
-
for (const stompSubscription of primitiveManager.stompSubscriptions) {
|
|
6758
|
-
stompSubscription.unsubscribe();
|
|
6759
|
-
}
|
|
6760
6739
|
this.createStompSubscriptions(primitiveManager);
|
|
6761
6740
|
}
|
|
6762
6741
|
}
|
|
@@ -6764,16 +6743,17 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6764
6743
|
getObserversCount() {
|
|
6765
6744
|
let observersCount = 0;
|
|
6766
6745
|
for (const primitiveManager of this.primitiveManagers.values()) {
|
|
6767
|
-
observersCount += primitiveManager.
|
|
6746
|
+
observersCount += primitiveManager.event$.observers.length;
|
|
6768
6747
|
}
|
|
6769
6748
|
return observersCount;
|
|
6770
6749
|
}
|
|
6771
6750
|
/** @private */
|
|
6772
6751
|
disconnectPrimitiveOnFinalize(primitiveManager) {
|
|
6773
6752
|
// @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
|
|
6774
|
-
const hasObservers = !(primitiveManager.
|
|
6753
|
+
const hasObservers = !(primitiveManager.event$.observers.length === 1);
|
|
6775
6754
|
if (hasObservers)
|
|
6776
6755
|
return;
|
|
6756
|
+
primitiveManager.event$.complete();
|
|
6777
6757
|
for (const stompSubscription of primitiveManager.stompSubscriptions) {
|
|
6778
6758
|
stompSubscription.unsubscribe();
|
|
6779
6759
|
}
|
|
@@ -6787,7 +6767,7 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
|
|
|
6787
6767
|
}
|
|
6788
6768
|
};
|
|
6789
6769
|
/** @private */
|
|
6790
|
-
WebsocketService.
|
|
6770
|
+
WebsocketService.RECONNECT_INTERVAL = 3000;
|
|
6791
6771
|
/** @private */
|
|
6792
6772
|
WebsocketService.CONNECTION_TIMEOUT = 15000;
|
|
6793
6773
|
/** @private */
|