@senior-gestao-empresarial/angular-components 6.8.0 → 6.9.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.
@@ -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, timer, iif, fromEvent, EMPTY, 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,15 +6977,15 @@ 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 */
6987
+ this.isReconnecting = false;
6988
+ /** @private */
6989
6989
  this.primitiveManagers = new Map();
6990
6990
  /** @private */
6991
6991
  this.connect$ = new Subject();
@@ -6995,23 +6995,19 @@ var WebsocketService = /** @class */ (function () {
6995
6995
  this.reconnect$ = new Subject();
6996
6996
  /** @private */
6997
6997
  this.error$ = new Subject();
6998
- window.onfocus = this.onFocus;
6999
- window.onblur = this.onBlur;
6998
+ this.subscribe$ = new Subject();
7000
6999
  this.connect();
7001
7000
  }
7002
7001
  WebsocketService_1 = WebsocketService;
7003
7002
  /**
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.
7003
+ * Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida pela primeira vez.
7004
+ * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida pela primeira vez.
7006
7005
  */
7007
7006
  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());
7007
+ if (this.isConnected || this.wasConnected) {
7008
+ return of(undefined).pipe(take(1));
7009
+ }
7010
+ return this.connect$.asObservable().pipe(take(1));
7015
7011
  };
7016
7012
  /**
7017
7013
  * Observable responsável por emitir uma notificação quando a conexão é desconectada.
@@ -7028,16 +7024,20 @@ var WebsocketService = /** @class */ (function () {
7028
7024
  return this.reconnect$.asObservable();
7029
7025
  };
7030
7026
  /**
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.
7027
+ * Observable responsável por emitir uma notificação após o subscribe do evento pela primeira vez.
7028
+ * @return Um `Observable<void>` que emite uma notificação após o subscribe do evento pela primeira vez.
7033
7029
  */
7034
7030
  WebsocketService.prototype.onSubscribe = function (_a) {
7031
+ var _this = this;
7035
7032
  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();
7033
+ var key = this.getPrimitiveManagerKey(domain, service, primitive);
7034
+ return this.onConnect().pipe(switchMap(function () {
7035
+ return _this.primitiveManagers.has(key) && _this.primitiveManagers.get(key).isSubscribed
7036
+ ? of(void 0).pipe(take(1))
7037
+ : _this.subscribe$.pipe(filter(function (primitiveManager) {
7038
+ return _this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive) === key;
7039
+ }), take(1), (map(function () { return void 0; })));
7040
+ }));
7041
7041
  };
7042
7042
  /**
7043
7043
  * Observable responsável por emitir uma notificação quando ocorre algum erro.
@@ -7067,25 +7067,21 @@ var WebsocketService = /** @class */ (function () {
7067
7067
  primitive: primitive,
7068
7068
  stompSubscriptions: [],
7069
7069
  event$: new Subject(),
7070
- subscribe$: new ReplaySubject(1)
7070
+ isSubscribed: false,
7071
7071
  };
7072
7072
  this.primitiveManagers.set(key, primitiveManager);
7073
- if (this.isConnected()) {
7073
+ if (this.isConnected) {
7074
7074
  this.createStompSubscriptions(primitiveManager);
7075
- return primitiveManager.event$
7076
- .asObservable()
7077
- .pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7075
+ return primitiveManager.event$.asObservable().pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7078
7076
  }
7079
7077
  else {
7080
- if (!this.isConnecting) {
7078
+ if (!this.isReconnecting && !this.isConnecting) {
7081
7079
  this.connect();
7082
7080
  }
7083
7081
  this.connect$.pipe(first()).subscribe(function () {
7084
7082
  _this.createStompSubscriptions(primitiveManager);
7085
7083
  });
7086
- return primitiveManager.event$
7087
- .asObservable()
7088
- .pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7084
+ return primitiveManager.event$.asObservable().pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7089
7085
  }
7090
7086
  };
7091
7087
  /** @private */
@@ -7095,19 +7091,21 @@ var WebsocketService = /** @class */ (function () {
7095
7091
  var withoutTokenUrl = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7096
7092
  var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
7097
7093
  primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
7098
- primitiveManager.subscribe$.next();
7094
+ primitiveManager.isSubscribed = true;
7095
+ this.subscribe$.next(primitiveManager);
7099
7096
  };
7100
7097
  /** @private */
7101
7098
  WebsocketService.prototype.connect = function () {
7102
7099
  var _this = this;
7103
7100
  this.createStompClient();
7104
7101
  this.isConnecting = true;
7105
- this._stompClient.activate();
7106
7102
  this._stompClient.connect({}, function () {
7107
7103
  _this.isConnecting = false;
7108
- _this.setConnected(true);
7104
+ _this.isReconnecting = false;
7105
+ _this.isConnected = true;
7109
7106
  if (_this.wasConnected) {
7110
7107
  _this.reconnectPrimitives();
7108
+ _this.connect$.next();
7111
7109
  _this.reconnect$.next();
7112
7110
  }
7113
7111
  else {
@@ -7115,19 +7113,16 @@ var WebsocketService = /** @class */ (function () {
7115
7113
  _this.connect$.next();
7116
7114
  }
7117
7115
  }, function (error) {
7118
- _this.setConnected(false);
7116
+ _this.isConnected = false;
7119
7117
  _this.error$.next(error);
7120
- _this.reconnect();
7118
+ _this.isReconnecting = true;
7119
+ timer(WebsocketService_1.RECONNECT_INTERVAL)
7120
+ .pipe(switchMap(function () {
7121
+ return iif(function () { return document.hidden; }, fromEvent(document, "visibilitychange").pipe(first()), EMPTY);
7122
+ }))
7123
+ .subscribe({ complete: function () { return _this.connect(); } });
7121
7124
  });
7122
7125
  };
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
7126
  WebsocketService.prototype.disconnect = function () {
7132
7127
  var e_1, _a, e_2, _b, e_3, _c;
7133
7128
  var observersCount = this.getObserversCount();
@@ -7162,7 +7157,6 @@ var WebsocketService = /** @class */ (function () {
7162
7157
  for (var _h = __values(this.primitiveManagers.values()), _j = _h.next(); !_j.done; _j = _h.next()) {
7163
7158
  var primitiveManager = _j.value;
7164
7159
  primitiveManager.event$.complete();
7165
- primitiveManager.subscribe$.complete();
7166
7160
  }
7167
7161
  }
7168
7162
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -7175,20 +7169,12 @@ var WebsocketService = /** @class */ (function () {
7175
7169
  this.primitiveManagers.clear();
7176
7170
  this._stompClient.disconnect();
7177
7171
  this._stompClient.deactivate();
7178
- this.setConnected(false);
7172
+ this.isConnected = false;
7179
7173
  this.isConnecting = false;
7180
7174
  this.wasConnected = false;
7181
7175
  this.disconnect$.next();
7182
7176
  };
7183
7177
  /** @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
7178
  WebsocketService.prototype.getSubscriptionUrlWithToken = function (domain, service, primitive) {
7193
7179
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
7194
7180
  var token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
@@ -7210,58 +7196,28 @@ var WebsocketService = /** @class */ (function () {
7210
7196
  WebsocketService.prototype.createStompClient = function () {
7211
7197
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
7212
7198
  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);
7199
+ this._stompClient.debug = function () { return null; };
7231
7200
  };
7232
7201
  /** @private */
7233
7202
  WebsocketService.prototype.reconnectPrimitives = function () {
7234
- var e_4, _a, e_5, _b;
7203
+ var e_4, _a;
7235
7204
  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
- }
7205
+ for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
7206
+ var primitiveManager = _c.value;
7251
7207
  this.createStompSubscriptions(primitiveManager);
7252
7208
  }
7253
7209
  }
7254
7210
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
7255
7211
  finally {
7256
7212
  try {
7257
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
7213
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7258
7214
  }
7259
7215
  finally { if (e_4) throw e_4.error; }
7260
7216
  }
7261
7217
  };
7262
7218
  /** @private */
7263
7219
  WebsocketService.prototype.getObserversCount = function () {
7264
- var e_6, _a;
7220
+ var e_5, _a;
7265
7221
  var observersCount = 0;
7266
7222
  try {
7267
7223
  for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -7269,36 +7225,35 @@ var WebsocketService = /** @class */ (function () {
7269
7225
  observersCount += primitiveManager.event$.observers.length;
7270
7226
  }
7271
7227
  }
7272
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
7228
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
7273
7229
  finally {
7274
7230
  try {
7275
7231
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7276
7232
  }
7277
- finally { if (e_6) throw e_6.error; }
7233
+ finally { if (e_5) throw e_5.error; }
7278
7234
  }
7279
7235
  return observersCount;
7280
7236
  };
7281
7237
  /** @private */
7282
7238
  WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitiveManager) {
7283
- var e_7, _a;
7239
+ var e_6, _a;
7284
7240
  // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
7285
7241
  var hasObservers = !(primitiveManager.event$.observers.length === 1);
7286
7242
  if (hasObservers)
7287
7243
  return;
7288
7244
  primitiveManager.event$.complete();
7289
- primitiveManager.subscribe$.complete();
7290
7245
  try {
7291
7246
  for (var _b = __values(primitiveManager.stompSubscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
7292
7247
  var stompSubscription = _c.value;
7293
7248
  stompSubscription.unsubscribe();
7294
7249
  }
7295
7250
  }
7296
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
7251
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
7297
7252
  finally {
7298
7253
  try {
7299
7254
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7300
7255
  }
7301
- finally { if (e_7) throw e_7.error; }
7256
+ finally { if (e_6) throw e_6.error; }
7302
7257
  }
7303
7258
  var key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7304
7259
  this.primitiveManagers.delete(key);
@@ -7310,7 +7265,7 @@ var WebsocketService = /** @class */ (function () {
7310
7265
  };
7311
7266
  var WebsocketService_1;
7312
7267
  /** @private */
7313
- WebsocketService.RECONNECT_TIMER = 3000;
7268
+ WebsocketService.RECONNECT_INTERVAL = 3000;
7314
7269
  /** @private */
7315
7270
  WebsocketService.CONNECTION_TIMEOUT = 15000;
7316
7271
  /** @private */