@senior-gestao-empresarial/angular-components 6.8.0 → 6.9.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.
@@ -3,8 +3,8 @@ import { Input, Component, NgModule, Injectable, Inject, ɵɵdefineInjectable,
3
3
  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
- import { Subject, throwError, interval, of, ReplaySubject } from 'rxjs';
7
- import { takeUntil, filter, catchError, map, takeWhile, switchMap, first, finalize, take } from 'rxjs/operators';
6
+ import { Subject, throwError, interval, of, race, timer, iif, fromEvent, ReplaySubject } from 'rxjs';
7
+ import { takeUntil, filter, catchError, map, takeWhile, switchMap, take, finalize, first } 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';
@@ -6977,12 +6977,10 @@ var NpsService = /** @class */ (function () {
6977
6977
 
6978
6978
  var WebsocketService = /** @class */ (function () {
6979
6979
  function WebsocketService() {
6980
- /** @private */
6981
- this.focused = true;
6982
6980
  /** @private */
6983
6981
  this.wasConnected = false;
6984
6982
  /** @private */
6985
- this.connected = false;
6983
+ this.isConnected = false;
6986
6984
  /** @private */
6987
6985
  this.isConnecting = false;
6988
6986
  /** @private */
@@ -6995,23 +6993,19 @@ var WebsocketService = /** @class */ (function () {
6995
6993
  this.reconnect$ = new Subject();
6996
6994
  /** @private */
6997
6995
  this.error$ = new Subject();
6998
- window.onfocus = this.onFocus;
6999
- window.onblur = this.onBlur;
6996
+ this.subscribe$ = new Subject();
7000
6997
  this.connect();
7001
6998
  }
7002
6999
  WebsocketService_1 = WebsocketService;
7003
7000
  /**
7004
- * Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida.
7005
- * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida.
7001
+ * Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida pela primeira vez.
7002
+ * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida pela primeira vez.
7006
7003
  */
7007
7004
  WebsocketService.prototype.onConnect = function () {
7008
- var _this = this;
7009
- setTimeout(function () {
7010
- if (_this.isConnected()) {
7011
- _this.connect$.next();
7012
- }
7013
- }, 0);
7014
- return this.connect$.pipe(first());
7005
+ if (this.isConnected || this.wasConnected) {
7006
+ return of(undefined).pipe(take(1));
7007
+ }
7008
+ return this.connect$.asObservable().pipe(take(1));
7015
7009
  };
7016
7010
  /**
7017
7011
  * Observable responsável por emitir uma notificação quando a conexão é desconectada.
@@ -7028,16 +7022,21 @@ var WebsocketService = /** @class */ (function () {
7028
7022
  return this.reconnect$.asObservable();
7029
7023
  };
7030
7024
  /**
7031
- * Observable responsável por emitir uma notificação após o subscribe do evento.
7032
- * @return Um `Observable<void>` que emite uma notificação após o subscribe do evento.
7025
+ * Observable responsável por emitir uma notificação após o subscribe do evento pela primeira vez.
7026
+ * @return Um `Observable<void>` que emite uma notificação após o subscribe do evento pela primeira vez.
7033
7027
  */
7034
7028
  WebsocketService.prototype.onSubscribe = function (_a) {
7029
+ var _this = this;
7035
7030
  var domain = _a.domain, service = _a.service, primitive = _a.primitive;
7036
- var primitiveManager = this.primitiveManagers.get(this.getPrimitiveManagerKey(domain, service, primitive));
7037
- if (!primitiveManager) {
7038
- throw new Error("No subscription found for " + this.getPrimitiveManagerKey(domain, service, primitive));
7039
- }
7040
- return primitiveManager.subscribe$.asObservable();
7031
+ var key = this.getPrimitiveManagerKey(domain, service, primitive);
7032
+ return this.onConnect().pipe(switchMap(function () {
7033
+ return _this.primitiveManagers.has(key) &&
7034
+ _this.primitiveManagers.get(key).isSubscribed
7035
+ ? of(void 0).pipe(take(1))
7036
+ : _this.subscribe$.pipe(filter(function (primitiveManager) {
7037
+ return _this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive) === key;
7038
+ }), take(1), map(function () { return void 0; }));
7039
+ }));
7041
7040
  };
7042
7041
  /**
7043
7042
  * Observable responsável por emitir uma notificação quando ocorre algum erro.
@@ -7067,14 +7066,16 @@ var WebsocketService = /** @class */ (function () {
7067
7066
  primitive: primitive,
7068
7067
  stompSubscriptions: [],
7069
7068
  event$: new Subject(),
7070
- subscribe$: new ReplaySubject(1)
7069
+ isSubscribed: false
7071
7070
  };
7072
7071
  this.primitiveManagers.set(key, primitiveManager);
7073
- if (this.isConnected()) {
7072
+ if (this.isConnected) {
7074
7073
  this.createStompSubscriptions(primitiveManager);
7075
7074
  return primitiveManager.event$
7076
7075
  .asObservable()
7077
- .pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7076
+ .pipe(finalize(function () {
7077
+ return _this.disconnectPrimitiveOnFinalize(primitiveManager);
7078
+ }));
7078
7079
  }
7079
7080
  else {
7080
7081
  if (!this.isConnecting) {
@@ -7085,7 +7086,9 @@ var WebsocketService = /** @class */ (function () {
7085
7086
  });
7086
7087
  return primitiveManager.event$
7087
7088
  .asObservable()
7088
- .pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7089
+ .pipe(finalize(function () {
7090
+ return _this.disconnectPrimitiveOnFinalize(primitiveManager);
7091
+ }));
7089
7092
  }
7090
7093
  };
7091
7094
  /** @private */
@@ -7094,20 +7097,24 @@ var WebsocketService = /** @class */ (function () {
7094
7097
  var stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
7095
7098
  var withoutTokenUrl = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7096
7099
  var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
7097
- primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
7098
- primitiveManager.subscribe$.next();
7100
+ primitiveManager.stompSubscriptions = [
7101
+ stompSubscriptionWithToken,
7102
+ stompSubscriptionWithoutToken
7103
+ ];
7104
+ primitiveManager.isSubscribed = true;
7105
+ this.subscribe$.next(primitiveManager);
7099
7106
  };
7100
7107
  /** @private */
7101
7108
  WebsocketService.prototype.connect = function () {
7102
7109
  var _this = this;
7103
7110
  this.createStompClient();
7104
7111
  this.isConnecting = true;
7105
- this._stompClient.activate();
7106
7112
  this._stompClient.connect({}, function () {
7107
7113
  _this.isConnecting = false;
7108
- _this.setConnected(true);
7114
+ _this.isConnected = true;
7109
7115
  if (_this.wasConnected) {
7110
7116
  _this.reconnectPrimitives();
7117
+ _this.connect$.next();
7111
7118
  _this.reconnect$.next();
7112
7119
  }
7113
7120
  else {
@@ -7115,24 +7122,28 @@ var WebsocketService = /** @class */ (function () {
7115
7122
  _this.connect$.next();
7116
7123
  }
7117
7124
  }, function (error) {
7118
- _this.setConnected(false);
7125
+ _this.isConnected = false;
7119
7126
  _this.error$.next(error);
7120
- _this.reconnect();
7127
+ race(_this.disconnect$.pipe(take(1), map(function () { return ({ wasDisconnected: true }); })), timer(WebsocketService_1.RECONNECT_INTERVAL).pipe(take(1), switchMap(function () {
7128
+ return iif(function () { return document.hidden; }, fromEvent(document, 'visibilitychange').pipe(first()), of(void 0));
7129
+ }), map(function () { return ({ wasDisconnected: false }); })))
7130
+ .pipe(take(1))
7131
+ .subscribe({
7132
+ next: function (_a) {
7133
+ var wasDisconnected = _a.wasDisconnected;
7134
+ if (!wasDisconnected &&
7135
+ !(_this.isConnected || _this.isConnecting)) {
7136
+ _this.connect();
7137
+ }
7138
+ }
7139
+ });
7121
7140
  });
7122
7141
  };
7123
- /** @private */
7124
- WebsocketService.prototype.onFocus = function () {
7125
- this.focused = true;
7126
- };
7127
- /** @private */
7128
- WebsocketService.prototype.onBlur = function () {
7129
- this.focused = false;
7130
- };
7131
7142
  WebsocketService.prototype.disconnect = function () {
7132
7143
  var e_1, _a, e_2, _b, e_3, _c;
7133
- var observersCount = this.getObserversCount();
7134
- if (observersCount > 0)
7144
+ if (this.getObserversCount() > 0) {
7135
7145
  return;
7146
+ }
7136
7147
  try {
7137
7148
  for (var _d = __values(this.primitiveManagers.values()), _e = _d.next(); !_e.done; _e = _d.next()) {
7138
7149
  var primitiveManager = _e.value;
@@ -7162,7 +7173,6 @@ var WebsocketService = /** @class */ (function () {
7162
7173
  for (var _h = __values(this.primitiveManagers.values()), _j = _h.next(); !_j.done; _j = _h.next()) {
7163
7174
  var primitiveManager = _j.value;
7164
7175
  primitiveManager.event$.complete();
7165
- primitiveManager.subscribe$.complete();
7166
7176
  }
7167
7177
  }
7168
7178
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -7175,34 +7185,32 @@ var WebsocketService = /** @class */ (function () {
7175
7185
  this.primitiveManagers.clear();
7176
7186
  this._stompClient.disconnect();
7177
7187
  this._stompClient.deactivate();
7178
- this.setConnected(false);
7188
+ this.isConnected = false;
7179
7189
  this.isConnecting = false;
7180
7190
  this.wasConnected = false;
7181
7191
  this.disconnect$.next();
7182
7192
  };
7183
7193
  /** @private */
7184
- WebsocketService.prototype.isConnected = function () {
7185
- return this.connected;
7186
- };
7187
- /** @private */
7188
- WebsocketService.prototype.setConnected = function (connected) {
7189
- this.connected = connected;
7190
- };
7191
- /** @private */
7192
7194
  WebsocketService.prototype.getSubscriptionUrlWithToken = function (domain, service, primitive) {
7193
- var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
7194
- var token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
7195
+ var tenant = WebsocketService_1.TOKEN
7196
+ ? WebsocketService_1.TOKEN.username.split('@')[1]
7197
+ : null;
7198
+ var token = WebsocketService_1.TOKEN
7199
+ ? WebsocketService_1.TOKEN.access_token
7200
+ : null;
7195
7201
  return "/topic/" + tenant + "/" + token + "/" + domain + "/" + service + "/" + primitive;
7196
7202
  };
7197
7203
  /** @private */
7198
7204
  WebsocketService.prototype.getSubscriptionUrlWithoutToken = function (domain, service, primitive) {
7199
- var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
7205
+ var tenant = WebsocketService_1.TOKEN
7206
+ ? WebsocketService_1.TOKEN.username.split('@')[1]
7207
+ : null;
7200
7208
  return "/topic/" + tenant + "/" + domain + "/" + service + "/" + primitive;
7201
7209
  };
7202
7210
  /** @private */
7203
7211
  WebsocketService.prototype.createStompSubscription = function (destination, primitiveManager) {
7204
7212
  return this._stompClient.subscribe(destination, function (message) {
7205
- var event = JSON.parse(message.body || "{}");
7213
+ var event = JSON.parse(message.body || '{}');
7206
7214
  primitiveManager.event$.next(event);
7207
7215
  });
7208
7216
  };
@@ -7210,58 +7218,28 @@ var WebsocketService = /** @class */ (function () {
7210
7218
  WebsocketService.prototype.createStompClient = function () {
7211
7219
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
7212
7220
  this._stompClient = Stomp.over(ws);
7213
- // this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
7214
- this._stompClient.debug = function () { }; // Para remover os logs.
7215
- };
7216
- /** @private */
7217
- WebsocketService.prototype.reconnect = function () {
7218
- var _this = this;
7219
- if (this.connected)
7220
- this._stompClient.disconnect();
7221
- setTimeout(function () {
7222
- if (_this.getObserversCount() === 0)
7223
- return;
7224
- if (_this.focused) {
7225
- _this.connect();
7226
- }
7227
- else {
7228
- _this.reconnect();
7229
- }
7230
- }, WebsocketService_1.RECONNECT_TIMER);
7221
+ this._stompClient.debug = function () { return null; };
7231
7222
  };
7232
7223
  /** @private */
7233
7224
  WebsocketService.prototype.reconnectPrimitives = function () {
7234
- var e_4, _a, e_5, _b;
7225
+ var e_4, _a;
7235
7226
  try {
7236
- for (var _c = __values(this.primitiveManagers.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
7237
- var primitiveManager = _d.value;
7238
- try {
7239
- for (var _e = (e_5 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
7240
- var stompSubscription = _f.value;
7241
- stompSubscription.unsubscribe();
7242
- }
7243
- }
7244
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
7245
- finally {
7246
- try {
7247
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
7248
- }
7249
- finally { if (e_5) throw e_5.error; }
7250
- }
7227
+ for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
7228
+ var primitiveManager = _c.value;
7251
7229
  this.createStompSubscriptions(primitiveManager);
7252
7230
  }
7253
7231
  }
7254
7232
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
7255
7233
  finally {
7256
7234
  try {
7257
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
7235
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7258
7236
  }
7259
7237
  finally { if (e_4) throw e_4.error; }
7260
7238
  }
7261
7239
  };
7262
7240
  /** @private */
7263
7241
  WebsocketService.prototype.getObserversCount = function () {
7264
- var e_6, _a;
7242
+ var e_5, _a;
7265
7243
  var observersCount = 0;
7266
7244
  try {
7267
7245
  for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -7269,36 +7247,35 @@ var WebsocketService = /** @class */ (function () {
7269
7247
  observersCount += primitiveManager.event$.observers.length;
7270
7248
  }
7271
7249
  }
7272
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
7250
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
7273
7251
  finally {
7274
7252
  try {
7275
7253
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7276
7254
  }
7277
- finally { if (e_6) throw e_6.error; }
7255
+ finally { if (e_5) throw e_5.error; }
7278
7256
  }
7279
7257
  return observersCount;
7280
7258
  };
7281
7259
  /** @private */
7282
7260
  WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitiveManager) {
7283
- var e_7, _a;
7261
+ var e_6, _a;
7284
7262
  // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
7285
7263
  var hasObservers = !(primitiveManager.event$.observers.length === 1);
7286
7264
  if (hasObservers)
7287
7265
  return;
7288
7266
  primitiveManager.event$.complete();
7289
- primitiveManager.subscribe$.complete();
7290
7267
  try {
7291
7268
  for (var _b = __values(primitiveManager.stompSubscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
7292
7269
  var stompSubscription = _c.value;
7293
7270
  stompSubscription.unsubscribe();
7294
7271
  }
7295
7272
  }
7296
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
7273
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
7297
7274
  finally {
7298
7275
  try {
7299
7276
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7300
7277
  }
7301
- finally { if (e_7) throw e_7.error; }
7278
+ finally { if (e_6) throw e_6.error; }
7302
7279
  }
7303
7280
  var key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7304
7281
  this.primitiveManagers.delete(key);
@@ -7309,22 +7286,20 @@ var WebsocketService = /** @class */ (function () {
7309
7286
  return domain + "/" + service + "/" + primitive;
7310
7287
  };
7311
7288
  var WebsocketService_1;
7312
- /** @private */
7313
- WebsocketService.RECONNECT_TIMER = 3000;
7314
- /** @private */
7289
+ WebsocketService.RECONNECT_INTERVAL = 3000;
7315
7290
  WebsocketService.CONNECTION_TIMEOUT = 15000;
7316
7291
  /** @private */
7317
- WebsocketService.BASE_URL_COOKIE = "com.senior.base.url";
7292
+ WebsocketService.BASE_URL_COOKIE = 'com.senior.base.url';
7318
7293
  /** @private */
7319
- WebsocketService.TOKEN_COOKIE = "com.senior.token";
7294
+ WebsocketService.TOKEN_COOKIE = 'com.senior.token';
7320
7295
  /** @private */
7321
- WebsocketService.TOKEN = JSON.parse(get(WebsocketService_1.TOKEN_COOKIE) || "{}");
7296
+ WebsocketService.TOKEN = JSON.parse(get(WebsocketService_1.TOKEN_COOKIE) || '{}');
7322
7297
  /** @private */
7323
- WebsocketService.WEBSOCKET_URL = get(WebsocketService_1.BASE_URL_COOKIE) + "/websocket/";
7298
+ WebsocketService.WEBSOCKET_URL = get(WebsocketService_1.BASE_URL_COOKIE) + '/websocket/';
7324
7299
  WebsocketService.ɵprov = ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
7325
7300
  WebsocketService = WebsocketService_1 = __decorate([
7326
7301
  Injectable({
7327
- providedIn: "root",
7302
+ providedIn: 'root'
7328
7303
  })
7329
7304
  ], WebsocketService);
7330
7305
  return WebsocketService;