@senior-gestao-empresarial/angular-components 4.22.2 → 4.23.0

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('primeng/breadcrumb'), require('@angular/router'), require('rxjs'), require('rxjs/operators'), require('moment'), require('@seniorsistemas/angular-components'), require('@angular/common/http'), require('primeng/api'), require('@ngx-translate/core'), require('@seniorsistemas/platform-components'), require('@seniorsistemas/senior-platform-data'), require('@angular/forms'), require('js-cookie'), require('@stomp/stompjs'), require('ngx-cookie-service'), require('sockjs-client')) :
3
- typeof define === 'function' && define.amd ? define('@senior-gestao-empresarial/angular-components', ['exports', '@angular/core', '@angular/common', 'primeng/breadcrumb', '@angular/router', 'rxjs', 'rxjs/operators', 'moment', '@seniorsistemas/angular-components', '@angular/common/http', 'primeng/api', '@ngx-translate/core', '@seniorsistemas/platform-components', '@seniorsistemas/senior-platform-data', '@angular/forms', 'js-cookie', '@stomp/stompjs', 'ngx-cookie-service', 'sockjs-client'], factory) :
4
- (global = global || self, factory((global['senior-gestao-empresarial'] = global['senior-gestao-empresarial'] || {}, global['senior-gestao-empresarial']['angular-components'] = {}), global.ng.core, global.ng.common, global.breadcrumb, global.ng.router, global.rxjs, global.rxjs.operators, global.moment_, global.angularComponents, global.ng.common.http, global.api, global.core$1, global.platformComponents, global.seniorPlatformData, global.ng.forms, global.jsCookie, global.stompjs, global.ngxCookieService, global.SockJS));
5
- }(this, (function (exports, core, common, breadcrumb, router, rxjs, operators, moment_, angularComponents, http, api, core$1, platformComponents, seniorPlatformData, forms, jsCookie, stompjs, ngxCookieService, SockJS) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common'), require('primeng/breadcrumb'), require('@angular/router'), require('rxjs'), require('rxjs/operators'), require('moment'), require('@seniorsistemas/angular-components'), require('@angular/common/http'), require('primeng/api'), require('@ngx-translate/core'), require('@seniorsistemas/platform-components'), require('@seniorsistemas/senior-platform-data'), require('@angular/forms'), require('js-cookie'), require('@stomp/stompjs'), require('sockjs-client')) :
3
+ typeof define === 'function' && define.amd ? define('@senior-gestao-empresarial/angular-components', ['exports', '@angular/core', '@angular/common', 'primeng/breadcrumb', '@angular/router', 'rxjs', 'rxjs/operators', 'moment', '@seniorsistemas/angular-components', '@angular/common/http', 'primeng/api', '@ngx-translate/core', '@seniorsistemas/platform-components', '@seniorsistemas/senior-platform-data', '@angular/forms', 'js-cookie', '@stomp/stompjs', 'sockjs-client'], factory) :
4
+ (global = global || self, factory((global['senior-gestao-empresarial'] = global['senior-gestao-empresarial'] || {}, global['senior-gestao-empresarial']['angular-components'] = {}), global.ng.core, global.ng.common, global.breadcrumb, global.ng.router, global.rxjs, global.rxjs.operators, global.moment_, global.angularComponents, global.ng.common.http, global.api, global.core$1, global.platformComponents, global.seniorPlatformData, global.ng.forms, global.jsCookie, global.stompjs, global.SockJS));
5
+ }(this, (function (exports, core, common, breadcrumb, router, rxjs, operators, moment_, angularComponents, http, api, core$1, platformComponents, seniorPlatformData, forms, jsCookie, stompjs, SockJS) { 'use strict';
6
6
 
7
7
  /*! *****************************************************************************
8
8
  Copyright (c) Microsoft Corporation.
@@ -6609,17 +6609,16 @@
6609
6609
  }());
6610
6610
 
6611
6611
  var WebsocketService = /** @class */ (function () {
6612
- function WebsocketService(cookieService) {
6613
- this.cookieService = cookieService;
6614
- this.baseUrl = null;
6615
- this.username = null;
6612
+ function WebsocketService() {
6616
6613
  this.focused = true;
6614
+ this.wasConnected = false;
6617
6615
  this.connected = false;
6618
6616
  this.isConnecting = false;
6619
- this.stompSubscriptions = new Map();
6620
6617
  this.primitiveManagers = new Map();
6621
- this.disconnectSubject = new rxjs.Subject();
6622
6618
  this.connect$ = new rxjs.Subject();
6619
+ this.disconnect$ = new rxjs.Subject();
6620
+ this.reconnect$ = new rxjs.Subject();
6621
+ this.error$ = new rxjs.Subject();
6623
6622
  window.onfocus = this.onFocus;
6624
6623
  window.onblur = this.onBlur;
6625
6624
  this.connect();
@@ -6633,22 +6632,36 @@
6633
6632
  var _this = this;
6634
6633
  setTimeout(function () {
6635
6634
  if (_this.isConnected()) {
6636
- _this.publishOnConnect();
6635
+ _this.connect$.next();
6637
6636
  }
6638
6637
  }, 0);
6639
- return this.connect$.asObservable();
6638
+ return this.connect$.pipe(operators.first());
6640
6639
  };
6641
6640
  /**
6642
- * Observable responsável por emitir uma notificação quando a conexão é finalizada.
6643
- * @return Um `Observable<void>` que emite uma notificação quando a conexão é finalizada.
6641
+ * Observable responsável por emitir uma notificação quando a conexão é desconectada.
6642
+ * @return Um `Observable<void>` que emite uma notificação quando a conexão é desconectada.
6644
6643
  */
6645
6644
  WebsocketService.prototype.onDisconnect = function () {
6646
- return this.disconnectSubject.asObservable();
6645
+ return this.disconnect$.asObservable();
6646
+ };
6647
+ /**
6648
+ * Observable responsável por emitir uma notificação quando a conexão é reconectada.
6649
+ * @return Um `Observable<void>` que emite uma notificação quando a conexão é reconectada.
6650
+ */
6651
+ WebsocketService.prototype.onReconnect = function () {
6652
+ return this.reconnect$.asObservable();
6653
+ };
6654
+ /**
6655
+ * Observable responsável por emitir uma notificação quando ocorre algum erro.
6656
+ * @return Um `Observable<FrameImpl>` que emite uma notificação quando ocorre algum erro.
6657
+ */
6658
+ WebsocketService.prototype.onError = function () {
6659
+ return this.error$.asObservable();
6647
6660
  };
6648
6661
  /**
6649
6662
  * Observable responsável por emitir uma notificação quando um evento é publicado.
6650
6663
  * @typeParam `<T>` Tipo do objeto que o retorno do `observable` vai devolver.
6651
- * @param domain Dominio da primitva.
6664
+ * @param domain Dominio da primitiva.
6652
6665
  * @param service Service da primitiva.
6653
6666
  * @param primitive Primitiva que será "observada" pelo client.
6654
6667
  * @param identifierPath Caminho até a propriedade considerada o identificador do registro.
@@ -6660,25 +6673,27 @@
6660
6673
  return this.primitiveManagers.get(primitive).subject.asObservable();
6661
6674
  }
6662
6675
  var primitiveManager = {
6676
+ domain: domain,
6677
+ service: service,
6678
+ primitive: primitive,
6679
+ stompSubscriptions: [],
6663
6680
  subject: new rxjs.Subject(),
6664
6681
  identifierPath: identifierPath,
6665
6682
  publishedEvents: [],
6666
6683
  };
6667
6684
  this.primitiveManagers.set(primitive, primitiveManager);
6668
6685
  if (this.isConnected()) {
6669
- this.createStompSubscriptions(domain, service, primitive, primitiveManager);
6670
- return primitiveManager.subject.asObservable();
6686
+ this.createStompSubscriptions(primitiveManager);
6687
+ return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitive); }));
6671
6688
  }
6672
6689
  else {
6673
6690
  if (!this.isConnecting) {
6674
6691
  this.connect();
6675
6692
  }
6676
- this.onConnect()
6677
- .pipe(operators.first())
6678
- .subscribe(function () {
6679
- _this.createStompSubscriptions(domain, service, primitive, primitiveManager);
6693
+ this.connect$.pipe(operators.first()).subscribe(function () {
6694
+ _this.createStompSubscriptions(primitiveManager);
6680
6695
  });
6681
- return primitiveManager.subject.asObservable();
6696
+ return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitive); }));
6682
6697
  }
6683
6698
  };
6684
6699
  /**
@@ -6725,12 +6740,12 @@
6725
6740
  primitiveManager.publishedEvents.push(event);
6726
6741
  }
6727
6742
  };
6728
- WebsocketService.prototype.createStompSubscriptions = function (domain, service, primitive, primitiveManager) {
6729
- var withTokenUrl = this.getSubscriptionUrlWithToken(domain, service, primitive);
6743
+ WebsocketService.prototype.createStompSubscriptions = function (primitiveManager) {
6744
+ var withTokenUrl = this.getSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6730
6745
  var stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
6731
- var withoutTokenUrl = this.getSubscriptionUrlWithoutToken(domain, service, primitive);
6746
+ var withoutTokenUrl = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6732
6747
  var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
6733
- this.stompSubscriptions.set(primitive, [stompSubscriptionWithToken, stompSubscriptionWithoutToken]);
6748
+ primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
6734
6749
  };
6735
6750
  WebsocketService.prototype.getIdentifierFromEvent = function (identifierPath, event) {
6736
6751
  var e_2, _a;
@@ -6755,19 +6770,24 @@
6755
6770
  var _this = this;
6756
6771
  this.createStompClient();
6757
6772
  this.isConnecting = true;
6773
+ this._stompClient.activate();
6758
6774
  this._stompClient.connect({}, function () {
6759
- _this.setConnected(true);
6760
6775
  _this.isConnecting = false;
6761
- _this.publishOnConnect();
6762
- }, function () {
6776
+ _this.setConnected(true);
6777
+ if (_this.wasConnected) {
6778
+ _this.reconnectPrimitives();
6779
+ _this.reconnect$.next();
6780
+ }
6781
+ else {
6782
+ _this.wasConnected = true;
6783
+ _this.connect$.next();
6784
+ }
6785
+ }, function (error) {
6763
6786
  _this.setConnected(false);
6764
- // this.reconnectWebSocket();
6787
+ _this.error$.next(error);
6788
+ _this.reconnect();
6765
6789
  });
6766
6790
  };
6767
- WebsocketService.prototype.publishOnConnect = function () {
6768
- this.connect$.next();
6769
- this.connect$.observers = [];
6770
- };
6771
6791
  WebsocketService.prototype.onFocus = function () {
6772
6792
  this.focused = true;
6773
6793
  };
@@ -6775,59 +6795,55 @@
6775
6795
  this.focused = false;
6776
6796
  };
6777
6797
  WebsocketService.prototype.disconnect = function () {
6778
- var e_3, _a, e_4, _b;
6779
- var observersCount = 0;
6798
+ var e_3, _a, e_4, _b, e_5, _c;
6799
+ var observersCount = this.getObserversCount();
6800
+ if (observersCount > 0)
6801
+ return;
6780
6802
  try {
6781
- for (var _c = __values(this.primitiveManagers.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
6782
- var primitiveManager = _d.value;
6783
- observersCount += primitiveManager.subject.observers.length;
6784
- }
6785
- }
6786
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
6787
- finally {
6788
- try {
6789
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
6790
- }
6791
- finally { if (e_3) throw e_3.error; }
6792
- }
6793
- if (observersCount === 0) {
6794
- this.stompSubscriptions.forEach(function (stompSubscriptions) {
6795
- var e_5, _a;
6803
+ for (var _d = __values(this.primitiveManagers.values()), _e = _d.next(); !_e.done; _e = _d.next()) {
6804
+ var primitiveManager = _e.value;
6796
6805
  try {
6797
- for (var stompSubscriptions_1 = __values(stompSubscriptions), stompSubscriptions_1_1 = stompSubscriptions_1.next(); !stompSubscriptions_1_1.done; stompSubscriptions_1_1 = stompSubscriptions_1.next()) {
6798
- var stompSubscription = stompSubscriptions_1_1.value;
6806
+ for (var _f = (e_4 = void 0, __values(primitiveManager.stompSubscriptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
6807
+ var stompSubscription = _g.value;
6799
6808
  stompSubscription.unsubscribe();
6800
6809
  }
6801
6810
  }
6802
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
6811
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
6803
6812
  finally {
6804
6813
  try {
6805
- if (stompSubscriptions_1_1 && !stompSubscriptions_1_1.done && (_a = stompSubscriptions_1.return)) _a.call(stompSubscriptions_1);
6814
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
6806
6815
  }
6807
- finally { if (e_5) throw e_5.error; }
6816
+ finally { if (e_4) throw e_4.error; }
6808
6817
  }
6809
- });
6818
+ }
6819
+ }
6820
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
6821
+ finally {
6810
6822
  try {
6811
- for (var _e = __values(this.primitiveManagers.values()), _f = _e.next(); !_f.done; _f = _e.next()) {
6812
- var primitiveManager = _f.value;
6813
- primitiveManager.subject.complete();
6814
- }
6823
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
6815
6824
  }
6816
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
6817
- finally {
6818
- try {
6819
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
6820
- }
6821
- finally { if (e_4) throw e_4.error; }
6825
+ finally { if (e_3) throw e_3.error; }
6826
+ }
6827
+ try {
6828
+ for (var _h = __values(this.primitiveManagers.values()), _j = _h.next(); !_j.done; _j = _h.next()) {
6829
+ var primitiveManager = _j.value;
6830
+ primitiveManager.subject.complete();
6822
6831
  }
6823
- this.stompSubscriptions.clear();
6824
- this.primitiveManagers.clear();
6825
- this._stompClient.disconnect();
6826
- this._stompClient.deactivate();
6827
- this.setConnected(false);
6828
- this.isConnecting = false;
6829
- this.disconnectSubject.next();
6830
6832
  }
6833
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
6834
+ finally {
6835
+ try {
6836
+ if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
6837
+ }
6838
+ finally { if (e_5) throw e_5.error; }
6839
+ }
6840
+ this.primitiveManagers.clear();
6841
+ this._stompClient.disconnect();
6842
+ this._stompClient.deactivate();
6843
+ this.setConnected(false);
6844
+ this.isConnecting = false;
6845
+ this.wasConnected = false;
6846
+ this.disconnect$.next();
6831
6847
  };
6832
6848
  WebsocketService.prototype.isConnected = function () {
6833
6849
  return this.connected;
@@ -6855,46 +6871,104 @@
6855
6871
  WebsocketService.prototype.createStompClient = function () {
6856
6872
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
6857
6873
  this._stompClient = stompjs.Stomp.over(ws);
6874
+ // this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
6858
6875
  this._stompClient.debug = function () { }; // Para remover os logs.
6859
6876
  };
6860
- WebsocketService.prototype.getBaseUrl = function () {
6861
- return this.cookieService.get("com.senior.base.url");
6862
- };
6863
- WebsocketService.prototype.getUserName = function () {
6864
- var token = this.cookieService.get("com.senior.token");
6865
- return token && JSON.parse(token).username;
6866
- };
6867
- WebsocketService.prototype.reconnectWebSocket = function () {
6877
+ WebsocketService.prototype.reconnect = function () {
6868
6878
  var _this = this;
6869
- this._stompClient.disconnect();
6870
- var baseUrl = this.getBaseUrl();
6871
- if (this.baseUrl !== null && baseUrl != this.baseUrl) {
6872
- return;
6873
- }
6874
- var username = this.getUserName();
6875
- if (this.username !== null && username != this.username) {
6876
- return;
6877
- }
6879
+ if (this.connected)
6880
+ this._stompClient.disconnect();
6878
6881
  setTimeout(function () {
6882
+ if (_this.getObserversCount() === 0)
6883
+ return;
6879
6884
  if (_this.focused) {
6880
6885
  _this.connect();
6881
6886
  }
6882
6887
  else {
6883
- _this.reconnectWebSocket();
6888
+ _this.reconnect();
6884
6889
  }
6885
6890
  }, WebsocketService_1.RECONNECT_TIMER);
6886
6891
  };
6892
+ WebsocketService.prototype.reconnectPrimitives = function () {
6893
+ var e_6, _a, e_7, _b;
6894
+ try {
6895
+ for (var _c = __values(this.primitiveManagers.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
6896
+ var primitiveManager = _d.value;
6897
+ try {
6898
+ for (var _e = (e_7 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
6899
+ var stompSubscription = _f.value;
6900
+ stompSubscription.unsubscribe();
6901
+ }
6902
+ }
6903
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
6904
+ finally {
6905
+ try {
6906
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
6907
+ }
6908
+ finally { if (e_7) throw e_7.error; }
6909
+ }
6910
+ this.createStompSubscriptions(primitiveManager);
6911
+ }
6912
+ }
6913
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
6914
+ finally {
6915
+ try {
6916
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
6917
+ }
6918
+ finally { if (e_6) throw e_6.error; }
6919
+ }
6920
+ };
6921
+ WebsocketService.prototype.getObserversCount = function () {
6922
+ var e_8, _a;
6923
+ var observersCount = 0;
6924
+ try {
6925
+ for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
6926
+ var primitiveManager = _c.value;
6927
+ observersCount += primitiveManager.subject.observers.length;
6928
+ }
6929
+ }
6930
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
6931
+ finally {
6932
+ try {
6933
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6934
+ }
6935
+ finally { if (e_8) throw e_8.error; }
6936
+ }
6937
+ return observersCount;
6938
+ };
6939
+ WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitive) {
6940
+ var e_9, _a;
6941
+ var primitiveManager = this.primitiveManagers.get(primitive);
6942
+ if (!primitiveManager)
6943
+ return;
6944
+ // @IMPORTANT: Replace .observers.length with .observed in rxjs 7.0+
6945
+ var hasObservers = !(primitiveManager.subject.observers.length === 1);
6946
+ if (hasObservers)
6947
+ return;
6948
+ try {
6949
+ for (var _b = __values(primitiveManager.stompSubscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
6950
+ var stompSubscription = _c.value;
6951
+ stompSubscription.unsubscribe();
6952
+ }
6953
+ }
6954
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
6955
+ finally {
6956
+ try {
6957
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6958
+ }
6959
+ finally { if (e_9) throw e_9.error; }
6960
+ }
6961
+ this.primitiveManagers.delete(primitive);
6962
+ this.disconnect();
6963
+ };
6887
6964
  var WebsocketService_1;
6888
6965
  WebsocketService.RECONNECT_TIMER = 3000;
6889
- WebsocketService.CONNECTION_TIMEOUT = 30000;
6966
+ WebsocketService.CONNECTION_TIMEOUT = 15000;
6890
6967
  WebsocketService.BASE_URL_COOKIE = "com.senior.base.url";
6891
6968
  WebsocketService.TOKEN_COOKIE = "com.senior.token";
6892
6969
  WebsocketService.TOKEN = JSON.parse(jsCookie.get(WebsocketService_1.TOKEN_COOKIE) || "{}");
6893
6970
  WebsocketService.WEBSOCKET_URL = jsCookie.get(WebsocketService_1.BASE_URL_COOKIE) + "/websocket/";
6894
- WebsocketService.ctorParameters = function () { return [
6895
- { type: ngxCookieService.CookieService }
6896
- ]; };
6897
- WebsocketService.ɵprov = core.ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(core.ɵɵinject(ngxCookieService.CookieService)); }, token: WebsocketService, providedIn: "root" });
6971
+ WebsocketService.ɵprov = core.ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
6898
6972
  WebsocketService = WebsocketService_1 = __decorate([
6899
6973
  core.Injectable({
6900
6974
  providedIn: "root",