@senior-gestao-empresarial/angular-components 6.12.0-bea9aaec-b4b5-4e5b-b8eb-155b7aa8d5aa → 6.12.0-cb91124b-ecdd-4d38-8aca-770d208b1882

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.
Files changed (29) hide show
  1. package/bundles/senior-gestao-empresarial-angular-components.umd.js +159 -54
  2. package/bundles/senior-gestao-empresarial-angular-components.umd.js.map +1 -1
  3. package/bundles/senior-gestao-empresarial-angular-components.umd.min.js +2 -2
  4. package/bundles/senior-gestao-empresarial-angular-components.umd.min.js.map +1 -1
  5. package/components/utils/async-lock.d.ts +6 -0
  6. package/components/websocket/index.d.ts +2 -0
  7. package/components/websocket/models/index.d.ts +1 -0
  8. package/components/websocket/protocols/index.d.ts +2 -0
  9. package/components/websocket/websocket.service.d.ts +3 -3
  10. package/esm2015/components/utils/async-lock.js +34 -0
  11. package/esm2015/components/websocket/index.js +2 -1
  12. package/esm2015/components/websocket/models/index.js +2 -0
  13. package/esm2015/components/websocket/models/primitive-manager.js +2 -2
  14. package/esm2015/components/websocket/protocols/index.js +1 -0
  15. package/esm2015/components/websocket/user-information.service.js +2 -2
  16. package/esm2015/components/websocket/websocket.service.js +86 -54
  17. package/esm5/components/utils/async-lock.js +43 -0
  18. package/esm5/components/websocket/index.js +2 -1
  19. package/esm5/components/websocket/models/index.js +2 -0
  20. package/esm5/components/websocket/models/primitive-manager.js +2 -2
  21. package/esm5/components/websocket/protocols/index.js +1 -0
  22. package/esm5/components/websocket/user-information.service.js +2 -2
  23. package/esm5/components/websocket/websocket.service.js +119 -55
  24. package/fesm2015/senior-gestao-empresarial-angular-components.js +119 -55
  25. package/fesm2015/senior-gestao-empresarial-angular-components.js.map +1 -1
  26. package/fesm5/senior-gestao-empresarial-angular-components.js +160 -56
  27. package/fesm5/senior-gestao-empresarial-angular-components.js.map +1 -1
  28. package/package.json +1 -1
  29. package/senior-gestao-empresarial-angular-components.metadata.json +1 -1
@@ -13,7 +13,7 @@ import { TranslateService } from '@ngx-translate/core';
13
13
  import { HttpInterceptorModule } from '@seniorsistemas/platform-components';
14
14
  import { user } from '@seniorsistemas/senior-platform-data';
15
15
  import { FormControl, FormGroup } from '@angular/forms';
16
- import { Client } from '@stomp/stompjs';
16
+ import { Client, FrameImpl } from '@stomp/stompjs';
17
17
  import * as SockJS from 'sockjs-client';
18
18
  import { get } from 'js-cookie';
19
19
 
@@ -6768,6 +6768,39 @@ NpsService = __decorate([
6768
6768
  })
6769
6769
  ], NpsService);
6770
6770
 
6771
+ class AsyncLock {
6772
+ constructor() {
6773
+ this.queue = [];
6774
+ this.acquired = false;
6775
+ }
6776
+ acquire() {
6777
+ return __awaiter(this, void 0, void 0, function* () {
6778
+ if (!this.acquired) {
6779
+ this.acquired = true;
6780
+ return Promise.resolve();
6781
+ }
6782
+ else {
6783
+ return new Promise((resolve, _) => {
6784
+ this.queue.push(resolve);
6785
+ });
6786
+ }
6787
+ });
6788
+ }
6789
+ release() {
6790
+ return __awaiter(this, void 0, void 0, function* () {
6791
+ if (this.queue.length === 0 && this.acquired) {
6792
+ this.acquired = false;
6793
+ return Promise.resolve();
6794
+ }
6795
+ const continuation = this.queue.shift();
6796
+ return new Promise((res) => {
6797
+ continuation();
6798
+ res();
6799
+ });
6800
+ });
6801
+ }
6802
+ }
6803
+
6771
6804
  var UserInformationService_1;
6772
6805
  let UserInformationService = UserInformationService_1 = class UserInformationService {
6773
6806
  getAuthToken() {
@@ -6782,7 +6815,7 @@ let UserInformationService = UserInformationService_1 = class UserInformationSer
6782
6815
  }
6783
6816
  getWebSocketUrl() {
6784
6817
  let baseUrl = get(UserInformationService_1.BASE_URL_COOKIE_KEY);
6785
- if (!baseUrl.endsWith('/')) {
6818
+ if (baseUrl && !baseUrl.endsWith('/')) {
6786
6819
  baseUrl += '/';
6787
6820
  }
6788
6821
  return baseUrl + 'websocket';
@@ -6828,7 +6861,7 @@ class PrimitiveManager {
6828
6861
  }
6829
6862
  hasObservers() {
6830
6863
  // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
6831
- return this.event$.observers.length > 1;
6864
+ return this.event$.observers.length !== 1;
6832
6865
  }
6833
6866
  getObserversCount() {
6834
6867
  return this.event$.observers.length;
@@ -6846,6 +6879,7 @@ let WebsocketService = class WebsocketService {
6846
6879
  this.error$ = new Subject();
6847
6880
  this.subscribed$ = new Subject();
6848
6881
  this.primitiveManagers = new Map();
6882
+ this.connectionLock = new AsyncLock();
6849
6883
  this.debugEnable = false;
6850
6884
  this.lostConnection = false;
6851
6885
  }
@@ -6859,43 +6893,59 @@ let WebsocketService = class WebsocketService {
6859
6893
  * Manually starts the connection
6860
6894
  */
6861
6895
  connect() {
6862
- if (this.isConnected() || this.isConnecting()) {
6863
- return;
6864
- }
6865
- this.lostConnection = false;
6866
- const stompConfig = {
6867
- webSocketFactory: () => {
6868
- return new SockJS(this.getSubscriptionUrl(), null, {
6869
- timeout: CONNECTION_TIMEOUT_MILLISECONDS
6870
- });
6871
- },
6872
- connectionTimeout: CONNECTION_TIMEOUT_MILLISECONDS,
6873
- reconnectDelay: RECONNECT_INTERVAL_MILLISECONDS,
6874
- debug: this.debug.bind(this),
6875
- onConnect: this.handleOnConnected.bind(this),
6876
- onDisconnect: this.handleOnDisconnect.bind(this),
6877
- onWebSocketClose: this.handleOnWebSocketClose.bind(this),
6878
- onStompError: this.handleOnStompError.bind(this),
6879
- onWebSocketError: this.handleOnWebSocketError.bind(this)
6880
- };
6881
- this.debug('Connecting the Webscoket');
6882
- this.stompClient = new Client(stompConfig);
6883
- this.stompClient.activate();
6896
+ return __awaiter(this, void 0, void 0, function* () {
6897
+ yield this.connectionLock.acquire();
6898
+ try {
6899
+ if (this.isConnected() || this.isConnecting()) {
6900
+ return;
6901
+ }
6902
+ this.lostConnection = false;
6903
+ const stompConfig = {
6904
+ webSocketFactory: () => {
6905
+ return new SockJS(this.getSubscriptionUrl(), null, {
6906
+ timeout: CONNECTION_TIMEOUT_MILLISECONDS
6907
+ });
6908
+ },
6909
+ connectionTimeout: CONNECTION_TIMEOUT_MILLISECONDS,
6910
+ reconnectDelay: RECONNECT_INTERVAL_MILLISECONDS,
6911
+ debug: this.debug.bind(this),
6912
+ onConnect: this.handleOnConnected.bind(this),
6913
+ onDisconnect: this.handleOnDisconnect.bind(this),
6914
+ onWebSocketClose: this.handleOnWebSocketClose.bind(this),
6915
+ onStompError: this.handleOnStompError.bind(this),
6916
+ onWebSocketError: this.handleOnWebSocketError.bind(this)
6917
+ };
6918
+ this.debug('Connecting the Webscoket');
6919
+ this.stompClient = new Client(stompConfig);
6920
+ this.stompClient.activate();
6921
+ }
6922
+ finally {
6923
+ yield this.connectionLock.release();
6924
+ }
6925
+ });
6884
6926
  }
6885
6927
  /**
6886
6928
  * Manually disconnect the websocket. The reconnect loop will be stopped.
6887
6929
  */
6888
6930
  disconnect() {
6889
6931
  return __awaiter(this, void 0, void 0, function* () {
6890
- for (const primitiveManager of this.primitiveManagers.values()) {
6891
- primitiveManager.unsubscribe();
6932
+ if (!this.isConnected()) {
6933
+ return;
6934
+ }
6935
+ yield this.connectionLock.acquire();
6936
+ try {
6937
+ for (const primitiveManager of this.primitiveManagers.values()) {
6938
+ primitiveManager.unsubscribe();
6939
+ }
6940
+ this.primitiveManagers.clear();
6941
+ this.connected$.next(false);
6942
+ if (this.stompClient) {
6943
+ yield this.stompClient.deactivate();
6944
+ }
6892
6945
  }
6893
- this.primitiveManagers.clear();
6894
- if (this.stompClient) {
6895
- yield this.stompClient.deactivate();
6896
- this.stompClient = null;
6946
+ finally {
6947
+ yield this.connectionLock.release();
6897
6948
  }
6898
- this.connected$.next(false);
6899
6949
  });
6900
6950
  }
6901
6951
  /**
@@ -6966,11 +7016,12 @@ let WebsocketService = class WebsocketService {
6966
7016
  }
6967
7017
  const primitiveManager = new PrimitiveManager(domain, service, primitive);
6968
7018
  this.primitiveManagers.set(key, primitiveManager);
6969
- this.connect();
6970
- this.onConnect()
6971
- .pipe(take(1))
6972
- .subscribe(() => {
6973
- this.createStompSubscriptions(primitiveManager);
7019
+ this.connect().then(() => {
7020
+ this.onConnect()
7021
+ .pipe(take(1))
7022
+ .subscribe(() => {
7023
+ this.createStompSubscriptions(primitiveManager);
7024
+ });
6974
7025
  });
6975
7026
  return primitiveManager
6976
7027
  .getEventObservable()
@@ -6986,7 +7037,6 @@ let WebsocketService = class WebsocketService {
6986
7037
  onSubscribe(options) {
6987
7038
  const { domain, service, primitive } = options;
6988
7039
  const key = this.buildPrimitiveManagerKey(domain, service, primitive);
6989
- this.connect();
6990
7040
  return this.onConnect().pipe(take(1), switchMap(() => {
6991
7041
  if (this.primitiveManagers.has(key)) {
6992
7042
  return this.primitiveManagers
@@ -7008,26 +7058,36 @@ let WebsocketService = class WebsocketService {
7008
7058
  info(message) {
7009
7059
  console.info('WS info: ' + message);
7010
7060
  }
7011
- handleOnConnected(data) {
7012
- this.debug('Webscoket connected', data);
7061
+ handleOnConnected() {
7062
+ this.info('Webscoket connected');
7013
7063
  this.connected$.next(true);
7014
7064
  if (this.lostConnection) {
7015
7065
  this.info('Webscoket reconnected, recriating subscriptions');
7016
7066
  this.handleReconnection();
7017
7067
  }
7018
7068
  }
7019
- handleOnDisconnect(data) {
7020
- this.debug('Webscoket disconnected', data);
7069
+ handleOnDisconnect() {
7070
+ this.info('Webscoket disconnected');
7071
+ this.connected$.next(false);
7021
7072
  this.disconnected$.next();
7022
7073
  }
7023
7074
  handleOnWebSocketClose(data) {
7075
+ if (data.reason && data.reason.toLowerCase().indexOf("go away") !== -1) {
7076
+ this.lostConnection = true;
7077
+ this.handleError('AuthenticationError', new FrameImpl({
7078
+ command: data.type,
7079
+ headers: {
7080
+ message: data.reason
7081
+ }
7082
+ }));
7083
+ return;
7084
+ }
7024
7085
  if (data.wasClean) {
7025
7086
  return;
7026
7087
  }
7027
7088
  this.lostConnection = true;
7028
7089
  }
7029
7090
  handleOnStompError(data) {
7030
- debugger;
7031
7091
  this.handleError('StompError', data);
7032
7092
  if (this.isAuthenticationError(data)) {
7033
7093
  this.info('Authentication error, recriating subscriptions');
@@ -7072,19 +7132,23 @@ let WebsocketService = class WebsocketService {
7072
7132
  return `${domain}/${service}/${primitive}`;
7073
7133
  }
7074
7134
  unsubscribePrimitiveOnFinalize(primitiveManager) {
7075
- if (primitiveManager.hasObservers()) {
7076
- return;
7077
- }
7078
- primitiveManager.unsubscribe();
7079
- const key = this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7080
- this.primitiveManagers.delete(key);
7081
- this.disconnectIfNoMoreObservables();
7135
+ return __awaiter(this, void 0, void 0, function* () {
7136
+ if (primitiveManager.hasObservers()) {
7137
+ return;
7138
+ }
7139
+ primitiveManager.unsubscribe();
7140
+ const key = this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7141
+ this.primitiveManagers.delete(key);
7142
+ yield this.disconnectIfNoMoreObservables();
7143
+ });
7082
7144
  }
7083
7145
  disconnectIfNoMoreObservables() {
7084
- if (this.getObserversCount() === 0) {
7085
- this.debug('Manually disconnecting because there are no more observers');
7086
- this.disconnect();
7087
- }
7146
+ return __awaiter(this, void 0, void 0, function* () {
7147
+ if (this.getObserversCount() === 0) {
7148
+ this.debug('Manually disconnecting because there are no more observers');
7149
+ yield this.disconnect();
7150
+ }
7151
+ });
7088
7152
  }
7089
7153
  getObserversCount() {
7090
7154
  let observersCount = 0;
@@ -7266,5 +7330,5 @@ var ModulesEnum;
7266
7330
  * Generated bundle index. Do not edit.
7267
7331
  */
7268
7332
 
7269
- export { AgreementLookup, BankLookup, BeneficioFiscalLookup, BreadcrumbComponent, BreadcrumbModule, Breakpoints, ContaInternaFilialLookup, CountryLookup, CplTriNotaSaidaE001EndLookup, CplTriNotaSaidaE001PesLookup, CplTriNotaSaidaE001TnsLookup, CplTriNotaSaidaE007UfsLookup, CplTriNotaSaidaE008RaiLookup, CplTriNotaSaidaE015MedLookup, CplTriNotaSaidaE020SnfLookup, CplTriNotaSaidaE024MsgLookup, CplTriNotaSaidaE028CpgLookup, CplTriNotaSaidaE032EdcLookup, CplTriNotaSaidaE051DisLookup, CplTriNotaSaidaE066FpgLookup, CplTriNotaSaidaE070EmpLookup, CplTriNotaSaidaE070FilLookup, CplTriNotaSaidaE075DerLookup, CplTriNotaSaidaE080SerLookup, CplTriNotaSaidaNaturezaReceitaPisCofinsLookup, CplTriNotaSaidaNcmLookup, CplTriNotaSaidaNfEntradaLookup, CplTriNotaSaidaNfSaidaLookup, CurrencyLookup, DocumentoLookup, E001EndLookup, E001PesLookup, E001TnsLookup, E001TnsSupEstLookup, E002TptLookup, E007UfsLookup, E008CepLookup, E008RaiLookup, E012FamLookup, E015MedLookup, E020SnfLookup, E021MotLookup, E023CrpLookup, E024MsgLookup, E027EqiLookup, E027StrLookup, E028CpgLookup, E030AgeLookup, E030BanLookup, E031MoeLookup, E032EdcLookup, E035OcrLookup, E036InsLookup, E039PorLookup, E043MpcLookup, E043PcmLookup, E044CcuFinRatDepLookup, E044CcuLookup, E045PlaLookup, E046HpdLookup, E047NtgLookup, E048FctLookup, E048SfcLookup, E051DisLookup, E066FpgLookup, E067FinLookup, E069GreLookup, E070EmpLookup, E070EntLookup, E070FilLookup, E073PesLookup, E073VeiLookup, E075DerLookup, E080SerLookup, E081TabLookup, E082TprLookup, E085PesLookup, E089DocLookup, E090HrpComGerLookup, E090PesLookup, E091PlfFinRatLookup, E095PesLookup, E099UsuComGerLookup, E099UsuSupCprLookup, E140InsLookup, E140NfsLookup, E200LotLookup, E200SerLookup, E205DepLookup, E210DxpE075DerLookup, E210DxpLookup, E301TcrLookup, E403FprLookup, E420IcpLookup, E420IpcLookup, E420OcpLookup, E501TcpLookup, E600CcoLookup, E640LotLookup, EntityPersonProductLookup, EnumLogicalOperator, EquipmentLookup, ErpLookups, ErpLookupsModule, ErpPolling, ExportUtils, FiltersStorageService, FormUtilsService, HTTP_STATUS_CODE, LigacaoItemFornecedorLookup, LookupValidationUtils, ModulesEnum, NcmLookup, NotaFiscalEntradaLookup, NpsService, ParametersLookup, ProdutoServicoLookup, QuantidadeDisponivelDemandaLookup, RequisicaoLookup, SegmentoLookup, TypeTaxesLookup, UnidadeMedidaLookup, UtilsModule, VerifyModulePermission, VerifyModulePermissions, WebsocketService, naturezaReceitaPisCofins, ɵ0, ErpLookupsService as ɵa, EnumAnaSin as ɵb, EnumNatCtb as ɵc, StorageService as ɵd, UserInformationService as ɵe, VerifyModulePermissionService as ɵf, VerifyModulePermissionsService as ɵg };
7333
+ export { AgreementLookup, BankLookup, BeneficioFiscalLookup, BreadcrumbComponent, BreadcrumbModule, Breakpoints, ContaInternaFilialLookup, CountryLookup, CplTriNotaSaidaE001EndLookup, CplTriNotaSaidaE001PesLookup, CplTriNotaSaidaE001TnsLookup, CplTriNotaSaidaE007UfsLookup, CplTriNotaSaidaE008RaiLookup, CplTriNotaSaidaE015MedLookup, CplTriNotaSaidaE020SnfLookup, CplTriNotaSaidaE024MsgLookup, CplTriNotaSaidaE028CpgLookup, CplTriNotaSaidaE032EdcLookup, CplTriNotaSaidaE051DisLookup, CplTriNotaSaidaE066FpgLookup, CplTriNotaSaidaE070EmpLookup, CplTriNotaSaidaE070FilLookup, CplTriNotaSaidaE075DerLookup, CplTriNotaSaidaE080SerLookup, CplTriNotaSaidaNaturezaReceitaPisCofinsLookup, CplTriNotaSaidaNcmLookup, CplTriNotaSaidaNfEntradaLookup, CplTriNotaSaidaNfSaidaLookup, CurrencyLookup, DocumentoLookup, E001EndLookup, E001PesLookup, E001TnsLookup, E001TnsSupEstLookup, E002TptLookup, E007UfsLookup, E008CepLookup, E008RaiLookup, E012FamLookup, E015MedLookup, E020SnfLookup, E021MotLookup, E023CrpLookup, E024MsgLookup, E027EqiLookup, E027StrLookup, E028CpgLookup, E030AgeLookup, E030BanLookup, E031MoeLookup, E032EdcLookup, E035OcrLookup, E036InsLookup, E039PorLookup, E043MpcLookup, E043PcmLookup, E044CcuFinRatDepLookup, E044CcuLookup, E045PlaLookup, E046HpdLookup, E047NtgLookup, E048FctLookup, E048SfcLookup, E051DisLookup, E066FpgLookup, E067FinLookup, E069GreLookup, E070EmpLookup, E070EntLookup, E070FilLookup, E073PesLookup, E073VeiLookup, E075DerLookup, E080SerLookup, E081TabLookup, E082TprLookup, E085PesLookup, E089DocLookup, E090HrpComGerLookup, E090PesLookup, E091PlfFinRatLookup, E095PesLookup, E099UsuComGerLookup, E099UsuSupCprLookup, E140InsLookup, E140NfsLookup, E200LotLookup, E200SerLookup, E205DepLookup, E210DxpE075DerLookup, E210DxpLookup, E301TcrLookup, E403FprLookup, E420IcpLookup, E420IpcLookup, E420OcpLookup, E501TcpLookup, E600CcoLookup, E640LotLookup, EntityPersonProductLookup, EnumLogicalOperator, EquipmentLookup, ErpLookups, ErpLookupsModule, ErpPolling, ExportUtils, FiltersStorageService, FormUtilsService, HTTP_STATUS_CODE, LigacaoItemFornecedorLookup, LookupValidationUtils, ModulesEnum, NcmLookup, NotaFiscalEntradaLookup, NpsService, ParametersLookup, PrimitiveManager, ProdutoServicoLookup, QuantidadeDisponivelDemandaLookup, RequisicaoLookup, SegmentoLookup, TypeTaxesLookup, UnidadeMedidaLookup, UtilsModule, VerifyModulePermission, VerifyModulePermissions, WebsocketService, naturezaReceitaPisCofins, ɵ0, ErpLookupsService as ɵa, EnumAnaSin as ɵb, EnumNatCtb as ɵc, StorageService as ɵd, UserInformationService as ɵe, VerifyModulePermissionService as ɵf, VerifyModulePermissionsService as ɵg };
7270
7334
  //# sourceMappingURL=senior-gestao-empresarial-angular-components.js.map