@iobroker/adapter-react-v5 4.4.6 → 4.4.8
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.
- package/LegacyConnection.d.ts +6 -6
- package/LegacyConnection.js +179 -90
- package/LegacyConnection.js.map +1 -1
- package/README.md +5 -1
- package/i18n/de.json +8 -2
- package/i18n/en.json +8 -2
- package/i18n/es.json +8 -2
- package/i18n/fr.json +8 -2
- package/i18n/it.json +8 -2
- package/i18n/nl.json +8 -2
- package/i18n/pl.json +8 -2
- package/i18n/pt.json +8 -2
- package/i18n/ru.json +8 -2
- package/i18n/uk.json +8 -2
- package/i18n/zh-cn.json +8 -2
- package/package.json +7 -7
package/LegacyConnection.d.ts
CHANGED
|
@@ -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
|
|
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
|
*/
|
package/LegacyConnection.js
CHANGED
|
@@ -545,23 +545,35 @@ var Connection = /*#__PURE__*/function () {
|
|
|
545
545
|
cb = binary;
|
|
546
546
|
binary = false;
|
|
547
547
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
this.statesSubscribes[
|
|
558
|
-
|
|
559
|
-
if (
|
|
560
|
-
|
|
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
|
-
}
|
|
564
|
-
|
|
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
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
this.statesSubscribes[
|
|
603
|
-
|
|
604
|
-
if (
|
|
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
|
-
|
|
626
|
+
toSubscribe.push(_id);
|
|
607
627
|
}
|
|
628
|
+
} else {
|
|
629
|
+
!this.statesSubscribes[_id].cbs.includes(cb) && this.statesSubscribes[_id].cbs.push(cb);
|
|
608
630
|
}
|
|
609
|
-
}
|
|
610
|
-
|
|
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
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
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
|
-
|
|
665
|
-
|
|
666
|
-
|
|
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
|
-
|
|
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
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
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
|
|
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
|
-
|
|
763
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
794
|
-
if (
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
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
|
/**
|