@senior-gestao-empresarial/angular-components 5.1.1 → 6.0.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.
@@ -6758,14 +6758,23 @@
6758
6758
 
6759
6759
  var WebsocketService = /** @class */ (function () {
6760
6760
  function WebsocketService() {
6761
+ /** @private */
6761
6762
  this.focused = true;
6763
+ /** @private */
6762
6764
  this.wasConnected = false;
6765
+ /** @private */
6763
6766
  this.connected = false;
6767
+ /** @private */
6764
6768
  this.isConnecting = false;
6769
+ /** @private */
6765
6770
  this.primitiveManagers = new Map();
6771
+ /** @private */
6766
6772
  this.connect$ = new rxjs.Subject();
6773
+ /** @private */
6767
6774
  this.disconnect$ = new rxjs.Subject();
6775
+ /** @private */
6768
6776
  this.reconnect$ = new rxjs.Subject();
6777
+ /** @private */
6769
6778
  this.error$ = new rxjs.Subject();
6770
6779
  window.onfocus = this.onFocus;
6771
6780
  window.onblur = this.onBlur;
@@ -6807,18 +6816,19 @@
6807
6816
  return this.error$.asObservable();
6808
6817
  };
6809
6818
  /**
6810
- * Observable responsável por emitir uma notificação quando um evento é publicado.
6811
6819
  * @typeParam `<T>` Tipo do objeto que o retorno do `observable` vai devolver.
6812
- * @param domain Dominio da primitiva.
6813
- * @param service Service da primitiva.
6814
- * @param primitive Primitiva que será "observada" pelo client.
6815
- * @param identifierPath Caminho até a propriedade considerada o identificador do registro.
6816
- * @return Um `observable` que emite notificações toda vez que o respectivo evento é publicado no sistema.
6820
+ * @param {Object} options Objeto de configuração do evento.
6821
+ * @param {string} options.domain Domínio da primitiva.
6822
+ * @param {string} options.service Serviço da primitiva.
6823
+ * @param {string} options.primitive Primitiva que será "observada".
6824
+ * @return Um Observable<T> que emite notificações toda vez que o respectivo evento é publicado.
6817
6825
  */
6818
- WebsocketService.prototype.onEvent = function (domain, service, primitive, identifierPath) {
6826
+ WebsocketService.prototype.onEvent = function (options) {
6819
6827
  var _this = this;
6820
- if (this.primitiveManagers.has(primitive)) {
6821
- return this.primitiveManagers.get(primitive).subject.asObservable();
6828
+ var domain = options.domain, service = options.service, primitive = options.primitive;
6829
+ var key = this.getPrimitiveManagerKey(domain, service, primitive);
6830
+ if (this.primitiveManagers.has(key)) {
6831
+ return this.primitiveManagers.get(key).subject.asObservable();
6822
6832
  }
6823
6833
  var primitiveManager = {
6824
6834
  domain: domain,
@@ -6826,13 +6836,11 @@
6826
6836
  primitive: primitive,
6827
6837
  stompSubscriptions: [],
6828
6838
  subject: new rxjs.Subject(),
6829
- identifierPath: identifierPath,
6830
- publishedEvents: [],
6831
6839
  };
6832
- this.primitiveManagers.set(primitive, primitiveManager);
6840
+ this.primitiveManagers.set(key, primitiveManager);
6833
6841
  if (this.isConnected()) {
6834
6842
  this.createStompSubscriptions(primitiveManager);
6835
- return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitive); }));
6843
+ return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
6836
6844
  }
6837
6845
  else {
6838
6846
  if (!this.isConnecting) {
@@ -6841,53 +6849,10 @@
6841
6849
  this.connect$.pipe(operators.first()).subscribe(function () {
6842
6850
  _this.createStompSubscriptions(primitiveManager);
6843
6851
  });
6844
- return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitive); }));
6845
- }
6846
- };
6847
- /**
6848
- * Retorna todos os eventos ouvidos pela primitiva com os respectivos identificadores.
6849
- * @typeParam `<T>` Tipo do evento retornado pela primitiva.
6850
- * @param primitive Primitiva que será "observada" pelo client.
6851
- * @param identifiers Array com os identificadores interessados.
6852
- * @return Array contendo o último evento recebido de cada identificador fornecido.
6853
- */
6854
- WebsocketService.prototype.getPublishedEvents = function (primitive, identifiers) {
6855
- var e_1, _a;
6856
- var _this = this;
6857
- var publishedEvents = [];
6858
- var primitiveManager = this.primitiveManagers.get(primitive);
6859
- var _loop_1 = function (identifier) {
6860
- var event_1 = primitiveManager.publishedEvents.find(function (x) { return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier; });
6861
- if (event_1) {
6862
- publishedEvents.push(event_1);
6863
- }
6864
- };
6865
- try {
6866
- for (var identifiers_1 = __values(identifiers), identifiers_1_1 = identifiers_1.next(); !identifiers_1_1.done; identifiers_1_1 = identifiers_1.next()) {
6867
- var identifier = identifiers_1_1.value;
6868
- _loop_1(identifier);
6869
- }
6870
- }
6871
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
6872
- finally {
6873
- try {
6874
- if (identifiers_1_1 && !identifiers_1_1.done && (_a = identifiers_1.return)) _a.call(identifiers_1);
6875
- }
6876
- finally { if (e_1) throw e_1.error; }
6877
- }
6878
- return publishedEvents;
6879
- };
6880
- WebsocketService.prototype.addPublishedEvent = function (primitiveManager, event) {
6881
- var _this = this;
6882
- var identifier = this.getIdentifierFromEvent(primitiveManager.identifierPath, event);
6883
- var eventIndex = primitiveManager.publishedEvents.findIndex(function (x) { return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier; });
6884
- if (eventIndex !== -1) {
6885
- primitiveManager.publishedEvents[eventIndex] = __assign(__assign({}, primitiveManager.publishedEvents[eventIndex]), event);
6886
- }
6887
- else {
6888
- primitiveManager.publishedEvents.push(event);
6852
+ return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
6889
6853
  }
6890
6854
  };
6855
+ /** @private */
6891
6856
  WebsocketService.prototype.createStompSubscriptions = function (primitiveManager) {
6892
6857
  var withTokenUrl = this.getSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6893
6858
  var stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
@@ -6895,25 +6860,7 @@
6895
6860
  var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
6896
6861
  primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
6897
6862
  };
6898
- WebsocketService.prototype.getIdentifierFromEvent = function (identifierPath, event) {
6899
- var e_2, _a;
6900
- var properties = identifierPath.split(".");
6901
- var identifier = event;
6902
- try {
6903
- for (var properties_1 = __values(properties), properties_1_1 = properties_1.next(); !properties_1_1.done; properties_1_1 = properties_1.next()) {
6904
- var property = properties_1_1.value;
6905
- identifier = identifier[property];
6906
- }
6907
- }
6908
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
6909
- finally {
6910
- try {
6911
- if (properties_1_1 && !properties_1_1.done && (_a = properties_1.return)) _a.call(properties_1);
6912
- }
6913
- finally { if (e_2) throw e_2.error; }
6914
- }
6915
- return identifier;
6916
- };
6863
+ /** @private */
6917
6864
  WebsocketService.prototype.connect = function () {
6918
6865
  var _this = this;
6919
6866
  this.createStompClient();
@@ -6936,14 +6883,16 @@
6936
6883
  _this.reconnect();
6937
6884
  });
6938
6885
  };
6886
+ /** @private */
6939
6887
  WebsocketService.prototype.onFocus = function () {
6940
6888
  this.focused = true;
6941
6889
  };
6890
+ /** @private */
6942
6891
  WebsocketService.prototype.onBlur = function () {
6943
6892
  this.focused = false;
6944
6893
  };
6945
6894
  WebsocketService.prototype.disconnect = function () {
6946
- var e_3, _a, e_4, _b, e_5, _c;
6895
+ var e_1, _a, e_2, _b, e_3, _c;
6947
6896
  var observersCount = this.getObserversCount();
6948
6897
  if (observersCount > 0)
6949
6898
  return;
@@ -6951,26 +6900,26 @@
6951
6900
  for (var _d = __values(this.primitiveManagers.values()), _e = _d.next(); !_e.done; _e = _d.next()) {
6952
6901
  var primitiveManager = _e.value;
6953
6902
  try {
6954
- for (var _f = (e_4 = void 0, __values(primitiveManager.stompSubscriptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
6903
+ for (var _f = (e_2 = void 0, __values(primitiveManager.stompSubscriptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
6955
6904
  var stompSubscription = _g.value;
6956
6905
  stompSubscription.unsubscribe();
6957
6906
  }
6958
6907
  }
6959
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
6908
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
6960
6909
  finally {
6961
6910
  try {
6962
6911
  if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
6963
6912
  }
6964
- finally { if (e_4) throw e_4.error; }
6913
+ finally { if (e_2) throw e_2.error; }
6965
6914
  }
6966
6915
  }
6967
6916
  }
6968
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
6917
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
6969
6918
  finally {
6970
6919
  try {
6971
6920
  if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
6972
6921
  }
6973
- finally { if (e_3) throw e_3.error; }
6922
+ finally { if (e_1) throw e_1.error; }
6974
6923
  }
6975
6924
  try {
6976
6925
  for (var _h = __values(this.primitiveManagers.values()), _j = _h.next(); !_j.done; _j = _h.next()) {
@@ -6978,12 +6927,12 @@
6978
6927
  primitiveManager.subject.complete();
6979
6928
  }
6980
6929
  }
6981
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
6930
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
6982
6931
  finally {
6983
6932
  try {
6984
6933
  if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
6985
6934
  }
6986
- finally { if (e_5) throw e_5.error; }
6935
+ finally { if (e_3) throw e_3.error; }
6987
6936
  }
6988
6937
  this.primitiveManagers.clear();
6989
6938
  this._stompClient.disconnect();
@@ -6993,35 +6942,40 @@
6993
6942
  this.wasConnected = false;
6994
6943
  this.disconnect$.next();
6995
6944
  };
6945
+ /** @private */
6996
6946
  WebsocketService.prototype.isConnected = function () {
6997
6947
  return this.connected;
6998
6948
  };
6949
+ /** @private */
6999
6950
  WebsocketService.prototype.setConnected = function (connected) {
7000
6951
  this.connected = connected;
7001
6952
  };
6953
+ /** @private */
7002
6954
  WebsocketService.prototype.getSubscriptionUrlWithToken = function (domain, service, primitive) {
7003
6955
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
7004
6956
  var token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
7005
6957
  return "/topic/" + tenant + "/" + token + "/" + domain + "/" + service + "/" + primitive;
7006
6958
  };
6959
+ /** @private */
7007
6960
  WebsocketService.prototype.getSubscriptionUrlWithoutToken = function (domain, service, primitive) {
7008
6961
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
7009
6962
  return "/topic/" + tenant + "/" + domain + "/" + service + "/" + primitive;
7010
6963
  };
6964
+ /** @private */
7011
6965
  WebsocketService.prototype.createStompSubscription = function (destination, primitiveManager) {
7012
- var _this = this;
7013
6966
  return this._stompClient.subscribe(destination, function (message) {
7014
6967
  var event = JSON.parse(message.body || "{}");
7015
- _this.addPublishedEvent(primitiveManager, event);
7016
6968
  primitiveManager.subject.next(event);
7017
6969
  });
7018
6970
  };
6971
+ /** @private */
7019
6972
  WebsocketService.prototype.createStompClient = function () {
7020
6973
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
7021
6974
  this._stompClient = stompjs.Stomp.over(ws);
7022
6975
  // this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
7023
6976
  this._stompClient.debug = function () { }; // Para remover os logs.
7024
6977
  };
6978
+ /** @private */
7025
6979
  WebsocketService.prototype.reconnect = function () {
7026
6980
  var _this = this;
7027
6981
  if (this.connected)
@@ -7037,37 +6991,39 @@
7037
6991
  }
7038
6992
  }, WebsocketService_1.RECONNECT_TIMER);
7039
6993
  };
6994
+ /** @private */
7040
6995
  WebsocketService.prototype.reconnectPrimitives = function () {
7041
- var e_6, _a, e_7, _b;
6996
+ var e_4, _a, e_5, _b;
7042
6997
  try {
7043
6998
  for (var _c = __values(this.primitiveManagers.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
7044
6999
  var primitiveManager = _d.value;
7045
7000
  try {
7046
- for (var _e = (e_7 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
7001
+ for (var _e = (e_5 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
7047
7002
  var stompSubscription = _f.value;
7048
7003
  stompSubscription.unsubscribe();
7049
7004
  }
7050
7005
  }
7051
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
7006
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
7052
7007
  finally {
7053
7008
  try {
7054
7009
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
7055
7010
  }
7056
- finally { if (e_7) throw e_7.error; }
7011
+ finally { if (e_5) throw e_5.error; }
7057
7012
  }
7058
7013
  this.createStompSubscriptions(primitiveManager);
7059
7014
  }
7060
7015
  }
7061
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
7016
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
7062
7017
  finally {
7063
7018
  try {
7064
7019
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
7065
7020
  }
7066
- finally { if (e_6) throw e_6.error; }
7021
+ finally { if (e_4) throw e_4.error; }
7067
7022
  }
7068
7023
  };
7024
+ /** @private */
7069
7025
  WebsocketService.prototype.getObserversCount = function () {
7070
- var e_8, _a;
7026
+ var e_6, _a;
7071
7027
  var observersCount = 0;
7072
7028
  try {
7073
7029
  for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -7075,21 +7031,19 @@
7075
7031
  observersCount += primitiveManager.subject.observers.length;
7076
7032
  }
7077
7033
  }
7078
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
7034
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
7079
7035
  finally {
7080
7036
  try {
7081
7037
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7082
7038
  }
7083
- finally { if (e_8) throw e_8.error; }
7039
+ finally { if (e_6) throw e_6.error; }
7084
7040
  }
7085
7041
  return observersCount;
7086
7042
  };
7087
- WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitive) {
7088
- var e_9, _a;
7089
- var primitiveManager = this.primitiveManagers.get(primitive);
7090
- if (!primitiveManager)
7091
- return;
7092
- // @IMPORTANT: Replace .observers.length with .observed in rxjs 7.0+
7043
+ /** @private */
7044
+ WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitiveManager) {
7045
+ var e_7, _a;
7046
+ // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
7093
7047
  var hasObservers = !(primitiveManager.subject.observers.length === 1);
7094
7048
  if (hasObservers)
7095
7049
  return;
@@ -7099,22 +7053,33 @@
7099
7053
  stompSubscription.unsubscribe();
7100
7054
  }
7101
7055
  }
7102
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
7056
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
7103
7057
  finally {
7104
7058
  try {
7105
7059
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7106
7060
  }
7107
- finally { if (e_9) throw e_9.error; }
7061
+ finally { if (e_7) throw e_7.error; }
7108
7062
  }
7109
- this.primitiveManagers.delete(primitive);
7063
+ var key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7064
+ this.primitiveManagers.delete(key);
7110
7065
  this.disconnect();
7111
7066
  };
7067
+ /** @private */
7068
+ WebsocketService.prototype.getPrimitiveManagerKey = function (domain, service, primitive) {
7069
+ return domain + "/" + service + "/" + primitive;
7070
+ };
7112
7071
  var WebsocketService_1;
7072
+ /** @private */
7113
7073
  WebsocketService.RECONNECT_TIMER = 3000;
7074
+ /** @private */
7114
7075
  WebsocketService.CONNECTION_TIMEOUT = 15000;
7076
+ /** @private */
7115
7077
  WebsocketService.BASE_URL_COOKIE = "com.senior.base.url";
7078
+ /** @private */
7116
7079
  WebsocketService.TOKEN_COOKIE = "com.senior.token";
7080
+ /** @private */
7117
7081
  WebsocketService.TOKEN = JSON.parse(jsCookie.get(WebsocketService_1.TOKEN_COOKIE) || "{}");
7082
+ /** @private */
7118
7083
  WebsocketService.WEBSOCKET_URL = jsCookie.get(WebsocketService_1.BASE_URL_COOKIE) + "/websocket/";
7119
7084
  WebsocketService.ɵprov = core.ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
7120
7085
  WebsocketService = WebsocketService_1 = __decorate([