@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
@@ -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,18 @@
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];
7576
7647
  return [4 /*yield*/, this.stompClient.deactivate()];
7577
- case 1:
7648
+ case 3:
7578
7649
  _d.sent();
7579
- this.stompClient = null;
7580
- _d.label = 2;
7581
- case 2:
7582
- this.connected$.next(false);
7583
- return [2 /*return*/];
7650
+ _d.label = 4;
7651
+ case 4: return [3 /*break*/, 7];
7652
+ case 5: return [4 /*yield*/, this.connectionLock.release()];
7653
+ case 6:
7654
+ _d.sent();
7655
+ return [7 /*endfinally*/];
7656
+ case 7: return [2 /*return*/];
7584
7657
  }
7585
7658
  });
7586
7659
  });
@@ -7654,11 +7727,12 @@
7654
7727
  }
7655
7728
  var primitiveManager = new PrimitiveManager(domain, service, primitive);
7656
7729
  this.primitiveManagers.set(key, primitiveManager);
7657
- this.connect();
7658
- this.onConnect()
7659
- .pipe(operators.take(1))
7660
- .subscribe(function () {
7661
- _this.createStompSubscriptions(primitiveManager);
7730
+ this.connect().then(function () {
7731
+ _this.onConnect()
7732
+ .pipe(operators.take(1))
7733
+ .subscribe(function () {
7734
+ _this.createStompSubscriptions(primitiveManager);
7735
+ });
7662
7736
  });
7663
7737
  return primitiveManager
7664
7738
  .getEventObservable()
@@ -7675,7 +7749,6 @@
7675
7749
  var _this = this;
7676
7750
  var domain = options.domain, service = options.service, primitive = options.primitive;
7677
7751
  var key = this.buildPrimitiveManagerKey(domain, service, primitive);
7678
- this.connect();
7679
7752
  return this.onConnect().pipe(operators.take(1), operators.switchMap(function () {
7680
7753
  if (_this.primitiveManagers.has(key)) {
7681
7754
  return _this.primitiveManagers
@@ -7701,26 +7774,36 @@
7701
7774
  WebsocketService.prototype.info = function (message) {
7702
7775
  console.info('WS info: ' + message);
7703
7776
  };
7704
- WebsocketService.prototype.handleOnConnected = function (data) {
7705
- this.debug('Webscoket connected', data);
7777
+ WebsocketService.prototype.handleOnConnected = function () {
7778
+ this.info('Webscoket connected');
7706
7779
  this.connected$.next(true);
7707
7780
  if (this.lostConnection) {
7708
7781
  this.info('Webscoket reconnected, recriating subscriptions');
7709
7782
  this.handleReconnection();
7710
7783
  }
7711
7784
  };
7712
- WebsocketService.prototype.handleOnDisconnect = function (data) {
7713
- this.debug('Webscoket disconnected', data);
7785
+ WebsocketService.prototype.handleOnDisconnect = function () {
7786
+ this.info('Webscoket disconnected');
7787
+ this.connected$.next(false);
7714
7788
  this.disconnected$.next();
7715
7789
  };
7716
7790
  WebsocketService.prototype.handleOnWebSocketClose = function (data) {
7791
+ if (data.reason && data.reason.toLowerCase().indexOf("go away") !== -1) {
7792
+ this.lostConnection = true;
7793
+ this.handleError('AuthenticationError', new stompjs.FrameImpl({
7794
+ command: data.type,
7795
+ headers: {
7796
+ message: data.reason
7797
+ }
7798
+ }));
7799
+ return;
7800
+ }
7717
7801
  if (data.wasClean) {
7718
7802
  return;
7719
7803
  }
7720
7804
  this.lostConnection = true;
7721
7805
  };
7722
7806
  WebsocketService.prototype.handleOnStompError = function (data) {
7723
- debugger;
7724
7807
  this.handleError('StompError', data);
7725
7808
  if (this.isAuthenticationError(data)) {
7726
7809
  this.info('Authentication error, recriating subscriptions');
@@ -7776,19 +7859,40 @@
7776
7859
  return domain + "/" + service + "/" + primitive;
7777
7860
  };
7778
7861
  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();
7862
+ return __awaiter(this, void 0, void 0, function () {
7863
+ var key;
7864
+ return __generator(this, function (_a) {
7865
+ switch (_a.label) {
7866
+ case 0:
7867
+ if (primitiveManager.hasObservers()) {
7868
+ return [2 /*return*/];
7869
+ }
7870
+ primitiveManager.unsubscribe();
7871
+ key = this.buildPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7872
+ this.primitiveManagers.delete(key);
7873
+ return [4 /*yield*/, this.disconnectIfNoMoreObservables()];
7874
+ case 1:
7875
+ _a.sent();
7876
+ return [2 /*return*/];
7877
+ }
7878
+ });
7879
+ });
7786
7880
  };
7787
7881
  WebsocketService.prototype.disconnectIfNoMoreObservables = function () {
7788
- if (this.getObserversCount() === 0) {
7789
- this.debug('Manually disconnecting because there are no more observers');
7790
- this.disconnect();
7791
- }
7882
+ return __awaiter(this, void 0, void 0, function () {
7883
+ return __generator(this, function (_a) {
7884
+ switch (_a.label) {
7885
+ case 0:
7886
+ if (!(this.getObserversCount() === 0)) return [3 /*break*/, 2];
7887
+ this.debug('Manually disconnecting because there are no more observers');
7888
+ return [4 /*yield*/, this.disconnect()];
7889
+ case 1:
7890
+ _a.sent();
7891
+ _a.label = 2;
7892
+ case 2: return [2 /*return*/];
7893
+ }
7894
+ });
7895
+ });
7792
7896
  };
7793
7897
  WebsocketService.prototype.getObserversCount = function () {
7794
7898
  var observersCount = 0;
@@ -8089,6 +8193,7 @@
8089
8193
  exports.NotaFiscalEntradaLookup = NotaFiscalEntradaLookup;
8090
8194
  exports.NpsService = NpsService;
8091
8195
  exports.ParametersLookup = ParametersLookup;
8196
+ exports.PrimitiveManager = PrimitiveManager;
8092
8197
  exports.ProdutoServicoLookup = ProdutoServicoLookup;
8093
8198
  exports.QuantidadeDisponivelDemandaLookup = QuantidadeDisponivelDemandaLookup;
8094
8199
  exports.RequisicaoLookup = RequisicaoLookup;