@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.
@@ -7183,12 +7183,10 @@
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 */
@@ -7201,23 +7199,19 @@
7201
7199
  this.reconnect$ = new rxjs.Subject();
7202
7200
  /** @private */
7203
7201
  this.error$ = new rxjs.Subject();
7204
- window.onfocus = this.onFocus;
7205
- window.onblur = this.onBlur;
7202
+ this.subscribe$ = new rxjs.Subject();
7206
7203
  this.connect();
7207
7204
  }
7208
7205
  WebsocketService_1 = WebsocketService;
7209
7206
  /**
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.
7207
+ * Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida pela primeira vez.
7208
+ * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida pela primeira vez.
7212
7209
  */
7213
7210
  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());
7211
+ if (this.isConnected || this.wasConnected) {
7212
+ return rxjs.of(undefined).pipe(operators.take(1));
7213
+ }
7214
+ return this.connect$.asObservable().pipe(operators.take(1));
7221
7215
  };
7222
7216
  /**
7223
7217
  * Observable responsável por emitir uma notificação quando a conexão é desconectada.
@@ -7234,16 +7228,21 @@
7234
7228
  return this.reconnect$.asObservable();
7235
7229
  };
7236
7230
  /**
7237
- * Observable responsável por emitir uma notificação após o subscribe do evento.
7238
- * @return Um `Observable<void>` que emite uma notificação após o subscribe do evento.
7231
+ * Observable responsável por emitir uma notificação após o subscribe do evento pela primeira vez.
7232
+ * @return Um `Observable<void>` que emite uma notificação após o subscribe do evento pela primeira vez.
7239
7233
  */
7240
7234
  WebsocketService.prototype.onSubscribe = function (_a) {
7235
+ var _this = this;
7241
7236
  var domain = _a.domain, service = _a.service, primitive = _a.primitive;
7242
- var primitiveManager = this.primitiveManagers.get(this.getPrimitiveManagerKey(domain, service, primitive));
7243
- if (!primitiveManager) {
7244
- throw new Error("No subscription found for " + this.getPrimitiveManagerKey(domain, service, primitive));
7245
- }
7246
- return primitiveManager.subscribe$.asObservable();
7237
+ var key = this.getPrimitiveManagerKey(domain, service, primitive);
7238
+ return this.onConnect().pipe(operators.switchMap(function () {
7239
+ return _this.primitiveManagers.has(key) &&
7240
+ _this.primitiveManagers.get(key).isSubscribed
7241
+ ? rxjs.of(void 0).pipe(operators.take(1))
7242
+ : _this.subscribe$.pipe(operators.filter(function (primitiveManager) {
7243
+ return _this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive) === key;
7244
+ }), operators.take(1), operators.map(function () { return void 0; }));
7245
+ }));
7247
7246
  };
7248
7247
  /**
7249
7248
  * Observable responsável por emitir uma notificação quando ocorre algum erro.
@@ -7273,14 +7272,16 @@
7273
7272
  primitive: primitive,
7274
7273
  stompSubscriptions: [],
7275
7274
  event$: new rxjs.Subject(),
7276
- subscribe$: new rxjs.ReplaySubject(1)
7275
+ isSubscribed: false
7277
7276
  };
7278
7277
  this.primitiveManagers.set(key, primitiveManager);
7279
- if (this.isConnected()) {
7278
+ if (this.isConnected) {
7280
7279
  this.createStompSubscriptions(primitiveManager);
7281
7280
  return primitiveManager.event$
7282
7281
  .asObservable()
7283
- .pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7282
+ .pipe(operators.finalize(function () {
7283
+ return _this.disconnectPrimitiveOnFinalize(primitiveManager);
7284
+ }));
7284
7285
  }
7285
7286
  else {
7286
7287
  if (!this.isConnecting) {
@@ -7291,7 +7292,9 @@
7291
7292
  });
7292
7293
  return primitiveManager.event$
7293
7294
  .asObservable()
7294
- .pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
7295
+ .pipe(operators.finalize(function () {
7296
+ return _this.disconnectPrimitiveOnFinalize(primitiveManager);
7297
+ }));
7295
7298
  }
7296
7299
  };
7297
7300
  /** @private */
@@ -7300,20 +7303,24 @@
7300
7303
  var stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
7301
7304
  var withoutTokenUrl = this.getSubscriptionUrlWithoutToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7302
7305
  var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
7303
- primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
7304
- primitiveManager.subscribe$.next();
7306
+ primitiveManager.stompSubscriptions = [
7307
+ stompSubscriptionWithToken,
7308
+ stompSubscriptionWithoutToken
7309
+ ];
7310
+ primitiveManager.isSubscribed = true;
7311
+ this.subscribe$.next(primitiveManager);
7305
7312
  };
7306
7313
  /** @private */
7307
7314
  WebsocketService.prototype.connect = function () {
7308
7315
  var _this = this;
7309
7316
  this.createStompClient();
7310
7317
  this.isConnecting = true;
7311
- this._stompClient.activate();
7312
7318
  this._stompClient.connect({}, function () {
7313
7319
  _this.isConnecting = false;
7314
- _this.setConnected(true);
7320
+ _this.isConnected = true;
7315
7321
  if (_this.wasConnected) {
7316
7322
  _this.reconnectPrimitives();
7323
+ _this.connect$.next();
7317
7324
  _this.reconnect$.next();
7318
7325
  }
7319
7326
  else {
@@ -7321,24 +7328,28 @@
7321
7328
  _this.connect$.next();
7322
7329
  }
7323
7330
  }, function (error) {
7324
- _this.setConnected(false);
7331
+ _this.isConnected = false;
7325
7332
  _this.error$.next(error);
7326
- _this.reconnect();
7333
+ rxjs.race(_this.disconnect$.pipe(operators.take(1), operators.map(function () { return ({ wasDisconnected: true }); })), rxjs.timer(WebsocketService_1.RECONNECT_INTERVAL).pipe(operators.take(1), operators.switchMap(function () {
7334
+ return rxjs.iif(function () { return document.hidden; }, rxjs.fromEvent(document, 'visibilitychange').pipe(operators.first()), rxjs.of(void 0));
7335
+ }), operators.map(function () { return ({ wasDisconnected: false }); })))
7336
+ .pipe(operators.take(1))
7337
+ .subscribe({
7338
+ next: function (_a) {
7339
+ var wasDisconnected = _a.wasDisconnected;
7340
+ if (!wasDisconnected &&
7341
+ !(_this.isConnected || _this.isConnecting)) {
7342
+ _this.connect();
7343
+ }
7344
+ }
7345
+ });
7327
7346
  });
7328
7347
  };
7329
- /** @private */
7330
- WebsocketService.prototype.onFocus = function () {
7331
- this.focused = true;
7332
- };
7333
- /** @private */
7334
- WebsocketService.prototype.onBlur = function () {
7335
- this.focused = false;
7336
- };
7337
7348
  WebsocketService.prototype.disconnect = function () {
7338
7349
  var e_1, _a, e_2, _b, e_3, _c;
7339
- var observersCount = this.getObserversCount();
7340
- if (observersCount > 0)
7350
+ if (this.getObserversCount() > 0) {
7341
7351
  return;
7352
+ }
7342
7353
  try {
7343
7354
  for (var _d = __values(this.primitiveManagers.values()), _e = _d.next(); !_e.done; _e = _d.next()) {
7344
7355
  var primitiveManager = _e.value;
@@ -7368,7 +7379,6 @@
7368
7379
  for (var _h = __values(this.primitiveManagers.values()), _j = _h.next(); !_j.done; _j = _h.next()) {
7369
7380
  var primitiveManager = _j.value;
7370
7381
  primitiveManager.event$.complete();
7371
- primitiveManager.subscribe$.complete();
7372
7382
  }
7373
7383
  }
7374
7384
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
@@ -7381,34 +7391,32 @@
7381
7391
  this.primitiveManagers.clear();
7382
7392
  this._stompClient.disconnect();
7383
7393
  this._stompClient.deactivate();
7384
- this.setConnected(false);
7394
+ this.isConnected = false;
7385
7395
  this.isConnecting = false;
7386
7396
  this.wasConnected = false;
7387
7397
  this.disconnect$.next();
7388
7398
  };
7389
7399
  /** @private */
7390
- WebsocketService.prototype.isConnected = function () {
7391
- return this.connected;
7392
- };
7393
- /** @private */
7394
- WebsocketService.prototype.setConnected = function (connected) {
7395
- this.connected = connected;
7396
- };
7397
- /** @private */
7398
7400
  WebsocketService.prototype.getSubscriptionUrlWithToken = function (domain, service, primitive) {
7399
- var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
7400
- var token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
7401
+ var tenant = WebsocketService_1.TOKEN
7402
+ ? WebsocketService_1.TOKEN.username.split('@')[1]
7403
+ : null;
7404
+ var token = WebsocketService_1.TOKEN
7405
+ ? WebsocketService_1.TOKEN.access_token
7406
+ : null;
7401
7407
  return "/topic/" + tenant + "/" + token + "/" + domain + "/" + service + "/" + primitive;
7402
7408
  };
7403
7409
  /** @private */
7404
7410
  WebsocketService.prototype.getSubscriptionUrlWithoutToken = function (domain, service, primitive) {
7405
- var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
7411
+ var tenant = WebsocketService_1.TOKEN
7412
+ ? WebsocketService_1.TOKEN.username.split('@')[1]
7413
+ : null;
7406
7414
  return "/topic/" + tenant + "/" + domain + "/" + service + "/" + primitive;
7407
7415
  };
7408
7416
  /** @private */
7409
7417
  WebsocketService.prototype.createStompSubscription = function (destination, primitiveManager) {
7410
7418
  return this._stompClient.subscribe(destination, function (message) {
7411
- var event = JSON.parse(message.body || "{}");
7419
+ var event = JSON.parse(message.body || '{}');
7412
7420
  primitiveManager.event$.next(event);
7413
7421
  });
7414
7422
  };
@@ -7416,58 +7424,28 @@
7416
7424
  WebsocketService.prototype.createStompClient = function () {
7417
7425
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
7418
7426
  this._stompClient = stompjs.Stomp.over(ws);
7419
- // this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
7420
- this._stompClient.debug = function () { }; // Para remover os logs.
7421
- };
7422
- /** @private */
7423
- WebsocketService.prototype.reconnect = function () {
7424
- var _this = this;
7425
- if (this.connected)
7426
- this._stompClient.disconnect();
7427
- setTimeout(function () {
7428
- if (_this.getObserversCount() === 0)
7429
- return;
7430
- if (_this.focused) {
7431
- _this.connect();
7432
- }
7433
- else {
7434
- _this.reconnect();
7435
- }
7436
- }, WebsocketService_1.RECONNECT_TIMER);
7427
+ this._stompClient.debug = function () { return null; };
7437
7428
  };
7438
7429
  /** @private */
7439
7430
  WebsocketService.prototype.reconnectPrimitives = function () {
7440
- var e_4, _a, e_5, _b;
7431
+ var e_4, _a;
7441
7432
  try {
7442
- for (var _c = __values(this.primitiveManagers.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
7443
- var primitiveManager = _d.value;
7444
- try {
7445
- for (var _e = (e_5 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
7446
- var stompSubscription = _f.value;
7447
- stompSubscription.unsubscribe();
7448
- }
7449
- }
7450
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
7451
- finally {
7452
- try {
7453
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
7454
- }
7455
- finally { if (e_5) throw e_5.error; }
7456
- }
7433
+ for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
7434
+ var primitiveManager = _c.value;
7457
7435
  this.createStompSubscriptions(primitiveManager);
7458
7436
  }
7459
7437
  }
7460
7438
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
7461
7439
  finally {
7462
7440
  try {
7463
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
7441
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7464
7442
  }
7465
7443
  finally { if (e_4) throw e_4.error; }
7466
7444
  }
7467
7445
  };
7468
7446
  /** @private */
7469
7447
  WebsocketService.prototype.getObserversCount = function () {
7470
- var e_6, _a;
7448
+ var e_5, _a;
7471
7449
  var observersCount = 0;
7472
7450
  try {
7473
7451
  for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -7475,36 +7453,35 @@
7475
7453
  observersCount += primitiveManager.event$.observers.length;
7476
7454
  }
7477
7455
  }
7478
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
7456
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
7479
7457
  finally {
7480
7458
  try {
7481
7459
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7482
7460
  }
7483
- finally { if (e_6) throw e_6.error; }
7461
+ finally { if (e_5) throw e_5.error; }
7484
7462
  }
7485
7463
  return observersCount;
7486
7464
  };
7487
7465
  /** @private */
7488
7466
  WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitiveManager) {
7489
- var e_7, _a;
7467
+ var e_6, _a;
7490
7468
  // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
7491
7469
  var hasObservers = !(primitiveManager.event$.observers.length === 1);
7492
7470
  if (hasObservers)
7493
7471
  return;
7494
7472
  primitiveManager.event$.complete();
7495
- primitiveManager.subscribe$.complete();
7496
7473
  try {
7497
7474
  for (var _b = __values(primitiveManager.stompSubscriptions), _c = _b.next(); !_c.done; _c = _b.next()) {
7498
7475
  var stompSubscription = _c.value;
7499
7476
  stompSubscription.unsubscribe();
7500
7477
  }
7501
7478
  }
7502
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
7479
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
7503
7480
  finally {
7504
7481
  try {
7505
7482
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7506
7483
  }
7507
- finally { if (e_7) throw e_7.error; }
7484
+ finally { if (e_6) throw e_6.error; }
7508
7485
  }
7509
7486
  var key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7510
7487
  this.primitiveManagers.delete(key);
@@ -7515,22 +7492,20 @@
7515
7492
  return domain + "/" + service + "/" + primitive;
7516
7493
  };
7517
7494
  var WebsocketService_1;
7518
- /** @private */
7519
- WebsocketService.RECONNECT_TIMER = 3000;
7520
- /** @private */
7495
+ WebsocketService.RECONNECT_INTERVAL = 3000;
7521
7496
  WebsocketService.CONNECTION_TIMEOUT = 15000;
7522
7497
  /** @private */
7523
- WebsocketService.BASE_URL_COOKIE = "com.senior.base.url";
7498
+ WebsocketService.BASE_URL_COOKIE = 'com.senior.base.url';
7524
7499
  /** @private */
7525
- WebsocketService.TOKEN_COOKIE = "com.senior.token";
7500
+ WebsocketService.TOKEN_COOKIE = 'com.senior.token';
7526
7501
  /** @private */
7527
- WebsocketService.TOKEN = JSON.parse(jsCookie.get(WebsocketService_1.TOKEN_COOKIE) || "{}");
7502
+ WebsocketService.TOKEN = JSON.parse(jsCookie.get(WebsocketService_1.TOKEN_COOKIE) || '{}');
7528
7503
  /** @private */
7529
- WebsocketService.WEBSOCKET_URL = jsCookie.get(WebsocketService_1.BASE_URL_COOKIE) + "/websocket/";
7504
+ WebsocketService.WEBSOCKET_URL = jsCookie.get(WebsocketService_1.BASE_URL_COOKIE) + '/websocket/';
7530
7505
  WebsocketService.ɵprov = core.ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
7531
7506
  WebsocketService = WebsocketService_1 = __decorate([
7532
7507
  core.Injectable({
7533
- providedIn: "root",
7508
+ providedIn: 'root'
7534
7509
  })
7535
7510
  ], WebsocketService);
7536
7511
  return WebsocketService;