@iobroker/adapter-react-v5 4.4.6 → 4.4.7

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.
@@ -125,20 +125,20 @@ declare class Connection {
125
125
  subscribeState(id: string, binary: boolean, cb: ioBroker.StateChangeHandler): void;
126
126
  /**
127
127
  * Subscribe to changes of the given state.
128
- * @param {string} id The ioBroker state ID.
128
+ * @param {string | string[]} id The ioBroker state ID or array of states
129
129
  * @param {ioBroker.StateChangeHandler} cb The callback.
130
130
  */
131
- subscribeStateAsync(id: string, cb: ioBroker.StateChangeHandler): Promise<any>;
131
+ subscribeStateAsync(id: string | string[], cb: ioBroker.StateChangeHandler): Promise<any>;
132
132
  /**
133
133
  * Unsubscribes all callbacks from changes of the given state.
134
- * @param {string} id The ioBroker state ID.
134
+ * @param {string | string[]} id The ioBroker state ID or array of states
135
135
  */
136
136
  /**
137
137
  * Unsubscribes the given callback from changes of the given state.
138
- * @param {string} id The ioBroker state ID.
138
+ * @param {string | string[]} id The ioBroker state ID or array of states
139
139
  * @param {ioBroker.StateChangeHandler} cb The callback.
140
140
  */
141
- unsubscribeState(id: string, cb: ioBroker.StateChangeHandler): void;
141
+ unsubscribeState(id: string | string[], cb: ioBroker.StateChangeHandler): void;
142
142
  /**
143
143
  * Subscribe to changes of the given object.
144
144
  * @param {string} id The ioBroker object ID.
@@ -167,7 +167,7 @@ declare class Connection {
167
167
  fileChange(id: any, fileName: any, size: any): void;
168
168
  /**
169
169
  * Subscribe to changes of the files.
170
- * @param {string} id The ioBroker state ID for meat object. Could be a pattern
170
+ * @param {string} id The ioBroker state ID for meta-object. Could be a pattern
171
171
  * @param {string} filePattern Pattern or file name, like 'main/*' or 'main/visViews.json`
172
172
  * @param {function} cb The callback.
173
173
  */
@@ -545,23 +545,35 @@ var Connection = /*#__PURE__*/function () {
545
545
  cb = binary;
546
546
  binary = false;
547
547
  }
548
- if (!this.statesSubscribes[id]) {
549
- var reg = id.replace(/\./g, '\\.').replace(/\*/g, '.*').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/\+/g, '\\+').replace(/\[/g, '\\[');
550
- if (!reg.includes('*')) {
551
- reg += '$';
552
- }
553
- this.statesSubscribes[id] = {
554
- reg: new RegExp(reg),
555
- cbs: []
556
- };
557
- this.statesSubscribes[id].cbs.push(cb);
558
- if (this.connected) {
559
- if (this.connected && id !== this.ignoreState) {
560
- this._socket.emit('subscribe', id);
548
+ var ids;
549
+ if (!Array.isArray(id)) {
550
+ ids = [id];
551
+ } else {
552
+ ids = id;
553
+ }
554
+ var toSubscribe = [];
555
+ for (var i = 0; i < ids.length; i++) {
556
+ var _id = ids[i];
557
+ if (!this.statesSubscribes[_id]) {
558
+ var reg = _id.replace(/\./g, '\\.').replace(/\*/g, '.*').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/\+/g, '\\+').replace(/\[/g, '\\[');
559
+ if (!reg.includes('*')) {
560
+ reg += '$';
561
561
  }
562
+ this.statesSubscribes[_id] = {
563
+ reg: new RegExp(reg),
564
+ cbs: []
565
+ };
566
+ this.statesSubscribes[_id].cbs.push(cb);
567
+ if (_id !== this.ignoreState) {
568
+ toSubscribe.push(_id);
569
+ }
570
+ } else {
571
+ !this.statesSubscribes[_id].cbs.includes(cb) && this.statesSubscribes[_id].cbs.push(cb);
562
572
  }
563
- } else {
564
- !this.statesSubscribes[id].cbs.includes(cb) && this.statesSubscribes[id].cbs.push(cb);
573
+ }
574
+ if (toSubscribe.length && this.connected) {
575
+ // no answer from server required
576
+ this._socket.emit('subscribe', toSubscribe);
565
577
  }
566
578
  if (typeof cb === 'function' && this.connected) {
567
579
  if (binary) {
@@ -583,31 +595,43 @@ var Connection = /*#__PURE__*/function () {
583
595
 
584
596
  /**
585
597
  * Subscribe to changes of the given state.
586
- * @param {string} id The ioBroker state ID.
598
+ * @param {string | string[]} id The ioBroker state ID or array of states
587
599
  * @param {ioBroker.StateChangeHandler} cb The callback.
588
600
  */
589
601
  }, {
590
602
  key: "subscribeStateAsync",
591
603
  value: function subscribeStateAsync(id, cb) {
592
604
  var _this5 = this;
593
- if (!this.statesSubscribes[id]) {
594
- var reg = id.replace(/\./g, '\\.').replace(/\*/g, '.*').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/\+/g, '\\+').replace(/\[/g, '\\[');
595
- if (!reg.includes('*')) {
596
- reg += '$';
597
- }
598
- this.statesSubscribes[id] = {
599
- reg: new RegExp(reg),
600
- cbs: []
601
- };
602
- this.statesSubscribes[id].cbs.push(cb);
603
- if (this.connected) {
604
- if (this.connected && id !== this.ignoreState) {
605
+ var ids;
606
+ if (!Array.isArray(id)) {
607
+ ids = [id];
608
+ } else {
609
+ ids = id;
610
+ }
611
+ var toSubscribe = [];
612
+ for (var i = 0; i < ids.length; i++) {
613
+ var _id = ids[i];
614
+ if (!this.statesSubscribes[_id]) {
615
+ var reg = _id.replace(/\./g, '\\.').replace(/\*/g, '.*').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/\+/g, '\\+').replace(/\[/g, '\\[');
616
+ if (!reg.includes('*')) {
617
+ reg += '$';
618
+ }
619
+ this.statesSubscribes[_id] = {
620
+ reg: new RegExp(reg),
621
+ cbs: []
622
+ };
623
+ this.statesSubscribes[_id].cbs.push(cb);
624
+ if (_id !== this.ignoreState) {
605
625
  // no answer from server required
606
- this._socket.emit('subscribe', id);
626
+ toSubscribe.push(_id);
607
627
  }
628
+ } else {
629
+ !this.statesSubscribes[_id].cbs.includes(cb) && this.statesSubscribes[_id].cbs.push(cb);
608
630
  }
609
- } else {
610
- !this.statesSubscribes[id].cbs.includes(cb) && this.statesSubscribes[id].cbs.push(cb);
631
+ }
632
+ if (toSubscribe.length && this.connected) {
633
+ // no answer from server required
634
+ this._socket.emit('subscribe', toSubscribe);
611
635
  }
612
636
  return new Promise(function (resolve, reject) {
613
637
  if (typeof cb === 'function' && _this5.connected) {
@@ -626,30 +650,44 @@ var Connection = /*#__PURE__*/function () {
626
650
 
627
651
  /**
628
652
  * Unsubscribes all callbacks from changes of the given state.
629
- * @param {string} id The ioBroker state ID.
653
+ * @param {string | string[]} id The ioBroker state ID or array of states
630
654
  */
631
655
  /**
632
656
  * Unsubscribes the given callback from changes of the given state.
633
- * @param {string} id The ioBroker state ID.
657
+ * @param {string | string[]} id The ioBroker state ID or array of states
634
658
  * @param {ioBroker.StateChangeHandler} cb The callback.
635
659
  */
636
660
  }, {
637
661
  key: "unsubscribeState",
638
662
  value: function unsubscribeState(id, cb) {
639
- if (this.statesSubscribes[id]) {
640
- if (cb) {
641
- var pos = this.statesSubscribes[id].cbs.indexOf(cb);
642
- pos !== -1 && this.statesSubscribes[id].cbs.splice(pos, 1);
643
- } else {
644
- this.statesSubscribes[id].cbs = [];
645
- }
646
- if (!this.statesSubscribes[id].cbs || !this.statesSubscribes[id].cbs.length) {
647
- delete this.statesSubscribes[id];
648
- if (this.connected && id !== this.ignoreState) {
649
- this._socket.emit('unsubscribe', id);
663
+ var ids;
664
+ if (!Array.isArray(id)) {
665
+ ids = [id];
666
+ } else {
667
+ ids = id;
668
+ }
669
+ var toUnsubscribe = [];
670
+ for (var i = 0; i < ids.length; i++) {
671
+ var _id = ids[i];
672
+ if (this.statesSubscribes[_id]) {
673
+ if (cb) {
674
+ var pos = this.statesSubscribes[_id].cbs.indexOf(cb);
675
+ pos !== -1 && this.statesSubscribes[_id].cbs.splice(pos, 1);
676
+ } else {
677
+ this.statesSubscribes[_id].cbs = [];
678
+ }
679
+ if (!this.statesSubscribes[_id].cbs || !this.statesSubscribes[_id].cbs.length) {
680
+ delete this.statesSubscribes[_id];
681
+ if (_id !== this.ignoreState) {
682
+ toUnsubscribe.push(_id);
683
+ }
650
684
  }
651
685
  }
652
686
  }
687
+ if (toUnsubscribe.length && this.connected) {
688
+ // no answer from server required
689
+ this._socket.emit('unsubscribe', toUnsubscribe);
690
+ }
653
691
  }
654
692
 
655
693
  /**
@@ -661,19 +699,32 @@ var Connection = /*#__PURE__*/function () {
661
699
  }, {
662
700
  key: "subscribeObject",
663
701
  value: function subscribeObject(id, cb) {
664
- if (!this.objectsSubscribes[id]) {
665
- var reg = id.replace(/\./g, '\\.').replace(/\*/g, '.*');
666
- if (!reg.includes('*')) {
667
- reg += '$';
668
- }
669
- this.objectsSubscribes[id] = {
670
- reg: new RegExp(reg),
671
- cbs: []
672
- };
673
- this.objectsSubscribes[id].cbs.push(cb);
674
- this.connected && this._socket.emit('subscribeObjects', id);
702
+ var ids;
703
+ if (!Array.isArray(id)) {
704
+ ids = [id];
675
705
  } else {
676
- !this.objectsSubscribes[id].cbs.includes(cb) && this.objectsSubscribes[id].cbs.push(cb);
706
+ ids = id;
707
+ }
708
+ var toSubscribe = [];
709
+ for (var i = 0; i < ids.length; i++) {
710
+ var _id = ids[i];
711
+ if (!this.objectsSubscribes[_id]) {
712
+ var reg = _id.replace(/\./g, '\\.').replace(/\*/g, '.*');
713
+ if (!reg.includes('*')) {
714
+ reg += '$';
715
+ }
716
+ this.objectsSubscribes[_id] = {
717
+ reg: new RegExp(reg),
718
+ cbs: []
719
+ };
720
+ this.objectsSubscribes[_id].cbs.push(cb);
721
+ ids.push(_id);
722
+ } else {
723
+ !this.objectsSubscribes[_id].cbs.includes(cb) && this.objectsSubscribes[_id].cbs.push(cb);
724
+ }
725
+ }
726
+ if (this.connected && toSubscribe.length) {
727
+ this._socket.emit('subscribeObjects', toSubscribe);
677
728
  }
678
729
  return Promise.resolve();
679
730
  }
@@ -692,18 +743,31 @@ var Connection = /*#__PURE__*/function () {
692
743
  }, {
693
744
  key: "unsubscribeObject",
694
745
  value: function unsubscribeObject(id, cb) {
695
- if (this.objectsSubscribes[id]) {
696
- if (cb) {
697
- var pos = this.objectsSubscribes[id].cbs.indexOf(cb);
698
- pos !== -1 && this.objectsSubscribes[id].cbs.splice(pos, 1);
699
- } else {
700
- this.objectsSubscribes[id].cbs = [];
701
- }
702
- if (this.connected && (!this.objectsSubscribes[id].cbs || !this.objectsSubscribes[id].cbs.length)) {
703
- delete this.objectsSubscribes[id];
704
- this.connected && this._socket.emit('unsubscribeObjects', id);
746
+ var ids;
747
+ if (!Array.isArray(id)) {
748
+ ids = [id];
749
+ } else {
750
+ ids = id;
751
+ }
752
+ var toUnsubscribe = [];
753
+ for (var i = 0; i < ids.length; i++) {
754
+ var _id = ids[i];
755
+ if (this.objectsSubscribes[_id]) {
756
+ if (cb) {
757
+ var pos = this.objectsSubscribes[_id].cbs.indexOf(cb);
758
+ pos !== -1 && this.objectsSubscribes[_id].cbs.splice(pos, 1);
759
+ } else {
760
+ this.objectsSubscribes[_id].cbs = [];
761
+ }
762
+ if (this.connected && (!this.objectsSubscribes[_id].cbs || !this.objectsSubscribes[_id].cbs.length)) {
763
+ delete this.objectsSubscribes[_id];
764
+ toUnsubscribe.push(_id);
765
+ }
705
766
  }
706
767
  }
768
+ if (this.connected && toUnsubscribe.length) {
769
+ this._socket.emit('unsubscribeObjects', toUnsubscribe);
770
+ }
707
771
  return Promise.resolve();
708
772
  }
709
773
 
@@ -741,7 +805,7 @@ var Connection = /*#__PURE__*/function () {
741
805
 
742
806
  /**
743
807
  * Subscribe to changes of the files.
744
- * @param {string} id The ioBroker state ID for meat object. Could be a pattern
808
+ * @param {string} id The ioBroker state ID for meta-object. Could be a pattern
745
809
  * @param {string} filePattern Pattern or file name, like 'main/*' or 'main/visViews.json`
746
810
  * @param {function} cb The callback.
747
811
  */
@@ -749,7 +813,7 @@ var Connection = /*#__PURE__*/function () {
749
813
  key: "subscribeFiles",
750
814
  value: function () {
751
815
  var _subscribeFiles = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(id, filePattern, cb) {
752
- var key;
816
+ var filePatterns, toSubscribe, f, pattern, key;
753
817
  return _regenerator["default"].wrap(function _callee$(_context) {
754
818
  while (1) switch (_context.prev = _context.next) {
755
819
  case 0:
@@ -759,18 +823,30 @@ var Connection = /*#__PURE__*/function () {
759
823
  }
760
824
  throw new Error('The state change handler must be a function!');
761
825
  case 2:
762
- key = "".concat(id, "$%$").concat(filePattern);
763
- if (!this.filesSubscribes[key]) {
764
- this.filesSubscribes[key] = {
765
- regId: new RegExp(pattern2RegEx(id)),
766
- regFilePattern: new RegExp(pattern2RegEx(filePattern)),
767
- cbs: [cb]
768
- };
769
- this.connected && this._socket.emit('subscribeFiles', id, filePattern);
826
+ if (Array.isArray(filePattern)) {
827
+ filePatterns = filePattern;
770
828
  } else {
771
- !this.filesSubscribes[key].cbs.includes(cb) && this.filesSubscribes[key].cbs.push(cb);
829
+ filePatterns = [filePattern];
830
+ }
831
+ toSubscribe = [];
832
+ for (f = 0; f < filePatterns.length; f++) {
833
+ pattern = filePatterns[f];
834
+ key = "".concat(id, "$%$").concat(pattern);
835
+ if (!this.filesSubscribes[key]) {
836
+ this.filesSubscribes[key] = {
837
+ regId: new RegExp(pattern2RegEx(id)),
838
+ regFilePattern: new RegExp(pattern2RegEx(pattern)),
839
+ cbs: [cb]
840
+ };
841
+ toSubscribe.push(pattern);
842
+ } else {
843
+ !this.filesSubscribes[key].cbs.includes(cb) && this.filesSubscribes[key].cbs.push(cb);
844
+ }
845
+ }
846
+ if (this.connected && toSubscribe.length) {
847
+ this._socket.emit('subscribeFiles', id, toSubscribe);
772
848
  }
773
- case 4:
849
+ case 6:
774
850
  case "end":
775
851
  return _context.stop();
776
852
  }
@@ -790,20 +866,33 @@ var Connection = /*#__PURE__*/function () {
790
866
  }, {
791
867
  key: "unsubscribeFiles",
792
868
  value: function unsubscribeFiles(id, filePattern, cb) {
793
- var key = "".concat(id, "$%$").concat(filePattern);
794
- if (this.filesSubscribes[key]) {
795
- var sub = this.filesSubscribes[key];
796
- if (cb) {
797
- var pos = sub.cbs.indexOf(cb);
798
- pos !== -1 && sub.cbs.splice(pos, 1);
799
- } else {
800
- sub.cbs = [];
801
- }
802
- if (!sub.cbs || !sub.cbs.length) {
803
- delete this.filesSubscribes[key];
804
- this.connected && this._socket.emit('unsubscribeFiles', id, filePattern);
869
+ var filePatterns;
870
+ if (Array.isArray(filePattern)) {
871
+ filePatterns = filePattern;
872
+ } else {
873
+ filePatterns = [filePattern];
874
+ }
875
+ var toUnsubscribe = [];
876
+ for (var f = 0; f < filePatterns.length; f++) {
877
+ var pattern = filePatterns[f];
878
+ var key = "".concat(id, "$%$").concat(pattern);
879
+ if (this.filesSubscribes[key]) {
880
+ var sub = this.filesSubscribes[key];
881
+ if (cb) {
882
+ var pos = sub.cbs.indexOf(cb);
883
+ pos !== -1 && sub.cbs.splice(pos, 1);
884
+ } else {
885
+ sub.cbs = [];
886
+ }
887
+ if (!sub.cbs || !sub.cbs.length) {
888
+ delete this.filesSubscribes[key];
889
+ this.connected && toUnsubscribe.push(pattern);
890
+ }
805
891
  }
806
892
  }
893
+ if (this.connected && toUnsubscribe.length) {
894
+ this._socket.emit('unsubscribeFiles', id, toUnsubscribe);
895
+ }
807
896
  }
808
897
 
809
898
  /**