active-connect-ng2 0.2.28 → 0.2.30

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.
@@ -76,6 +76,7 @@ class WebsocketClient {
76
76
  this._token = '';
77
77
  this.connectionEstablishedOnce = false;
78
78
  this.messageId = 0;
79
+ this.rejectCallbacks = new Map();
79
80
  this.expectedMethods = new Map();
80
81
  this.closed = false;
81
82
  if (supportsCache)
@@ -150,7 +151,7 @@ class WebsocketClient {
150
151
  this.ws = new WebSocket(url + (this.supportsCache ? '?cache=true' : ''));
151
152
  this.ws.onerror = (err) => {
152
153
  this.ws.close();
153
- console.log(err);
154
+ console.log('ActiveConnect: ' + err);
154
155
  };
155
156
  this.ws.onopen = () => {
156
157
  this.Connected = true;
@@ -198,9 +199,10 @@ class WebsocketClient {
198
199
  }
199
200
  }
200
201
  expectMethod(method, messageId) {
201
- return new Promise((resolve) => {
202
+ return new Promise((resolve, reject) => {
202
203
  if (messageId) {
203
204
  this.expectedMethods.set(messageId, [resolve]);
205
+ this.rejectCallbacks.set(messageId, reject);
204
206
  }
205
207
  else {
206
208
  if (this.expectedMethods.has(method)) {
@@ -218,6 +220,13 @@ class WebsocketClient {
218
220
  this.handleOutboundCacheRequest(value);
219
221
  }
220
222
  if (messageId) {
223
+ if (method) {
224
+ const reject = this.rejectCallbacks.get(messageId);
225
+ if (reject) {
226
+ reject(value);
227
+ return;
228
+ }
229
+ }
221
230
  const callback = this.expectedMethods.get(messageId);
222
231
  if (callback) {
223
232
  const func = callback.shift();
@@ -250,20 +259,29 @@ class WebsocketClient {
250
259
  }
251
260
  handleOutboundCacheRequest(method) {
252
261
  if (this.dbService) {
253
- this.dbService.getByKey('outbound', method).subscribe((item) => {
254
- if (item) {
255
- this.send('___cache', {
256
- method,
257
- specificHash: item.specificHash || null,
258
- });
259
- }
260
- else {
261
- this.send('___cache', {
262
- method,
263
- specificHash: null,
264
- });
265
- }
266
- });
262
+ try {
263
+ this.dbService.getByKey('outbound', method).subscribe((item) => {
264
+ if (item) {
265
+ this.send('___cache', {
266
+ method,
267
+ specificHash: item.specificHash || null,
268
+ });
269
+ }
270
+ else {
271
+ this.send('___cache', {
272
+ method,
273
+ specificHash: null,
274
+ });
275
+ }
276
+ });
277
+ }
278
+ catch (e) {
279
+ this.send('___cache', {
280
+ method,
281
+ specificHash: null,
282
+ });
283
+ console.error('ActiveConnect: ' + e);
284
+ }
267
285
  }
268
286
  else {
269
287
  this.send('___cache', {
@@ -426,29 +444,51 @@ function Outbound(method, requestingRequired, cached, sortBy) {
426
444
  if (!target.___requested)
427
445
  target.___requested = {};
428
446
  if (!cached) {
429
- if (_this.dbService)
430
- _this.dbService.deleteByKey('outbound', method).subscribe(() => { });
447
+ if (_this.dbService) {
448
+ try {
449
+ _this.dbService
450
+ .deleteByKey('outbound', method)
451
+ .subscribe(() => { });
452
+ }
453
+ catch (e) {
454
+ console.error('ActiveConnect: could not delete indexdb cache entry');
455
+ }
456
+ }
431
457
  }
432
458
  if (data == 'cache_restore') {
433
459
  if (_this.dbService) {
434
- _this.dbService
435
- .getByKey('outbound', method)
436
- .subscribe((result) => {
437
- target.___received[propertyKey] = true;
438
- target.___data[propertyKey] = result.data;
439
- target.loading.set(propertyKey, false);
440
- });
460
+ try {
461
+ _this.dbService
462
+ .getByKey('outbound', method)
463
+ .subscribe((result) => {
464
+ target.___received[propertyKey] = true;
465
+ target.___data[propertyKey] = result.data;
466
+ target.loading.set(propertyKey, false);
467
+ });
468
+ }
469
+ catch (e) {
470
+ console.error('ActiveConnect: Unable to restore cached data.');
471
+ console.error(e);
472
+ }
441
473
  }
442
474
  else {
443
- console.error('Active - Connect: Caching / restore not possible as the indexedDB is not accessible');
475
+ console.error('ActiveConnect: Caching / restore not possible as the indexedDB is not accessible');
444
476
  }
445
477
  }
446
478
  else if (data == 'cache_delete') {
447
479
  if (_this.dbService) {
448
- _this.dbService.deleteByKey('outbound', method).subscribe(() => { });
480
+ try {
481
+ _this.dbService
482
+ .deleteByKey('outbound', method)
483
+ .subscribe(() => { });
484
+ }
485
+ catch (e) {
486
+ console.error('ActiveConnect: Unable to delete cached data');
487
+ console.error(e);
488
+ }
449
489
  }
450
490
  else {
451
- console.error('Active - Connect: Caching / restore not possible as the indexedDB is not accessible');
491
+ console.error('ActiveConnect: Caching / restore not possible as the indexedDB is not accessible');
452
492
  }
453
493
  target.___received[propertyKey] = false;
454
494
  target.___data[propertyKey] = undefined;
@@ -490,22 +530,34 @@ function Outbound(method, requestingRequired, cached, sortBy) {
490
530
  if (cached && specificHash) {
491
531
  if (_this.dbService) {
492
532
  if (data && (data === null || data === void 0 ? void 0 : data.length) > 0) {
493
- _this.dbService
494
- .update('outbound', {
495
- method,
496
- data,
497
- specificHash,
498
- })
499
- .subscribe(() => { });
533
+ try {
534
+ _this.dbService
535
+ .update('outbound', {
536
+ method,
537
+ data,
538
+ specificHash,
539
+ })
540
+ .subscribe(() => { });
541
+ }
542
+ catch (e) {
543
+ console.error('ActiveConnect: Unable to update cached data');
544
+ console.error(e);
545
+ }
500
546
  }
501
547
  else {
502
- _this.dbService
503
- .deleteByKey('outbound', method)
504
- .subscribe(() => { });
548
+ try {
549
+ _this.dbService
550
+ .deleteByKey('outbound', method)
551
+ .subscribe(() => { });
552
+ }
553
+ catch (e) {
554
+ console.error('ActiveConnect: Unable to delete cached data');
555
+ console.error(e);
556
+ }
505
557
  }
506
558
  }
507
559
  else {
508
- console.error('Active-Connect: Caching not possible as the indexedDB has not been initialized');
560
+ console.error('ActiveConnect: Caching not possible as the indexedDB has not been initialized');
509
561
  }
510
562
  }
511
563
  }
@@ -518,22 +570,34 @@ function Outbound(method, requestingRequired, cached, sortBy) {
518
570
  if (cached && specificHash) {
519
571
  if (_this.dbService) {
520
572
  if (data && (data === null || data === void 0 ? void 0 : data.length) > 0) {
521
- _this.dbService
522
- .update('outbound', {
523
- method,
524
- data,
525
- specificHash,
526
- })
527
- .subscribe(() => { });
573
+ try {
574
+ _this.dbService
575
+ .update('outbound', {
576
+ method,
577
+ data,
578
+ specificHash,
579
+ })
580
+ .subscribe(() => { });
581
+ }
582
+ catch (e) {
583
+ console.error('ActiveConnect: Unable to update cached data');
584
+ console.error(e);
585
+ }
528
586
  }
529
587
  else {
530
- _this.dbService
531
- .deleteByKey('outbound', method)
532
- .subscribe(() => { });
588
+ try {
589
+ _this.dbService
590
+ .deleteByKey('outbound', method)
591
+ .subscribe(() => { });
592
+ }
593
+ catch (e) {
594
+ console.error('ActiveConnect: Unable to update cached data');
595
+ console.error(e);
596
+ }
533
597
  }
534
598
  }
535
599
  else {
536
- console.error('Active-Connect: Caching not possible as the indexedDB has not been initialized');
600
+ console.error('ActiveConnect: Caching not possible as the indexedDB has not been initialized');
537
601
  }
538
602
  }
539
603
  }
@@ -583,6 +647,7 @@ function Route(method, loadingKey, dontEnsureTransmission) {
583
647
  // method annotation
584
648
  const original = target[propertyKey];
585
649
  target[propertyKey] = function execRoute(...data) {
650
+ var _a;
586
651
  return __awaiter(this, void 0, void 0, function* () {
587
652
  if (loadingKey) {
588
653
  if (!this.loadingElements[loadingKey]) {
@@ -593,7 +658,11 @@ function Route(method, loadingKey, dontEnsureTransmission) {
593
658
  const promise = original.bind(this)(...data);
594
659
  let res = null;
595
660
  if (this.client) {
596
- res = yield this.client.send(method, data[0], dontEnsureTransmission);
661
+ res = yield ((_a = this.client
662
+ .send(method, data[0], dontEnsureTransmission)) === null || _a === void 0 ? void 0 : _a.catch(() => {
663
+ if (loadingKey)
664
+ this.loadingElements[loadingKey]--;
665
+ }));
597
666
  }
598
667
  yield promise;
599
668
  if (loadingKey)
@@ -670,47 +739,72 @@ class OutboundObject {
670
739
  this.loadedGroupChanged = null;
671
740
  this.target.loading = new Map();
672
741
  if (this.client.dbService) {
673
- this.client.dbService
674
- .getByKey('outbound', method)
675
- .subscribe((result) => {
676
- var _a;
677
- if (result) {
678
- this.previouslyCachedCount = ((_a = result.data) === null || _a === void 0 ? void 0 : _a.length) || null;
679
- }
680
- });
742
+ try {
743
+ this.client.dbService
744
+ .getByKey('outbound', method)
745
+ .subscribe((result) => {
746
+ var _a;
747
+ if (result) {
748
+ this.previouslyCachedCount = ((_a = result.data) === null || _a === void 0 ? void 0 : _a.length) || null;
749
+ }
750
+ });
751
+ }
752
+ catch (e) {
753
+ console.error('ActiveConnect: Unable to read cached data');
754
+ console.error(e);
755
+ }
681
756
  }
682
757
  const _this = this;
683
758
  WebsocketClient.expectOutbound(method, function setOutbound(data, specificHash, insertedOrGroupData, updatedOrGroupId, deleted, length, _client) {
684
759
  var _a, _b, _c, _d;
685
760
  if (!cached) {
686
- if (_client.dbService)
687
- _client.dbService
688
- .deleteByKey('outbound', method)
689
- .subscribe(() => { });
761
+ if (_client.dbService) {
762
+ try {
763
+ _client.dbService
764
+ .deleteByKey('outbound', method)
765
+ .subscribe(() => { });
766
+ }
767
+ catch (e) {
768
+ console.error('ActiveConnect: Unable to delete cached data');
769
+ console.error(e);
770
+ }
771
+ }
690
772
  }
691
773
  if (data == 'cache_restore') {
692
774
  if (_client.dbService) {
693
- _client.dbService
694
- .getByKey('outbound', method)
695
- .subscribe((result) => {
696
- _this.setData(result.data);
697
- if (result.length)
698
- _this._length = result.length;
699
- _this.loading = false;
700
- });
775
+ try {
776
+ _client.dbService
777
+ .getByKey('outbound', method)
778
+ .subscribe((result) => {
779
+ _this.setData(result.data);
780
+ if (result.length)
781
+ _this._length = result.length;
782
+ _this.loading = false;
783
+ });
784
+ }
785
+ catch (e) {
786
+ console.error('ActiveConnect: Unable to restore cached data');
787
+ console.error(e);
788
+ }
701
789
  }
702
790
  else {
703
- console.error('Active - Connect: Caching / restore not possible as the indexedDB is not accessible');
791
+ console.error('ActiveConnect: Caching / restore not possible as the indexedDB is not accessible');
704
792
  }
705
793
  }
706
794
  else if (data == 'cache_delete') {
707
795
  if (_client.dbService) {
708
- _client.dbService
709
- .deleteByKey('outbound', method)
710
- .subscribe(() => { });
796
+ try {
797
+ _client.dbService
798
+ .deleteByKey('outbound', method)
799
+ .subscribe(() => { });
800
+ }
801
+ catch (e) {
802
+ console.error('ActiveConnect: Unable to delete cached data');
803
+ console.error(e);
804
+ }
711
805
  }
712
806
  else {
713
- console.error('Active - Connect: Caching / restore not possible as the indexedDB is not accessible');
807
+ console.error('ActiveConnect: Caching / restore not possible as the indexedDB is not accessible');
714
808
  }
715
809
  _this.loading = false;
716
810
  _this.requested = false;
@@ -772,24 +866,30 @@ class OutboundObject {
772
866
  _this.loading = false;
773
867
  if (cached && specificHash) {
774
868
  if (_client.dbService) {
775
- if (_this.data && ((_c = _this.data) === null || _c === void 0 ? void 0 : _c.length) > 0) {
776
- _client.dbService
777
- .update('outbound', {
778
- method,
779
- data: _this.data,
780
- specificHash,
781
- length,
782
- })
783
- .subscribe(() => { });
869
+ try {
870
+ if (_this.data && ((_c = _this.data) === null || _c === void 0 ? void 0 : _c.length) > 0) {
871
+ _client.dbService
872
+ .update('outbound', {
873
+ method,
874
+ data: _this.data,
875
+ specificHash,
876
+ length,
877
+ })
878
+ .subscribe(() => { });
879
+ }
880
+ else {
881
+ _client.dbService
882
+ .deleteByKey('outbound', method)
883
+ .subscribe(() => { });
884
+ }
784
885
  }
785
- else {
786
- _client.dbService
787
- .deleteByKey('outbound', method)
788
- .subscribe(() => { });
886
+ catch (e) {
887
+ console.error('ActiveConnect: Unable to update cached data.');
888
+ console.error(e);
789
889
  }
790
890
  }
791
891
  else {
792
- console.error('Active-Connect: Caching not possible as the indexedDB has not been initialized');
892
+ console.error('ActiveConnect: Caching not possible as the indexedDB has not been initialized');
793
893
  }
794
894
  }
795
895
  }
@@ -805,24 +905,30 @@ class OutboundObject {
805
905
  _this.loading = false;
806
906
  if (cached && specificHash) {
807
907
  if (_client.dbService) {
808
- if (data && (data === null || data === void 0 ? void 0 : data.length) > 0) {
809
- _client.dbService
810
- .update('outbound', {
811
- method,
812
- data,
813
- specificHash,
814
- length,
815
- })
816
- .subscribe(() => { });
908
+ try {
909
+ if (data && (data === null || data === void 0 ? void 0 : data.length) > 0) {
910
+ _client.dbService
911
+ .update('outbound', {
912
+ method,
913
+ data,
914
+ specificHash,
915
+ length,
916
+ })
917
+ .subscribe(() => { });
918
+ }
919
+ else {
920
+ _client.dbService
921
+ .deleteByKey('outbound', method)
922
+ .subscribe(() => { });
923
+ }
817
924
  }
818
- else {
819
- _client.dbService
820
- .deleteByKey('outbound', method)
821
- .subscribe(() => { });
925
+ catch (e) {
926
+ console.error('ActiveConnect: Unable to update cached data.');
927
+ console.error(e);
822
928
  }
823
929
  }
824
930
  else {
825
- console.error('Active-Connect: Caching not possible as the indexedDB has not been initialized');
931
+ console.error('ActiveConnect: Caching not possible as the indexedDB has not been initialized');
826
932
  }
827
933
  }
828
934
  }