@senior-gestao-empresarial/angular-components 4.22.0 → 4.22.1

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.
@@ -4,7 +4,7 @@ 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
6
  import { Subject, throwError, interval, of, ReplaySubject } from 'rxjs';
7
- import { takeUntil, filter, catchError, map, takeWhile, switchMap, take } from 'rxjs/operators';
7
+ import { takeUntil, filter, catchError, map, takeWhile, switchMap, first, take } 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';
@@ -6412,7 +6412,6 @@ var WebsocketService = /** @class */ (function () {
6412
6412
  this.connected = false;
6413
6413
  this.isConnecting = false;
6414
6414
  this.stompSubscriptions = new Map();
6415
- // private primitiveSubjects: Map<string, Subject<any>> = new Map<string, Subject<any>>();
6416
6415
  this.primitiveManagers = new Map();
6417
6416
  this.disconnectSubject = new Subject();
6418
6417
  this.connect$ = new Subject();
@@ -6422,7 +6421,7 @@ var WebsocketService = /** @class */ (function () {
6422
6421
  }
6423
6422
  WebsocketService_1 = WebsocketService;
6424
6423
  /**
6425
- * Observable resposável por emitir uma notificação quando a conexão websocket é estabelecida.
6424
+ * Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida.
6426
6425
  * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida ou já está em andamento.
6427
6426
  */
6428
6427
  WebsocketService.prototype.onConnect = function () {
@@ -6435,7 +6434,7 @@ var WebsocketService = /** @class */ (function () {
6435
6434
  return this.connect$.asObservable();
6436
6435
  };
6437
6436
  /**
6438
- * Observable resposável por emitir uma notificação quando a conexão é finalizada.
6437
+ * Observable responsável por emitir uma notificação quando a conexão é finalizada.
6439
6438
  * @return Um `Observable<void>` que emite uma notificação quando a conexão é finalizada.
6440
6439
  */
6441
6440
  WebsocketService.prototype.onDisconnect = function () {
@@ -6462,14 +6461,7 @@ var WebsocketService = /** @class */ (function () {
6462
6461
  publishedEvents: [],
6463
6462
  };
6464
6463
  if (this.isConnected()) {
6465
- var url = this.getSubscriptionUserUrl(domain, service, primitive);
6466
- this.primitiveManagers.set(primitive, primitiveManager);
6467
- var stompSubscription = this._stompClient.subscribe(url, function (message) {
6468
- var event = JSON.parse(message.body || "{}");
6469
- _this.addPublishedEvent(primitiveManager, event);
6470
- primitiveManager.subject.next(event);
6471
- });
6472
- this.stompSubscriptions.set(primitive, stompSubscription);
6464
+ this.createStompSubscriptions(domain, service, primitive, primitiveManager);
6473
6465
  return primitiveManager.subject.asObservable();
6474
6466
  }
6475
6467
  else {
@@ -6477,22 +6469,15 @@ var WebsocketService = /** @class */ (function () {
6477
6469
  this.connect();
6478
6470
  }
6479
6471
  this.onConnect()
6480
- .pipe(take(1))
6472
+ .pipe(first())
6481
6473
  .subscribe(function () {
6482
- var url = _this.getSubscriptionUserUrl(domain, service, primitive);
6483
- _this.primitiveManagers.set(primitive, primitiveManager);
6484
- var stompSubscription = _this._stompClient.subscribe(url, function (message) {
6485
- var event = JSON.parse(message.body || "{}");
6486
- _this.addPublishedEvent(primitiveManager, event);
6487
- primitiveManager.subject.next(event);
6488
- });
6489
- _this.stompSubscriptions.set(primitive, stompSubscription);
6474
+ _this.createStompSubscriptions(domain, service, primitive, primitiveManager);
6490
6475
  });
6491
6476
  return primitiveManager.subject.asObservable();
6492
6477
  }
6493
6478
  };
6494
6479
  /**
6495
- * Retorna todos os eventos ouvidos para a respectiva primitiva.
6480
+ * Retorna todos os eventos ouvidos pela primitiva com os respectivos identificadores.
6496
6481
  * @typeParam `<T>` Tipo do evento retornado pela primitiva.
6497
6482
  * @param primitive Primitiva que será "observada" pelo client.
6498
6483
  * @param identifiers Array com os indentificadores interessados.
@@ -6527,9 +6512,7 @@ var WebsocketService = /** @class */ (function () {
6527
6512
  WebsocketService.prototype.addPublishedEvent = function (primitiveManager, event) {
6528
6513
  var _this = this;
6529
6514
  var identifier = this.getIdentifierFromEvent(primitiveManager.identifierPath, event);
6530
- var eventIndex = primitiveManager.publishedEvents.findIndex(function (x) {
6531
- return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier;
6532
- });
6515
+ var eventIndex = primitiveManager.publishedEvents.findIndex(function (x) { return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier; });
6533
6516
  if (eventIndex !== -1) {
6534
6517
  primitiveManager.publishedEvents[eventIndex] = __assign(__assign({}, primitiveManager.publishedEvents[eventIndex]), event);
6535
6518
  }
@@ -6537,6 +6520,14 @@ var WebsocketService = /** @class */ (function () {
6537
6520
  primitiveManager.publishedEvents.push(event);
6538
6521
  }
6539
6522
  };
6523
+ WebsocketService.prototype.createStompSubscriptions = function (domain, service, primitive, primitiveManager) {
6524
+ var withTokenUrl = this.getSubscriptionUrlWithToken(domain, service, primitive);
6525
+ this.primitiveManagers.set(primitive, primitiveManager);
6526
+ var stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
6527
+ var withoutTokenUrl = this.getSubscriptionUrlWithoutToken(domain, service, primitive);
6528
+ var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
6529
+ this.stompSubscriptions.set(primitive, [stompSubscriptionWithToken, stompSubscriptionWithoutToken]);
6530
+ };
6540
6531
  WebsocketService.prototype.getIdentifierFromEvent = function (identifierPath, event) {
6541
6532
  var e_2, _a;
6542
6533
  var properties = identifierPath.split(".");
@@ -6562,9 +6553,7 @@ var WebsocketService = /** @class */ (function () {
6562
6553
  this.isConnecting = true;
6563
6554
  this._stompClient.connect({}, function () {
6564
6555
  _this.setConnected(true);
6565
- // console.log('setou false isConnecting');
6566
6556
  _this.isConnecting = false;
6567
- // console.log('connectou dentro do connect cb');
6568
6557
  _this.publishOnConnect();
6569
6558
  }, function () {
6570
6559
  _this.setConnected(false);
@@ -6598,8 +6587,21 @@ var WebsocketService = /** @class */ (function () {
6598
6587
  finally { if (e_3) throw e_3.error; }
6599
6588
  }
6600
6589
  if (observersCount === 0) {
6601
- this.stompSubscriptions.forEach(function (stompSubscription) {
6602
- stompSubscription.unsubscribe();
6590
+ this.stompSubscriptions.forEach(function (stompSubscriptions) {
6591
+ var e_5, _a;
6592
+ try {
6593
+ for (var stompSubscriptions_1 = __values(stompSubscriptions), stompSubscriptions_1_1 = stompSubscriptions_1.next(); !stompSubscriptions_1_1.done; stompSubscriptions_1_1 = stompSubscriptions_1.next()) {
6594
+ var stompSubscription = stompSubscriptions_1_1.value;
6595
+ stompSubscription.unsubscribe();
6596
+ }
6597
+ }
6598
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
6599
+ finally {
6600
+ try {
6601
+ if (stompSubscriptions_1_1 && !stompSubscriptions_1_1.done && (_a = stompSubscriptions_1.return)) _a.call(stompSubscriptions_1);
6602
+ }
6603
+ finally { if (e_5) throw e_5.error; }
6604
+ }
6603
6605
  });
6604
6606
  try {
6605
6607
  for (var _e = __values(this.primitiveManagers.values()), _f = _e.next(); !_f.done; _f = _e.next()) {
@@ -6629,11 +6631,23 @@ var WebsocketService = /** @class */ (function () {
6629
6631
  WebsocketService.prototype.setConnected = function (connected) {
6630
6632
  this.connected = connected;
6631
6633
  };
6632
- WebsocketService.prototype.getSubscriptionUserUrl = function (domain, service, primitive) {
6634
+ WebsocketService.prototype.getSubscriptionUrlWithToken = function (domain, service, primitive) {
6633
6635
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6634
6636
  var token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
6635
6637
  return "/topic/" + tenant + "/" + token + "/" + domain + "/" + service + "/" + primitive;
6636
6638
  };
6639
+ WebsocketService.prototype.getSubscriptionUrlWithoutToken = function (domain, service, primitive) {
6640
+ var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6641
+ return "/topic/" + tenant + "/" + domain + "/" + service + "/" + primitive;
6642
+ };
6643
+ WebsocketService.prototype.createStompSubscription = function (destination, primitiveManager) {
6644
+ var _this = this;
6645
+ return this._stompClient.subscribe(destination, function (message) {
6646
+ var event = JSON.parse(message.body || "{}");
6647
+ _this.addPublishedEvent(primitiveManager, event);
6648
+ primitiveManager.subject.next(event);
6649
+ });
6650
+ };
6637
6651
  WebsocketService.prototype.createStompClient = function () {
6638
6652
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
6639
6653
  this._stompClient = Stomp.over(ws);
@@ -6651,12 +6665,10 @@ var WebsocketService = /** @class */ (function () {
6651
6665
  this._stompClient.disconnect();
6652
6666
  var baseUrl = this.getBaseUrl();
6653
6667
  if (this.baseUrl !== null && baseUrl != this.baseUrl) {
6654
- // //console.log('ws disconnected: base url changed', this.baseUrl, ' -> ', baseUrl || 'null');
6655
6668
  return;
6656
6669
  }
6657
6670
  var username = this.getUserName();
6658
6671
  if (this.username !== null && username != this.username) {
6659
- // //console.log('ws disconnected: username changed', this.username, ' -> ', username || 'null');
6660
6672
  return;
6661
6673
  }
6662
6674
  setTimeout(function () {