@senior-gestao-empresarial/angular-components 6.12.0-bea9aaec-b4b5-4e5b-b8eb-155b7aa8d5aa → 6.12.0-cdee7359-3bca-4813-b06f-c65cc860eea4

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 +150 -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 +76 -53
  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 +109 -54
  24. package/fesm2015/senior-gestao-empresarial-angular-components.js +109 -54
  25. package/fesm2015/senior-gestao-empresarial-angular-components.js.map +1 -1
  26. package/fesm5/senior-gestao-empresarial-angular-components.js +150 -55
  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
@@ -7412,6 +7412,47 @@
7412
7412
  return NpsService;
7413
7413
  }());
7414
7414
 
7415
+ var AsyncLock = /** @class */ (function () {
7416
+ function AsyncLock() {
7417
+ this.queue = [];
7418
+ this.acquired = false;
7419
+ }
7420
+ AsyncLock.prototype.acquire = function () {
7421
+ return __awaiter(this, void 0, void 0, function () {
7422
+ var _this = this;
7423
+ return __generator(this, function (_a) {
7424
+ if (!this.acquired) {
7425
+ this.acquired = true;
7426
+ return [2 /*return*/, Promise.resolve()];
7427
+ }
7428
+ else {
7429
+ return [2 /*return*/, new Promise(function (resolve, _) {
7430
+ _this.queue.push(resolve);
7431
+ })];
7432
+ }
7433
+ return [2 /*return*/];
7434
+ });
7435
+ });
7436
+ };
7437
+ AsyncLock.prototype.release = function () {
7438
+ return __awaiter(this, void 0, void 0, function () {
7439
+ var continuation;
7440
+ return __generator(this, function (_a) {
7441
+ if (this.queue.length === 0 && this.acquired) {
7442
+ this.acquired = false;
7443
+ return [2 /*return*/, Promise.resolve()];
7444
+ }
7445
+ continuation = this.queue.shift();
7446
+ return [2 /*return*/, new Promise(function (res) {
7447
+ continuation();
7448
+ res();
7449
+ })];
7450
+ });
7451
+ });
7452
+ };
7453
+ return AsyncLock;
7454
+ }());
7455
+
7415
7456
  var UserInformationService = /** @class */ (function () {
7416
7457
  function UserInformationService() {
7417
7458
  }
@@ -7428,7 +7469,7 @@
7428
7469
  };
7429
7470
  UserInformationService.prototype.getWebSocketUrl = function () {
7430
7471
  var baseUrl = jsCookie.get(UserInformationService_1.BASE_URL_COOKIE_KEY);
7431
- if (!baseUrl.endsWith('/')) {
7472
+ if (baseUrl && !baseUrl.endsWith('/')) {
7432
7473
  baseUrl += '/';
7433
7474
  }
7434
7475
  return baseUrl + 'websocket';
@@ -7492,7 +7533,7 @@
7492
7533
  };
7493
7534
  PrimitiveManager.prototype.hasObservers = function () {
7494
7535
  // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
7495
- return this.event$.observers.length > 1;
7536
+ return this.event$.observers.length !== 1;
7496
7537
  };
7497
7538
  PrimitiveManager.prototype.getObserversCount = function () {
7498
7539
  return this.event$.observers.length;
@@ -7511,6 +7552,7 @@
7511
7552
  this.error$ = new rxjs.Subject();
7512
7553
  this.subscribed$ = new rxjs.Subject();
7513
7554
  this.primitiveManagers = new Map();
7555
+ this.connectionLock = new AsyncLock();
7514
7556
  this.debugEnable = false;
7515
7557
  this.lostConnection = false;
7516
7558
  }
@@ -7524,29 +7566,48 @@
7524
7566
  * Manually starts the connection
7525
7567
  */
7526
7568
  WebsocketService.prototype.connect = function () {
7527
- var _this = this;
7528
- if (this.isConnected() || this.isConnecting()) {
7529
- return;
7530
- }
7531
- this.lostConnection = false;
7532
- var stompConfig = {
7533
- webSocketFactory: function () {
7534
- return new SockJS(_this.getSubscriptionUrl(), null, {
7535
- timeout: CONNECTION_TIMEOUT_MILLISECONDS
7536
- });
7537
- },
7538
- connectionTimeout: CONNECTION_TIMEOUT_MILLISECONDS,
7539
- reconnectDelay: RECONNECT_INTERVAL_MILLISECONDS,
7540
- debug: this.debug.bind(this),
7541
- onConnect: this.handleOnConnected.bind(this),
7542
- onDisconnect: this.handleOnDisconnect.bind(this),
7543
- onWebSocketClose: this.handleOnWebSocketClose.bind(this),
7544
- onStompError: this.handleOnStompError.bind(this),
7545
- onWebSocketError: this.handleOnWebSocketError.bind(this)
7546
- };
7547
- this.debug('Connecting the Webscoket');
7548
- this.stompClient = new stompjs.Client(stompConfig);
7549
- this.stompClient.activate();
7569
+ return __awaiter(this, void 0, void 0, function () {
7570
+ var stompConfig;
7571
+ var _this = this;
7572
+ return __generator(this, function (_a) {
7573
+ switch (_a.label) {
7574
+ case 0: return [4 /*yield*/, this.connectionLock.acquire()];
7575
+ case 1:
7576
+ _a.sent();
7577
+ _a.label = 2;
7578
+ case 2:
7579
+ _a.trys.push([2, , 3, 5]);
7580
+ if (this.isConnected() || this.isConnecting()) {
7581
+ return [2 /*return*/];
7582
+ }
7583
+ this.lostConnection = false;
7584
+ stompConfig = {
7585
+ webSocketFactory: function () {
7586
+ return new SockJS(_this.getSubscriptionUrl(), null, {
7587
+ timeout: CONNECTION_TIMEOUT_MILLISECONDS
7588
+ });
7589
+ },
7590
+ connectionTimeout: CONNECTION_TIMEOUT_MILLISECONDS,
7591
+ reconnectDelay: RECONNECT_INTERVAL_MILLISECONDS,
7592
+ debug: this.debug.bind(this),
7593
+ onConnect: this.handleOnConnected.bind(this),
7594
+ onDisconnect: this.handleOnDisconnect.bind(this),
7595
+ onWebSocketClose: this.handleOnWebSocketClose.bind(this),
7596
+ onStompError: this.handleOnStompError.bind(this),
7597
+ onWebSocketError: this.handleOnWebSocketError.bind(this)
7598
+ };
7599
+ this.debug('Connecting the Webscoket');
7600
+ this.stompClient = new stompjs.Client(stompConfig);
7601
+ this.stompClient.activate();
7602
+ return [3 /*break*/, 5];
7603
+ case 3: return [4 /*yield*/, this.connectionLock.release()];
7604
+ case 4:
7605
+ _a.sent();
7606
+ return [7 /*endfinally*/];
7607
+ case 5: return [2 /*return*/];
7608
+ }
7609
+ });
7610
+ });
7550
7611
  };
7551
7612
  /**
7552
7613
  * Manually disconnect the websocket. The reconnect loop will be stopped.
@@ -7558,6 +7619,15 @@
7558
7619
  return __generator(this, function (_d) {
7559
7620
  switch (_d.label) {
7560
7621
  case 0:
7622
+ if (!this.isConnected()) {
7623
+ return [2 /*return*/];
7624
+ }
7625
+ return [4 /*yield*/, this.connectionLock.acquire()];
7626
+ case 1:
7627
+ _d.sent();
7628
+ _d.label = 2;
7629
+ case 2:
7630
+ _d.trys.push([2, , 5, 7]);
7561
7631
  try {
7562
7632
  for (_a = __values(this.primitiveManagers.values()), _b = _a.next(); !_b.done; _b = _a.next()) {
7563
7633
  primitiveManager = _b.value;
@@ -7572,15 +7642,19 @@
7572
7642
  finally { if (e_1) throw e_1.error; }
7573
7643
  }
7574
7644
  this.primitiveManagers.clear();
7575
- if (!this.stompClient) return [3 /*break*/, 2];
7645
+ this.connected$.next(false);
7646
+ if (!this.stompClient) return [3 /*break*/, 4];
7647
+ this.stompClient.forceDisconnect();
7576
7648
  return [4 /*yield*/, this.stompClient.deactivate()];
7577
- case 1:
7649
+ case 3:
7578
7650
  _d.sent();
7579
- this.stompClient = null;
7580
- _d.label = 2;
7581
- case 2:
7582
- this.connected$.next(false);
7583
- return [2 /*return*/];
7651
+ _d.label = 4;
7652
+ case 4: return [3 /*break*/, 7];
7653
+ case 5: return [4 /*yield*/, this.connectionLock.release()];
7654
+ case 6:
7655
+ _d.sent();
7656
+ return [7 /*endfinally*/];
7657
+ case 7: return [2 /*return*/];
7584
7658
  }
7585
7659
  });
7586
7660
  });
@@ -7654,11 +7728,12 @@
7654
7728
  }
7655
7729
  var primitiveManager = new PrimitiveManager(domain, service, primitive);
7656
7730
  this.primitiveManagers.set(key, primitiveManager);
7657
- this.connect();
7658
- this.onConnect()
7659
- .pipe(operators.take(1))
7660
- .subscribe(function () {
7661
- _this.createStompSubscriptions(primitiveManager);
7731
+ this.connect().then(function () {
7732
+ _this.onConnect()
7733
+ .pipe(operators.take(1))
7734
+ .subscribe(function () {
7735
+ _this.createStompSubscriptions(primitiveManager);
7736
+ });
7662
7737
  });
7663
7738
  return primitiveManager
7664
7739
  .getEventObservable()
@@ -7675,7 +7750,6 @@
7675
7750
  var _this = this;
7676
7751
  var domain = options.domain, service = options.service, primitive = options.primitive;
7677
7752
  var key = this.buildPrimitiveManagerKey(domain, service, primitive);
7678
- this.connect();
7679
7753
  return this.onConnect().pipe(operators.take(1), operators.switchMap(function () {
7680
7754
  if (_this.primitiveManagers.has(key)) {
7681
7755
  return _this.primitiveManagers
@@ -7701,16 +7775,17 @@
7701
7775
  WebsocketService.prototype.info = function (message) {
7702
7776
  console.info('WS info: ' + message);
7703
7777
  };
7704
- WebsocketService.prototype.handleOnConnected = function (data) {
7705
- this.debug('Webscoket connected', data);
7778
+ WebsocketService.prototype.handleOnConnected = function () {
7779
+ this.info('Webscoket connected');
7706
7780
  this.connected$.next(true);
7707
7781
  if (this.lostConnection) {
7708
7782
  this.info('Webscoket reconnected, recriating subscriptions');
7709
7783
  this.handleReconnection();
7710
7784
  }
7711
7785
  };
7712
- WebsocketService.prototype.handleOnDisconnect = function (data) {
7713
- this.debug('Webscoket disconnected', data);
7786
+ WebsocketService.prototype.handleOnDisconnect = function () {
7787
+ this.info('Webscoket disconnected');
7788
+ this.connected$.next(false);
7714
7789
  this.disconnected$.next();
7715
7790
  };
7716
7791
  WebsocketService.prototype.handleOnWebSocketClose = function (data) {
@@ -7720,7 +7795,6 @@
7720
7795
  this.lostConnection = true;
7721
7796
  };
7722
7797
  WebsocketService.prototype.handleOnStompError = function (data) {
7723
- debugger;
7724
7798
  this.handleError('StompError', data);
7725
7799
  if (this.isAuthenticationError(data)) {
7726
7800
  this.info('Authentication error, recriating subscriptions');
@@ -7776,19 +7850,40 @@
7776
7850
  return domain + "/" + service + "/" + primitive;
7777
7851
  };
7778
7852
  WebsocketService.prototype.unsubscribePrimitiveOnFinalize = function (primitiveManager) {
7779
- if (primitiveManager.hasObservers()) {
7780
- return;
7781
- }
7782
- primitiveManager.unsubscribe();
7783
- var key = this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7784
- this.primitiveManagers.delete(key);
7785
- this.disconnectIfNoMoreObservables();
7853
+ return __awaiter(this, void 0, void 0, function () {
7854
+ var key;
7855
+ return __generator(this, function (_a) {
7856
+ switch (_a.label) {
7857
+ case 0:
7858
+ if (primitiveManager.hasObservers()) {
7859
+ return [2 /*return*/];
7860
+ }
7861
+ primitiveManager.unsubscribe();
7862
+ key = this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7863
+ this.primitiveManagers.delete(key);
7864
+ return [4 /*yield*/, this.disconnectIfNoMoreObservables()];
7865
+ case 1:
7866
+ _a.sent();
7867
+ return [2 /*return*/];
7868
+ }
7869
+ });
7870
+ });
7786
7871
  };
7787
7872
  WebsocketService.prototype.disconnectIfNoMoreObservables = function () {
7788
- if (this.getObserversCount() === 0) {
7789
- this.debug('Manually disconnecting because there are no more observers');
7790
- this.disconnect();
7791
- }
7873
+ return __awaiter(this, void 0, void 0, function () {
7874
+ return __generator(this, function (_a) {
7875
+ switch (_a.label) {
7876
+ case 0:
7877
+ if (!(this.getObserversCount() === 0)) return [3 /*break*/, 2];
7878
+ this.debug('Manually disconnecting because there are no more observers');
7879
+ return [4 /*yield*/, this.disconnect()];
7880
+ case 1:
7881
+ _a.sent();
7882
+ _a.label = 2;
7883
+ case 2: return [2 /*return*/];
7884
+ }
7885
+ });
7886
+ });
7792
7887
  };
7793
7888
  WebsocketService.prototype.getObserversCount = function () {
7794
7889
  var observersCount = 0;
@@ -8089,6 +8184,7 @@
8089
8184
  exports.NotaFiscalEntradaLookup = NotaFiscalEntradaLookup;
8090
8185
  exports.NpsService = NpsService;
8091
8186
  exports.ParametersLookup = ParametersLookup;
8187
+ exports.PrimitiveManager = PrimitiveManager;
8092
8188
  exports.ProdutoServicoLookup = ProdutoServicoLookup;
8093
8189
  exports.QuantidadeDisponivelDemandaLookup = QuantidadeDisponivelDemandaLookup;
8094
8190
  exports.RequisicaoLookup = RequisicaoLookup;