@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
 
@@ -7206,6 +7206,47 @@ var NpsService = /** @class */ (function () {
7206
7206
  return NpsService;
7207
7207
  }());
7208
7208
 
7209
+ var AsyncLock = /** @class */ (function () {
7210
+ function AsyncLock() {
7211
+ this.queue = [];
7212
+ this.acquired = false;
7213
+ }
7214
+ AsyncLock.prototype.acquire = function () {
7215
+ return __awaiter(this, void 0, void 0, function () {
7216
+ var _this = this;
7217
+ return __generator(this, function (_a) {
7218
+ if (!this.acquired) {
7219
+ this.acquired = true;
7220
+ return [2 /*return*/, Promise.resolve()];
7221
+ }
7222
+ else {
7223
+ return [2 /*return*/, new Promise(function (resolve, _) {
7224
+ _this.queue.push(resolve);
7225
+ })];
7226
+ }
7227
+ return [2 /*return*/];
7228
+ });
7229
+ });
7230
+ };
7231
+ AsyncLock.prototype.release = function () {
7232
+ return __awaiter(this, void 0, void 0, function () {
7233
+ var continuation;
7234
+ return __generator(this, function (_a) {
7235
+ if (this.queue.length === 0 && this.acquired) {
7236
+ this.acquired = false;
7237
+ return [2 /*return*/, Promise.resolve()];
7238
+ }
7239
+ continuation = this.queue.shift();
7240
+ return [2 /*return*/, new Promise(function (res) {
7241
+ continuation();
7242
+ res();
7243
+ })];
7244
+ });
7245
+ });
7246
+ };
7247
+ return AsyncLock;
7248
+ }());
7249
+
7209
7250
  var UserInformationService = /** @class */ (function () {
7210
7251
  function UserInformationService() {
7211
7252
  }
@@ -7222,7 +7263,7 @@ var UserInformationService = /** @class */ (function () {
7222
7263
  };
7223
7264
  UserInformationService.prototype.getWebSocketUrl = function () {
7224
7265
  var baseUrl = get(UserInformationService_1.BASE_URL_COOKIE_KEY);
7225
- if (!baseUrl.endsWith('/')) {
7266
+ if (baseUrl && !baseUrl.endsWith('/')) {
7226
7267
  baseUrl += '/';
7227
7268
  }
7228
7269
  return baseUrl + 'websocket';
@@ -7286,7 +7327,7 @@ var PrimitiveManager = /** @class */ (function () {
7286
7327
  };
7287
7328
  PrimitiveManager.prototype.hasObservers = function () {
7288
7329
  // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
7289
- return this.event$.observers.length > 1;
7330
+ return this.event$.observers.length !== 1;
7290
7331
  };
7291
7332
  PrimitiveManager.prototype.getObserversCount = function () {
7292
7333
  return this.event$.observers.length;
@@ -7305,6 +7346,7 @@ var WebsocketService = /** @class */ (function () {
7305
7346
  this.error$ = new Subject();
7306
7347
  this.subscribed$ = new Subject();
7307
7348
  this.primitiveManagers = new Map();
7349
+ this.connectionLock = new AsyncLock();
7308
7350
  this.debugEnable = false;
7309
7351
  this.lostConnection = false;
7310
7352
  }
@@ -7318,29 +7360,48 @@ var WebsocketService = /** @class */ (function () {
7318
7360
  * Manually starts the connection
7319
7361
  */
7320
7362
  WebsocketService.prototype.connect = function () {
7321
- var _this = this;
7322
- if (this.isConnected() || this.isConnecting()) {
7323
- return;
7324
- }
7325
- this.lostConnection = false;
7326
- var stompConfig = {
7327
- webSocketFactory: function () {
7328
- return new SockJS(_this.getSubscriptionUrl(), null, {
7329
- timeout: CONNECTION_TIMEOUT_MILLISECONDS
7330
- });
7331
- },
7332
- connectionTimeout: CONNECTION_TIMEOUT_MILLISECONDS,
7333
- reconnectDelay: RECONNECT_INTERVAL_MILLISECONDS,
7334
- debug: this.debug.bind(this),
7335
- onConnect: this.handleOnConnected.bind(this),
7336
- onDisconnect: this.handleOnDisconnect.bind(this),
7337
- onWebSocketClose: this.handleOnWebSocketClose.bind(this),
7338
- onStompError: this.handleOnStompError.bind(this),
7339
- onWebSocketError: this.handleOnWebSocketError.bind(this)
7340
- };
7341
- this.debug('Connecting the Webscoket');
7342
- this.stompClient = new Client(stompConfig);
7343
- this.stompClient.activate();
7363
+ return __awaiter(this, void 0, void 0, function () {
7364
+ var stompConfig;
7365
+ var _this = this;
7366
+ return __generator(this, function (_a) {
7367
+ switch (_a.label) {
7368
+ case 0: return [4 /*yield*/, this.connectionLock.acquire()];
7369
+ case 1:
7370
+ _a.sent();
7371
+ _a.label = 2;
7372
+ case 2:
7373
+ _a.trys.push([2, , 3, 5]);
7374
+ if (this.isConnected() || this.isConnecting()) {
7375
+ return [2 /*return*/];
7376
+ }
7377
+ this.lostConnection = false;
7378
+ stompConfig = {
7379
+ webSocketFactory: function () {
7380
+ return new SockJS(_this.getSubscriptionUrl(), null, {
7381
+ timeout: CONNECTION_TIMEOUT_MILLISECONDS
7382
+ });
7383
+ },
7384
+ connectionTimeout: CONNECTION_TIMEOUT_MILLISECONDS,
7385
+ reconnectDelay: RECONNECT_INTERVAL_MILLISECONDS,
7386
+ debug: this.debug.bind(this),
7387
+ onConnect: this.handleOnConnected.bind(this),
7388
+ onDisconnect: this.handleOnDisconnect.bind(this),
7389
+ onWebSocketClose: this.handleOnWebSocketClose.bind(this),
7390
+ onStompError: this.handleOnStompError.bind(this),
7391
+ onWebSocketError: this.handleOnWebSocketError.bind(this)
7392
+ };
7393
+ this.debug('Connecting the Webscoket');
7394
+ this.stompClient = new Client(stompConfig);
7395
+ this.stompClient.activate();
7396
+ return [3 /*break*/, 5];
7397
+ case 3: return [4 /*yield*/, this.connectionLock.release()];
7398
+ case 4:
7399
+ _a.sent();
7400
+ return [7 /*endfinally*/];
7401
+ case 5: return [2 /*return*/];
7402
+ }
7403
+ });
7404
+ });
7344
7405
  };
7345
7406
  /**
7346
7407
  * Manually disconnect the websocket. The reconnect loop will be stopped.
@@ -7352,6 +7413,15 @@ var WebsocketService = /** @class */ (function () {
7352
7413
  return __generator(this, function (_d) {
7353
7414
  switch (_d.label) {
7354
7415
  case 0:
7416
+ if (!this.isConnected()) {
7417
+ return [2 /*return*/];
7418
+ }
7419
+ return [4 /*yield*/, this.connectionLock.acquire()];
7420
+ case 1:
7421
+ _d.sent();
7422
+ _d.label = 2;
7423
+ case 2:
7424
+ _d.trys.push([2, , 5, 7]);
7355
7425
  try {
7356
7426
  for (_a = __values(this.primitiveManagers.values()), _b = _a.next(); !_b.done; _b = _a.next()) {
7357
7427
  primitiveManager = _b.value;
@@ -7366,15 +7436,18 @@ var WebsocketService = /** @class */ (function () {
7366
7436
  finally { if (e_1) throw e_1.error; }
7367
7437
  }
7368
7438
  this.primitiveManagers.clear();
7369
- if (!this.stompClient) return [3 /*break*/, 2];
7439
+ this.connected$.next(false);
7440
+ if (!this.stompClient) return [3 /*break*/, 4];
7370
7441
  return [4 /*yield*/, this.stompClient.deactivate()];
7371
- case 1:
7442
+ case 3:
7372
7443
  _d.sent();
7373
- this.stompClient = null;
7374
- _d.label = 2;
7375
- case 2:
7376
- this.connected$.next(false);
7377
- return [2 /*return*/];
7444
+ _d.label = 4;
7445
+ case 4: return [3 /*break*/, 7];
7446
+ case 5: return [4 /*yield*/, this.connectionLock.release()];
7447
+ case 6:
7448
+ _d.sent();
7449
+ return [7 /*endfinally*/];
7450
+ case 7: return [2 /*return*/];
7378
7451
  }
7379
7452
  });
7380
7453
  });
@@ -7448,11 +7521,12 @@ var WebsocketService = /** @class */ (function () {
7448
7521
  }
7449
7522
  var primitiveManager = new PrimitiveManager(domain, service, primitive);
7450
7523
  this.primitiveManagers.set(key, primitiveManager);
7451
- this.connect();
7452
- this.onConnect()
7453
- .pipe(take(1))
7454
- .subscribe(function () {
7455
- _this.createStompSubscriptions(primitiveManager);
7524
+ this.connect().then(function () {
7525
+ _this.onConnect()
7526
+ .pipe(take(1))
7527
+ .subscribe(function () {
7528
+ _this.createStompSubscriptions(primitiveManager);
7529
+ });
7456
7530
  });
7457
7531
  return primitiveManager
7458
7532
  .getEventObservable()
@@ -7469,7 +7543,6 @@ var WebsocketService = /** @class */ (function () {
7469
7543
  var _this = this;
7470
7544
  var domain = options.domain, service = options.service, primitive = options.primitive;
7471
7545
  var key = this.buildPrimitiveManagerKey(domain, service, primitive);
7472
- this.connect();
7473
7546
  return this.onConnect().pipe(take(1), switchMap(function () {
7474
7547
  if (_this.primitiveManagers.has(key)) {
7475
7548
  return _this.primitiveManagers
@@ -7495,26 +7568,36 @@ var WebsocketService = /** @class */ (function () {
7495
7568
  WebsocketService.prototype.info = function (message) {
7496
7569
  console.info('WS info: ' + message);
7497
7570
  };
7498
- WebsocketService.prototype.handleOnConnected = function (data) {
7499
- this.debug('Webscoket connected', data);
7571
+ WebsocketService.prototype.handleOnConnected = function () {
7572
+ this.info('Webscoket connected');
7500
7573
  this.connected$.next(true);
7501
7574
  if (this.lostConnection) {
7502
7575
  this.info('Webscoket reconnected, recriating subscriptions');
7503
7576
  this.handleReconnection();
7504
7577
  }
7505
7578
  };
7506
- WebsocketService.prototype.handleOnDisconnect = function (data) {
7507
- this.debug('Webscoket disconnected', data);
7579
+ WebsocketService.prototype.handleOnDisconnect = function () {
7580
+ this.info('Webscoket disconnected');
7581
+ this.connected$.next(false);
7508
7582
  this.disconnected$.next();
7509
7583
  };
7510
7584
  WebsocketService.prototype.handleOnWebSocketClose = function (data) {
7585
+ if (data.reason && data.reason.toLowerCase().indexOf("go away") !== -1) {
7586
+ this.lostConnection = true;
7587
+ this.handleError('AuthenticationError', new FrameImpl({
7588
+ command: data.type,
7589
+ headers: {
7590
+ message: data.reason
7591
+ }
7592
+ }));
7593
+ return;
7594
+ }
7511
7595
  if (data.wasClean) {
7512
7596
  return;
7513
7597
  }
7514
7598
  this.lostConnection = true;
7515
7599
  };
7516
7600
  WebsocketService.prototype.handleOnStompError = function (data) {
7517
- debugger;
7518
7601
  this.handleError('StompError', data);
7519
7602
  if (this.isAuthenticationError(data)) {
7520
7603
  this.info('Authentication error, recriating subscriptions');
@@ -7570,19 +7653,40 @@ var WebsocketService = /** @class */ (function () {
7570
7653
  return domain + "/" + service + "/" + primitive;
7571
7654
  };
7572
7655
  WebsocketService.prototype.unsubscribePrimitiveOnFinalize = function (primitiveManager) {
7573
- if (primitiveManager.hasObservers()) {
7574
- return;
7575
- }
7576
- primitiveManager.unsubscribe();
7577
- var key = this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7578
- this.primitiveManagers.delete(key);
7579
- this.disconnectIfNoMoreObservables();
7656
+ return __awaiter(this, void 0, void 0, function () {
7657
+ var key;
7658
+ return __generator(this, function (_a) {
7659
+ switch (_a.label) {
7660
+ case 0:
7661
+ if (primitiveManager.hasObservers()) {
7662
+ return [2 /*return*/];
7663
+ }
7664
+ primitiveManager.unsubscribe();
7665
+ key = this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7666
+ this.primitiveManagers.delete(key);
7667
+ return [4 /*yield*/, this.disconnectIfNoMoreObservables()];
7668
+ case 1:
7669
+ _a.sent();
7670
+ return [2 /*return*/];
7671
+ }
7672
+ });
7673
+ });
7580
7674
  };
7581
7675
  WebsocketService.prototype.disconnectIfNoMoreObservables = function () {
7582
- if (this.getObserversCount() === 0) {
7583
- this.debug('Manually disconnecting because there are no more observers');
7584
- this.disconnect();
7585
- }
7676
+ return __awaiter(this, void 0, void 0, function () {
7677
+ return __generator(this, function (_a) {
7678
+ switch (_a.label) {
7679
+ case 0:
7680
+ if (!(this.getObserversCount() === 0)) return [3 /*break*/, 2];
7681
+ this.debug('Manually disconnecting because there are no more observers');
7682
+ return [4 /*yield*/, this.disconnect()];
7683
+ case 1:
7684
+ _a.sent();
7685
+ _a.label = 2;
7686
+ case 2: return [2 /*return*/];
7687
+ }
7688
+ });
7689
+ });
7586
7690
  };
7587
7691
  WebsocketService.prototype.getObserversCount = function () {
7588
7692
  var observersCount = 0;
@@ -7773,5 +7877,5 @@ var ModulesEnum;
7773
7877
  * Generated bundle index. Do not edit.
7774
7878
  */
7775
7879
 
7776
- 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 };
7880
+ 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 };
7777
7881
  //# sourceMappingURL=senior-gestao-empresarial-angular-components.js.map