@senior-gestao-empresarial/angular-components 6.7.1 → 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.
@@ -7183,15 +7183,15 @@
7183
7183
 
7184
7184
  var WebsocketService = /** @class */ (function () {
7185
7185
  function WebsocketService() {
7186
- /** @private */
7187
- this.focused = true;
7188
7186
  /** @private */
7189
7187
  this.wasConnected = false;
7190
7188
  /** @private */
7191
- this.connected = false;
7189
+ this.isConnected = false;
7192
7190
  /** @private */
7193
7191
  this.isConnecting = false;
7194
7192
  /** @private */
7193
+ this.isReconnecting = false;
7194
+ /** @private */
7195
7195
  this.primitiveManagers = new Map();
7196
7196
  /** @private */
7197
7197
  this.connect$ = new rxjs.Subject();
@@ -7201,23 +7201,19 @@
7201
7201
  this.reconnect$ = new rxjs.Subject();
7202
7202
  /** @private */
7203
7203
  this.error$ = new rxjs.Subject();
7204
- window.onfocus = this.onFocus;
7205
- window.onblur = this.onBlur;
7204
+ this.subscribe$ = new rxjs.Subject();
7206
7205
  this.connect();
7207
7206
  }
7208
7207
  WebsocketService_1 = WebsocketService;
7209
7208
  /**
7210
- * Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida.
7211
- * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida.
7209
+ * Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida pela primeira vez.
7210
+ * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida pela primeira vez.
7212
7211
  */
7213
7212
  WebsocketService.prototype.onConnect = function () {
7214
- var _this = this;
7215
- setTimeout(function () {
7216
- if (_this.isConnected()) {
7217
- _this.connect$.next();
7218
- }
7219
- }, 0);
7220
- return this.connect$.pipe(operators.first());
7213
+ if (this.isConnected || this.wasConnected) {
7214
+ return rxjs.of(undefined).pipe(operators.take(1));
7215
+ }
7216
+ return this.connect$.asObservable().pipe(operators.take(1));
7221
7217
  };
7222
7218
  /**
7223
7219
  * Observable responsável por emitir uma notificação quando a conexão é desconectada.
@@ -7233,6 +7229,22 @@
7233
7229
  WebsocketService.prototype.onReconnect = function () {
7234
7230
  return this.reconnect$.asObservable();
7235
7231
  };
7232
+ /**
7233
+ * Observable responsável por emitir uma notificação após o subscribe do evento pela primeira vez.
7234
+ * @return Um `Observable<void>` que emite uma notificação após o subscribe do evento pela primeira vez.
7235
+ */
7236
+ WebsocketService.prototype.onSubscribe = function (_a) {
7237
+ var _this = this;
7238
+ var domain = _a.domain, service = _a.service, primitive = _a.primitive;
7239
+ var key = this.getPrimitiveManagerKey(domain, service, primitive);
7240
+ return this.onConnect().pipe(operators.switchMap(function () {
7241
+ return _this.primitiveManagers.has(key) && _this.primitiveManagers.get(key).isSubscribed
7242
+ ? rxjs.of(void 0).pipe(operators.take(1))
7243
+ : _this.subscribe$.pipe(operators.filter(function (primitiveManager) {
7244
+ return _this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive) === key;
7245
+ }), operators.take(1), (operators.map(function () { return void 0; })));
7246
+ }));
7247
+ };
7236
7248
  /**
7237
7249
  * Observable responsável por emitir uma notificação quando ocorre algum erro.
7238
7250
  * @return Um `Observable<FrameImpl>` que emite uma notificação quando ocorre algum erro.
@@ -7253,28 +7265,29 @@
7253
7265
  var domain = options.domain, service = options.service, primitive = options.primitive;
7254
7266
  var key = this.getPrimitiveManagerKey(domain, service, primitive);
7255
7267
  if (this.primitiveManagers.has(key)) {
7256
- return this.primitiveManagers.get(key).subject.asObservable();
7268
+ return this.primitiveManagers.get(key).event$.asObservable();
7257
7269
  }
7258
7270
  var primitiveManager = {
7259
7271
  domain: domain,
7260
7272
  service: service,
7261
7273
  primitive: primitive,
7262
7274
  stompSubscriptions: [],
7263
- subject: new rxjs.Subject(),
7275
+ event$: new rxjs.Subject(),
7276
+ isSubscribed: false,
7264
7277
  };
7265
7278
  this.primitiveManagers.set(key, primitiveManager);
7266
- if (this.isConnected()) {
7279
+ if (this.isConnected) {
7267
7280
  this.createStompSubscriptions(primitiveManager);
7268
- return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7281
+ return primitiveManager.event$.asObservable().pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7269
7282
  }
7270
7283
  else {
7271
- if (!this.isConnecting) {
7284
+ if (!this.isReconnecting && !this.isConnecting) {
7272
7285
  this.connect();
7273
7286
  }
7274
7287
  this.connect$.pipe(operators.first()).subscribe(function () {
7275
7288
  _this.createStompSubscriptions(primitiveManager);
7276
7289
  });
7277
- return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7290
+ return primitiveManager.event$.asObservable().pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7278
7291
  }
7279
7292
  };
7280
7293
  /** @private */
@@ -7284,18 +7297,21 @@
7284
7297
  var withoutTokenUrl = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7285
7298
  var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
7286
7299
  primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
7300
+ primitiveManager.isSubscribed = true;
7301
+ this.subscribe$.next(primitiveManager);
7287
7302
  };
7288
7303
  /** @private */
7289
7304
  WebsocketService.prototype.connect = function () {
7290
7305
  var _this = this;
7291
7306
  this.createStompClient();
7292
7307
  this.isConnecting = true;
7293
- this._stompClient.activate();
7294
7308
  this._stompClient.connect({}, function () {
7295
7309
  _this.isConnecting = false;
7296
- _this.setConnected(true);
7310
+ _this.isReconnecting = false;
7311
+ _this.isConnected = true;
7297
7312
  if (_this.wasConnected) {
7298
7313
  _this.reconnectPrimitives();
7314
+ _this.connect$.next();
7299
7315
  _this.reconnect$.next();
7300
7316
  }
7301
7317
  else {
@@ -7303,19 +7319,16 @@
7303
7319
  _this.connect$.next();
7304
7320
  }
7305
7321
  }, function (error) {
7306
- _this.setConnected(false);
7322
+ _this.isConnected = false;
7307
7323
  _this.error$.next(error);
7308
- _this.reconnect();
7324
+ _this.isReconnecting = true;
7325
+ rxjs.timer(WebsocketService_1.RECONNECT_INTERVAL)
7326
+ .pipe(operators.switchMap(function () {
7327
+ return rxjs.iif(function () { return document.hidden; }, rxjs.fromEvent(document, "visibilitychange").pipe(operators.first()), rxjs.EMPTY);
7328
+ }))
7329
+ .subscribe({ complete: function () { return _this.connect(); } });
7309
7330
  });
7310
7331
  };
7311
- /** @private */
7312
- WebsocketService.prototype.onFocus = function () {
7313
- this.focused = true;
7314
- };
7315
- /** @private */
7316
- WebsocketService.prototype.onBlur = function () {
7317
- this.focused = false;
7318
- };
7319
7332
  WebsocketService.prototype.disconnect = function () {
7320
7333
  var e_1, _a, e_2, _b, e_3, _c;
7321
7334
  var observersCount = this.getObserversCount();
@@ -7349,7 +7362,7 @@
7349
7362
  try {
7350
7363
  for (var _h = __values(this.primitiveManagers.values()), _j = _h.next(); !_j.done; _j = _h.next()) {
7351
7364
  var primitiveManager = _j.value;
7352
- primitiveManager.subject.complete();
7365
+ primitiveManager.event$.complete();
7353
7366
  }
7354
7367
  }
7355
7368
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -7362,20 +7375,12 @@
7362
7375
  this.primitiveManagers.clear();
7363
7376
  this._stompClient.disconnect();
7364
7377
  this._stompClient.deactivate();
7365
- this.setConnected(false);
7378
+ this.isConnected = false;
7366
7379
  this.isConnecting = false;
7367
7380
  this.wasConnected = false;
7368
7381
  this.disconnect$.next();
7369
7382
  };
7370
7383
  /** @private */
7371
- WebsocketService.prototype.isConnected = function () {
7372
- return this.connected;
7373
- };
7374
- /** @private */
7375
- WebsocketService.prototype.setConnected = function (connected) {
7376
- this.connected = connected;
7377
- };
7378
- /** @private */
7379
7384
  WebsocketService.prototype.getSubscriptionUrlWithToken = function (domain, service, primitive) {
7380
7385
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
7381
7386
  var token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
@@ -7390,100 +7395,71 @@
7390
7395
  WebsocketService.prototype.createStompSubscription = function (destination, primitiveManager) {
7391
7396
  return this._stompClient.subscribe(destination, function (message) {
7392
7397
  var event = JSON.parse(message.body || "{}");
7393
- primitiveManager.subject.next(event);
7398
+ primitiveManager.event$.next(event);
7394
7399
  });
7395
7400
  };
7396
7401
  /** @private */
7397
7402
  WebsocketService.prototype.createStompClient = function () {
7398
7403
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
7399
7404
  this._stompClient = stompjs.Stomp.over(ws);
7400
- // this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
7401
- this._stompClient.debug = function () { }; // Para remover os logs.
7402
- };
7403
- /** @private */
7404
- WebsocketService.prototype.reconnect = function () {
7405
- var _this = this;
7406
- if (this.connected)
7407
- this._stompClient.disconnect();
7408
- setTimeout(function () {
7409
- if (_this.getObserversCount() === 0)
7410
- return;
7411
- if (_this.focused) {
7412
- _this.connect();
7413
- }
7414
- else {
7415
- _this.reconnect();
7416
- }
7417
- }, WebsocketService_1.RECONNECT_TIMER);
7405
+ this._stompClient.debug = function () { return null; };
7418
7406
  };
7419
7407
  /** @private */
7420
7408
  WebsocketService.prototype.reconnectPrimitives = function () {
7421
- var e_4, _a, e_5, _b;
7409
+ var e_4, _a;
7422
7410
  try {
7423
- for (var _c = __values(this.primitiveManagers.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
7424
- var primitiveManager = _d.value;
7425
- try {
7426
- for (var _e = (e_5 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
7427
- var stompSubscription = _f.value;
7428
- stompSubscription.unsubscribe();
7429
- }
7430
- }
7431
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
7432
- finally {
7433
- try {
7434
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
7435
- }
7436
- finally { if (e_5) throw e_5.error; }
7437
- }
7411
+ for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
7412
+ var primitiveManager = _c.value;
7438
7413
  this.createStompSubscriptions(primitiveManager);
7439
7414
  }
7440
7415
  }
7441
7416
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
7442
7417
  finally {
7443
7418
  try {
7444
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
7419
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7445
7420
  }
7446
7421
  finally { if (e_4) throw e_4.error; }
7447
7422
  }
7448
7423
  };
7449
7424
  /** @private */
7450
7425
  WebsocketService.prototype.getObserversCount = function () {
7451
- var e_6, _a;
7426
+ var e_5, _a;
7452
7427
  var observersCount = 0;
7453
7428
  try {
7454
7429
  for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
7455
7430
  var primitiveManager = _c.value;
7456
- observersCount += primitiveManager.subject.observers.length;
7431
+ observersCount += primitiveManager.event$.observers.length;
7457
7432
  }
7458
7433
  }
7459
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
7434
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
7460
7435
  finally {
7461
7436
  try {
7462
7437
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7463
7438
  }
7464
- finally { if (e_6) throw e_6.error; }
7439
+ finally { if (e_5) throw e_5.error; }
7465
7440
  }
7466
7441
  return observersCount;
7467
7442
  };
7468
7443
  /** @private */
7469
7444
  WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitiveManager) {
7470
- var e_7, _a;
7445
+ var e_6, _a;
7471
7446
  // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
7472
- var hasObservers = !(primitiveManager.subject.observers.length === 1);
7447
+ var hasObservers = !(primitiveManager.event$.observers.length === 1);
7473
7448
  if (hasObservers)
7474
7449
  return;
7450
+ primitiveManager.event$.complete();
7475
7451
  try {
7476
7452
  for (var _b = __values(primitiveManager.stompSubscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
7477
7453
  var stompSubscription = _c.value;
7478
7454
  stompSubscription.unsubscribe();
7479
7455
  }
7480
7456
  }
7481
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
7457
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
7482
7458
  finally {
7483
7459
  try {
7484
7460
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7485
7461
  }
7486
- finally { if (e_7) throw e_7.error; }
7462
+ finally { if (e_6) throw e_6.error; }
7487
7463
  }
7488
7464
  var key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7489
7465
  this.primitiveManagers.delete(key);
@@ -7495,7 +7471,7 @@
7495
7471
  };
7496
7472
  var WebsocketService_1;
7497
7473
  /** @private */
7498
- WebsocketService.RECONNECT_TIMER = 3000;
7474
+ WebsocketService.RECONNECT_INTERVAL = 3000;
7499
7475
  /** @private */
7500
7476
  WebsocketService.CONNECTION_TIMEOUT = 15000;
7501
7477
  /** @private */