@iobroker/socket-classes 0.5.2 → 0.5.4
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/README.md +820 -0
- package/lib/socketCommands.js +202 -17
- package/lib/socketCommandsAdmin.js +135 -37
- package/lib/socketCommon.js +1 -1
- package/package.json +5 -3
package/lib/socketCommands.js
CHANGED
|
@@ -262,6 +262,10 @@ class SocketCommands {
|
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
subscribe(socket, type, pattern, patternFile) {
|
|
265
|
+
if (!pattern) {
|
|
266
|
+
return this.adapter.log.warn('Empty pattern on subscribe!');
|
|
267
|
+
}
|
|
268
|
+
|
|
265
269
|
this.subscribes[type] = this.subscribes[type] || {};
|
|
266
270
|
|
|
267
271
|
let p;
|
|
@@ -269,7 +273,7 @@ class SocketCommands {
|
|
|
269
273
|
pattern = pattern.toString();
|
|
270
274
|
if (patternFile && type === 'fileChange') {
|
|
271
275
|
patternFile = patternFile.toString();
|
|
272
|
-
key = pattern
|
|
276
|
+
key = `${pattern}####${patternFile}`;
|
|
273
277
|
} else {
|
|
274
278
|
key = pattern;
|
|
275
279
|
}
|
|
@@ -310,7 +314,10 @@ class SocketCommands {
|
|
|
310
314
|
};
|
|
311
315
|
|
|
312
316
|
unsubscribe(socket, type, pattern, patternFile) {
|
|
313
|
-
|
|
317
|
+
if (!pattern) {
|
|
318
|
+
return this.adapter.log.warn('Empty pattern on subscribe!');
|
|
319
|
+
}
|
|
320
|
+
// console.log((socket._name || socket.id) + ' unsubscribe ' + pattern);
|
|
314
321
|
if (!this.subscribes[type]) {
|
|
315
322
|
return;
|
|
316
323
|
}
|
|
@@ -319,7 +326,7 @@ class SocketCommands {
|
|
|
319
326
|
pattern = pattern.toString();
|
|
320
327
|
if (patternFile && type === 'fileChange') {
|
|
321
328
|
patternFile = patternFile.toString();
|
|
322
|
-
key = pattern
|
|
329
|
+
key = `${pattern}####${patternFile}`;
|
|
323
330
|
} else {
|
|
324
331
|
key = pattern;
|
|
325
332
|
}
|
|
@@ -476,7 +483,7 @@ class SocketCommands {
|
|
|
476
483
|
|
|
477
484
|
_subscribeStates(socket, pattern, callback) {
|
|
478
485
|
if (this._checkPermissions(socket, 'subscribe', callback, pattern)) {
|
|
479
|
-
if (pattern
|
|
486
|
+
if (Array.isArray(pattern)) {
|
|
480
487
|
for (let p = 0; p < pattern.length; p++) {
|
|
481
488
|
this.subscribe(socket, 'stateChange', pattern[p]);
|
|
482
489
|
}
|
|
@@ -508,7 +515,7 @@ class SocketCommands {
|
|
|
508
515
|
|
|
509
516
|
_subscribeFiles(socket, id, pattern, callback) {
|
|
510
517
|
if (this._checkPermissions(socket, 'subscribeFiles', callback, pattern)) {
|
|
511
|
-
if (pattern
|
|
518
|
+
if (Array.isArray(pattern)) {
|
|
512
519
|
for (let p = 0; p < pattern.length; p++) {
|
|
513
520
|
this.subscribe(socket, 'fileChange', id, pattern[p]);
|
|
514
521
|
}
|
|
@@ -524,12 +531,12 @@ class SocketCommands {
|
|
|
524
531
|
|
|
525
532
|
_unsubscribeFiles(socket, id, pattern, callback) {
|
|
526
533
|
if (this._checkPermissions(socket, 'unsubscribeFiles', callback, pattern)) {
|
|
527
|
-
if (pattern
|
|
534
|
+
if (Array.isArray(pattern)) {
|
|
528
535
|
for (let p = 0; p < pattern.length; p++) {
|
|
529
536
|
this.unsubscribe(socket, 'fileChange', id, pattern[p]);
|
|
530
537
|
}
|
|
531
538
|
} else {
|
|
532
|
-
this.unsubscribe(socket, 'fileChange', pattern);
|
|
539
|
+
this.unsubscribe(socket, 'fileChange', id, pattern);
|
|
533
540
|
}
|
|
534
541
|
|
|
535
542
|
this.adapter.log.level === 'debug' && this._showSubscribes(socket, 'fileChange');
|
|
@@ -588,6 +595,10 @@ class SocketCommands {
|
|
|
588
595
|
|
|
589
596
|
__initCommandsCommon() {
|
|
590
597
|
this.commands['authenticate'] = (socket, user, pass, callback) => {
|
|
598
|
+
// Authenticate user by login and password
|
|
599
|
+
// @param {string} user - user name
|
|
600
|
+
// @param {string} pass - password
|
|
601
|
+
// @param {function} callback - `function (isUserAuthenticated, isAuthenticationUsed)`
|
|
591
602
|
if (socket && socket.___socket) {
|
|
592
603
|
socket = socket.___socket;
|
|
593
604
|
}
|
|
@@ -608,10 +619,15 @@ class SocketCommands {
|
|
|
608
619
|
};
|
|
609
620
|
|
|
610
621
|
this.commands['error'] = (socket, error) => {
|
|
622
|
+
// Write error into ioBroker log
|
|
623
|
+
// @param {string} error - error text
|
|
611
624
|
this.adapter.log.error('Socket error: ' + error);
|
|
612
625
|
};
|
|
613
626
|
|
|
614
627
|
this.commands['log'] = (socket, text, level) => {
|
|
628
|
+
// Write log entry into ioBroker log
|
|
629
|
+
// @param {string} text - log text
|
|
630
|
+
// @param {string} level - one of `['silly', 'debug', 'info', 'warn', 'error']`. Default is 'debug'.
|
|
615
631
|
if (level === 'error') {
|
|
616
632
|
this.adapter.log.error(text);
|
|
617
633
|
} else if (level === 'warn') {
|
|
@@ -625,6 +641,10 @@ class SocketCommands {
|
|
|
625
641
|
|
|
626
642
|
// new History
|
|
627
643
|
this.commands['getHistory'] = (socket, id, options, callback) => {
|
|
644
|
+
// Get history data from specific instance
|
|
645
|
+
// @param {string} id - object ID
|
|
646
|
+
// @param {object} options - See object description here: https://github.com/ioBroker/ioBroker.history/blob/master/docs/en/README.md#access-values-from-javascript-adapter
|
|
647
|
+
// @param {function} callback - `function (error, result)`
|
|
628
648
|
if (this._checkPermissions(socket, 'getStateHistory', callback, id)) {
|
|
629
649
|
if (typeof options === 'string') {
|
|
630
650
|
options = {
|
|
@@ -646,6 +666,9 @@ class SocketCommands {
|
|
|
646
666
|
|
|
647
667
|
// HTTP
|
|
648
668
|
this.commands['httpGet'] = (socket, url, callback) => {
|
|
669
|
+
// Read content of HTTP(S) page server-side (without CORS and stuff)
|
|
670
|
+
// @param {string} url - Page URL
|
|
671
|
+
// @param {function} callback - `function (error, {status, statusText}, body)`
|
|
649
672
|
if (this._checkPermissions(socket, 'httpGet', callback, url)) {
|
|
650
673
|
axios = axios || require('axios');
|
|
651
674
|
this.adapter.log.debug('httpGet: ' + url);
|
|
@@ -665,6 +688,11 @@ class SocketCommands {
|
|
|
665
688
|
|
|
666
689
|
// commands
|
|
667
690
|
this.commands['sendTo'] = (socket, adapterInstance, command, message, callback) => {
|
|
691
|
+
// Send message to specific instance
|
|
692
|
+
// @param {string} adapterInstance - instance name, e.g. `history.0`
|
|
693
|
+
// @param {string} command - command name
|
|
694
|
+
// @param {object} message - message is instance dependent
|
|
695
|
+
// @param {function} callback - `function (result)`
|
|
668
696
|
if (this._checkPermissions(socket, 'sendTo', callback, command)) {
|
|
669
697
|
try {
|
|
670
698
|
this.adapter.sendTo(adapterInstance, command, message, res =>
|
|
@@ -680,8 +708,12 @@ class SocketCommands {
|
|
|
680
708
|
const protectedCommands = ['cmdExec', 'getLocationOnDisk', 'getDiagData', 'getDevList', 'delLogs', 'writeDirAsZip', 'writeObjectsAsZip', 'readObjectsAsZip', 'checkLogging', 'updateMultihost', 'rebuildAdapter'];
|
|
681
709
|
|
|
682
710
|
this.commands['sendToHost'] = (socket, host, command, message, callback) => {
|
|
683
|
-
//
|
|
684
|
-
// delLogs, readDirAsZip, writeDirAsZip, readObjectsAsZip, writeObjectsAsZip, checkLogging, updateMultihost
|
|
711
|
+
// Send message to specific host.
|
|
712
|
+
// Host can answer following commands: `cmdExec, getRepository, getInstalled, getInstalledAdapter, getVersion, getDiagData, getLocationOnDisk, getDevList, getLogs, getHostInfo, delLogs, readDirAsZip, writeDirAsZip, readObjectsAsZip, writeObjectsAsZip, checkLogging, updateMultihost`.
|
|
713
|
+
// @param {string} host - instance name, e.g. `history.0`
|
|
714
|
+
// @param {string} command - command name
|
|
715
|
+
// @param {object} message - message is command specific
|
|
716
|
+
// @param {function} callback - `function (result)`
|
|
685
717
|
if (this._checkPermissions(socket, protectedCommands.includes(command) ? 'cmdExec' : 'sendToHost', callback, command)) {
|
|
686
718
|
// Try to decode this file locally as redis has a limitation for files bigger than 20MB
|
|
687
719
|
if (command === 'writeDirAsZip' && message && message.data.length > 1024 * 1024) {
|
|
@@ -726,6 +758,8 @@ class SocketCommands {
|
|
|
726
758
|
};
|
|
727
759
|
|
|
728
760
|
this.commands['authEnabled'] = (socket, callback) => {
|
|
761
|
+
// Ask server is authentication enabled and if the user authenticated
|
|
762
|
+
// @param {function} callback - `function (isAuthenticationUsed, userName)`
|
|
729
763
|
if (this._checkPermissions(socket, 'authEnabled', callback)) {
|
|
730
764
|
if (typeof callback === 'function') {
|
|
731
765
|
callback(this.adapter.config.auth, (socket._acl.user || '').replace(/^system\.user\./, ''));
|
|
@@ -736,10 +770,14 @@ class SocketCommands {
|
|
|
736
770
|
};
|
|
737
771
|
|
|
738
772
|
this.commands['logout'] = (socket, callback) => {
|
|
773
|
+
// Logout user
|
|
774
|
+
// @param {function} callback - function (error)
|
|
739
775
|
this.adapter.destroySession(socket._sessionID, callback);
|
|
740
776
|
};
|
|
741
777
|
|
|
742
778
|
this.commands['listPermissions'] = (socket, callback) => {
|
|
779
|
+
// List commands and permissions
|
|
780
|
+
// @param {function} callback - `function (permissions)`
|
|
743
781
|
if (typeof callback === 'function') {
|
|
744
782
|
callback(SocketCommands.COMMANDS_PERMISSIONS);
|
|
745
783
|
} else {
|
|
@@ -748,6 +786,8 @@ class SocketCommands {
|
|
|
748
786
|
};
|
|
749
787
|
|
|
750
788
|
this.commands['getUserPermissions'] = (socket, callback) => {
|
|
789
|
+
// Get user permissions
|
|
790
|
+
// @param {function} callback - `function (error, permissions)`
|
|
751
791
|
if (this._checkPermissions(socket, 'getUserPermissions', callback)) {
|
|
752
792
|
if (typeof callback === 'function') {
|
|
753
793
|
callback(null, socket._acl);
|
|
@@ -758,6 +798,8 @@ class SocketCommands {
|
|
|
758
798
|
};
|
|
759
799
|
|
|
760
800
|
this.commands['getVersion'] = (socket, callback) => {
|
|
801
|
+
// Get adapter version. Not the socket-classes version!
|
|
802
|
+
// @param {function} callback - `function (error, adapterVersion, adapterName)`
|
|
761
803
|
if (this._checkPermissions(socket, 'getVersion', callback)) {
|
|
762
804
|
if (typeof callback === 'function') {
|
|
763
805
|
callback(null, this.adapter.version, this.adapter.name);
|
|
@@ -768,6 +810,8 @@ class SocketCommands {
|
|
|
768
810
|
};
|
|
769
811
|
|
|
770
812
|
this.commands['getAdapterName'] = (socket, callback) => {
|
|
813
|
+
// Get adapter name. Not the socket-classes version!
|
|
814
|
+
// @param {function} callback - `function (error, adapterVersion)`
|
|
771
815
|
if (this._checkPermissions(socket, 'getAdapterName', callback)) {
|
|
772
816
|
if (typeof callback === 'function') {
|
|
773
817
|
callback(null, this.adapter.name || 'unknown');
|
|
@@ -776,12 +820,15 @@ class SocketCommands {
|
|
|
776
820
|
}
|
|
777
821
|
}
|
|
778
822
|
};
|
|
779
|
-
|
|
780
823
|
}
|
|
781
824
|
|
|
782
825
|
__initCommandsFiles() {
|
|
783
826
|
// file operations
|
|
784
827
|
this.commands['readFile'] = (socket, _adapter, fileName, callback) => {
|
|
828
|
+
// Read file from ioBroker DB
|
|
829
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
830
|
+
// @param {string} fileName - file name, e.g `main/vis-views.json`
|
|
831
|
+
// @param {function} callback - `function (error, data, mimeType)`
|
|
785
832
|
if (this._checkPermissions(socket, 'readFile', callback, fileName)) {
|
|
786
833
|
try {
|
|
787
834
|
this.adapter.readFile(_adapter, fileName, {user: socket._acl.user}, (error, ...args) =>
|
|
@@ -794,6 +841,10 @@ class SocketCommands {
|
|
|
794
841
|
};
|
|
795
842
|
|
|
796
843
|
this.commands['readFile64'] = (socket, _adapter, fileName, callback) => {
|
|
844
|
+
// Read file from ioBroker DB as base64 string
|
|
845
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
846
|
+
// @param {string} fileName - file name, e.g `main/vis-views.json`
|
|
847
|
+
// @param {function} callback - `function (error, base64, mimeType)`
|
|
797
848
|
if (this._checkPermissions(socket, 'readFile64', callback, fileName)) {
|
|
798
849
|
try {
|
|
799
850
|
this.adapter.readFile(_adapter, fileName, {user: socket._acl.user}, (error, buffer, type) => {
|
|
@@ -829,6 +880,12 @@ class SocketCommands {
|
|
|
829
880
|
};
|
|
830
881
|
|
|
831
882
|
this.commands['writeFile64'] = (socket, _adapter, fileName, data64, options, callback) => {
|
|
883
|
+
// Write file into ioBroker DB as base64 string
|
|
884
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
885
|
+
// @param {string} fileName - file name, e.g `main/vis-views.json`
|
|
886
|
+
// @param {string} data64 - file content as base64 string
|
|
887
|
+
// @param {object} options - optional `{mode: 0x0644}`
|
|
888
|
+
// @param {function} callback - `function (error)`
|
|
832
889
|
if (typeof options === 'function') {
|
|
833
890
|
callback = options;
|
|
834
891
|
options = {user: socket._acl.user};
|
|
@@ -856,6 +913,12 @@ class SocketCommands {
|
|
|
856
913
|
|
|
857
914
|
// this function is overloaded in admin (because admin accepts only base64)
|
|
858
915
|
this.commands['writeFile'] = (socket, _adapter, fileName, data, options, callback) => {
|
|
916
|
+
// Write file into ioBroker DB as text **DEPRECATED**
|
|
917
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
918
|
+
// @param {string} fileName - file name, e.g `main/vis-views.json`
|
|
919
|
+
// @param {string} data64 - file content as base64 string
|
|
920
|
+
// @param {object} options - optional `{mode: 0x644}`
|
|
921
|
+
// @param {function} callback - `function (error)`
|
|
859
922
|
if (this._checkPermissions(socket, 'writeFile', callback, fileName)) {
|
|
860
923
|
if (typeof options === 'function') {
|
|
861
924
|
callback = options;
|
|
@@ -876,6 +939,10 @@ class SocketCommands {
|
|
|
876
939
|
};
|
|
877
940
|
|
|
878
941
|
this.commands['unlink'] = (socket, _adapter, name, callback) => {
|
|
942
|
+
// Delete file in ioBroker DB
|
|
943
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
944
|
+
// @param {string} name - file name, e.g `main/vis-views.json`
|
|
945
|
+
// @param {function} callback - `function (error)`
|
|
879
946
|
if (this._checkPermissions(socket, 'unlink', callback, name)) {
|
|
880
947
|
try {
|
|
881
948
|
this._unlink(_adapter, name, {user: socket._acl.user})
|
|
@@ -889,6 +956,10 @@ class SocketCommands {
|
|
|
889
956
|
};
|
|
890
957
|
|
|
891
958
|
this.commands['deleteFile'] = (socket, _adapter, name, callback) => {
|
|
959
|
+
// Delete file in ioBroker DB (same as unlink, but only for files)
|
|
960
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
961
|
+
// @param {string} name - file name, e.g `main/vis-views.json`
|
|
962
|
+
// @param {function} callback - `function (error)`
|
|
892
963
|
if (this._checkPermissions(socket, 'unlink', callback, name)) {
|
|
893
964
|
try {
|
|
894
965
|
this.adapter.unlink(_adapter, name, {user: socket._acl.user}, (error, ...args) =>
|
|
@@ -901,6 +972,10 @@ class SocketCommands {
|
|
|
901
972
|
};
|
|
902
973
|
|
|
903
974
|
this.commands['deleteFolder'] = (socket, _adapter, name, callback) => {
|
|
975
|
+
// Delete file in ioBroker DB (same as unlink, but only for folders)
|
|
976
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
977
|
+
// @param {string} name - folder name, e.g `main`
|
|
978
|
+
// @param {function} callback - `function (error)`
|
|
904
979
|
if (this._checkPermissions(socket, 'unlink', callback, name)) {
|
|
905
980
|
try {
|
|
906
981
|
this._unlink(_adapter, name, {user: socket._acl.user})
|
|
@@ -914,6 +989,11 @@ class SocketCommands {
|
|
|
914
989
|
};
|
|
915
990
|
|
|
916
991
|
this.commands['renameFile'] = (socket, _adapter, oldName, newName, callback) => {
|
|
992
|
+
// Rename file in ioBroker DB
|
|
993
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
994
|
+
// @param {string} oldName - current file name, e.g `main/vis-views.json`
|
|
995
|
+
// @param {string} newName - new file name, e.g `main/vis-views-new.json`
|
|
996
|
+
// @param {function} callback - `function (error)`
|
|
917
997
|
if (this._checkPermissions(socket, 'rename', callback, oldName)) {
|
|
918
998
|
try {
|
|
919
999
|
this.adapter.rename(_adapter, oldName, newName, {user: socket._acl.user}, (error, ...args) =>
|
|
@@ -926,6 +1006,11 @@ class SocketCommands {
|
|
|
926
1006
|
};
|
|
927
1007
|
|
|
928
1008
|
this.commands['rename'] = (socket, _adapter, oldName, newName, callback) => {
|
|
1009
|
+
// Rename file or folder in ioBroker DB
|
|
1010
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
1011
|
+
// @param {string} oldName - current file name, e.g `main/vis-views.json`
|
|
1012
|
+
// @param {string} newName - new file name, e.g `main/vis-views-new.json`
|
|
1013
|
+
// @param {function} callback - `function (error)`
|
|
929
1014
|
if (this._checkPermissions(socket, 'rename', callback, oldName)) {
|
|
930
1015
|
try {
|
|
931
1016
|
this._rename(_adapter, oldName, newName, {user: socket._acl.user})
|
|
@@ -939,6 +1024,10 @@ class SocketCommands {
|
|
|
939
1024
|
};
|
|
940
1025
|
|
|
941
1026
|
this.commands['mkdir'] = (socket, _adapter, dirName, callback) => {
|
|
1027
|
+
// Create folder in ioBroker DB
|
|
1028
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
1029
|
+
// @param {string} dirName - desired folder name, e.g `main`
|
|
1030
|
+
// @param {function} callback - `function (error)`
|
|
942
1031
|
if (this._checkPermissions(socket, 'mkdir', callback, dirName)) {
|
|
943
1032
|
try {
|
|
944
1033
|
this.adapter.mkdir(_adapter, dirName, {user: socket._acl.user}, (error, ...args) =>
|
|
@@ -951,6 +1040,11 @@ class SocketCommands {
|
|
|
951
1040
|
};
|
|
952
1041
|
|
|
953
1042
|
this.commands['readDir'] = (socket, _adapter, dirName, options, callback) => {
|
|
1043
|
+
// Read content of folder in ioBroker DB
|
|
1044
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
1045
|
+
// @param {string} dirName - folder name, e.g `main`
|
|
1046
|
+
// @param {object} options - optional `{filter: '*'}` or `{filter: '*.json'}`
|
|
1047
|
+
// @param {function} callback - `function (error, files)` where `files` is an array of objects, like `{file: 'vis-views.json', isDir: false, stats: {size: 123}, modifiedAt: 1661336290090, acl: {owner: 'system.user.admin', ownerGroup: 'system.group.administrator', permissions: 1632, read: true, write: true}`
|
|
954
1048
|
if (typeof options === 'function') {
|
|
955
1049
|
callback = options;
|
|
956
1050
|
options = {};
|
|
@@ -974,6 +1068,11 @@ class SocketCommands {
|
|
|
974
1068
|
};
|
|
975
1069
|
|
|
976
1070
|
this.commands['chmodFile'] = (socket, _adapter, fileName, options, callback) => {
|
|
1071
|
+
// Change file mode in ioBroker DB
|
|
1072
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
1073
|
+
// @param {string} fileName - file name, e.g `main/vis-views.json`
|
|
1074
|
+
// @param {object} options - `{mode: 0x644}` or 0x644. First digit is user, second group, third others. Bit 1 is `execute`, bit 2 is `write`, bit 3 is `read`
|
|
1075
|
+
// @param {function} callback - `function (error)`
|
|
977
1076
|
if (typeof options === 'function') {
|
|
978
1077
|
callback = options;
|
|
979
1078
|
options = {};
|
|
@@ -997,6 +1096,11 @@ class SocketCommands {
|
|
|
997
1096
|
};
|
|
998
1097
|
|
|
999
1098
|
this.commands['chownFile'] = (socket, _adapter, fileName, options, callback) => {
|
|
1099
|
+
// Change file owner in ioBroker DB
|
|
1100
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
1101
|
+
// @param {string} fileName - file name, e.g `main/vis-views.json`
|
|
1102
|
+
// @param {object} options - `{owner: 'system.user.user', ownerGroup: ''system.group.administrator'}` or 'system.user.user'. If ownerGroup is not defined, it will be taken from owner.
|
|
1103
|
+
// @param {function} callback - `function (error)`
|
|
1000
1104
|
if (this._checkPermissions(socket, 'chownFile', callback, fileName)) {
|
|
1001
1105
|
options = options || {};
|
|
1002
1106
|
options.user = socket._acl.user;
|
|
@@ -1011,6 +1115,10 @@ class SocketCommands {
|
|
|
1011
1115
|
};
|
|
1012
1116
|
|
|
1013
1117
|
this.commands['fileExists'] = (socket, _adapter, fileName, callback) => {
|
|
1118
|
+
// Checks if the file or folder exists in ioBroker DB
|
|
1119
|
+
// @param {string} _adapter - instance name, e.g. `vis.0`
|
|
1120
|
+
// @param {string} fileName - file name, e.g `main/vis-views.json`
|
|
1121
|
+
// @param {function} callback - `function (error, isExist)`
|
|
1014
1122
|
if (this._checkPermissions(socket, 'fileExists', callback, fileName)) {
|
|
1015
1123
|
try {
|
|
1016
1124
|
this.adapter.fileExists(_adapter, fileName, {user: socket._acl.user}, (error, ...args) =>
|
|
@@ -1022,11 +1130,27 @@ class SocketCommands {
|
|
|
1022
1130
|
}
|
|
1023
1131
|
};
|
|
1024
1132
|
|
|
1025
|
-
this.commands['subscribeFiles'] = (socket, id, pattern, callback) =>
|
|
1133
|
+
this.commands['subscribeFiles'] = (socket, id, pattern, callback) => {
|
|
1134
|
+
// Subscribe on file changes in ioBroker DB
|
|
1135
|
+
// @param {string} id - instance name, e.g. `vis.0` or any object ID of type `meta`. `id` could have wildcards `*` too.
|
|
1136
|
+
// @param {string} pattern - file name pattern, e.g `main/*.json`
|
|
1137
|
+
// @param {function} callback - `function (error)`
|
|
1138
|
+
return this._subscribeFiles(socket, id, pattern, callback);
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
this.commands['unsubscribeFiles'] = (socket, id, pattern, callback) => {
|
|
1142
|
+
// Unsubscribe on file changes in ioBroker DB
|
|
1143
|
+
// @param {string} id - instance name, e.g. `vis.0` or any object ID of type `meta`. `id` could have wildcards `*` too.
|
|
1144
|
+
// @param {string} pattern - file name pattern, e.g `main/*.json`
|
|
1145
|
+
// @param {function} callback - `function (error)`
|
|
1026
1146
|
|
|
1027
|
-
|
|
1147
|
+
return this._unsubscribeFiles(socket, id, pattern, callback);
|
|
1148
|
+
}
|
|
1028
1149
|
|
|
1029
1150
|
this.commands['getAdapterInstances'] = (socket, adapterName, callback) => {
|
|
1151
|
+
// Read all instances of the given adapter, or all instances of all adapters if adapterName is not defined
|
|
1152
|
+
// @param {string} adapterName - optional adapter name, e.g `history`.
|
|
1153
|
+
// @param {function} callback - `function (error, instanceList)`, where instanceList is an array of instance objects, e.g. `{_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}}`
|
|
1030
1154
|
if (typeof callback === 'function') {
|
|
1031
1155
|
if (this._checkPermissions(socket, 'getObject', callback)) {
|
|
1032
1156
|
let _adapterName = adapterName !== undefined && adapterName !== null ? adapterName : this.adapterName || '';
|
|
@@ -1064,6 +1188,9 @@ class SocketCommands {
|
|
|
1064
1188
|
|
|
1065
1189
|
__initCommandsStates() {
|
|
1066
1190
|
this.commands['getStates'] = (socket, pattern, callback) => {
|
|
1191
|
+
// Read states by pattern
|
|
1192
|
+
// @param {string} pattern - optional pattern, like `system.adapter.*` or array of state IDs
|
|
1193
|
+
// @param {function} callback - `function (error, states)`, where `states` is an object like `{'system.adapter.history.0': {_id: 'system.adapter.history.0', common: {name: 'history', ...}, native: {...}, 'system.adapter.history.1': {...}}}`
|
|
1067
1194
|
if (this._checkPermissions(socket, 'getStates', callback, pattern)) {
|
|
1068
1195
|
if (typeof pattern === 'function') {
|
|
1069
1196
|
callback = pattern;
|
|
@@ -1085,7 +1212,10 @@ class SocketCommands {
|
|
|
1085
1212
|
|
|
1086
1213
|
// this function is overloaded in admin
|
|
1087
1214
|
this.commands['delObject'] = (socket, id, options, callback) => {
|
|
1088
|
-
//
|
|
1215
|
+
// Delete object. Only deletion of flot objects is allowed
|
|
1216
|
+
// @param {string} id - Object ID like, 'flot.0.myChart'
|
|
1217
|
+
// @param {string} options - ignored
|
|
1218
|
+
// @param {function} callback - `function (error)`
|
|
1089
1219
|
if (id.startsWith('flot.')) {
|
|
1090
1220
|
if (this._checkPermissions(socket, 'delObject', callback, id)) {
|
|
1091
1221
|
try {
|
|
@@ -1102,6 +1232,9 @@ class SocketCommands {
|
|
|
1102
1232
|
};
|
|
1103
1233
|
|
|
1104
1234
|
this.commands['getState'] = (socket, id, callback) => {
|
|
1235
|
+
// Read one state.
|
|
1236
|
+
// @param {string} id - State ID like, 'system.adapter.admin.0.memRss'
|
|
1237
|
+
// @param {function} callback - `function (error, state)`, where `state` is an object like `{val: 123, ts: 1663915537418, ack: true, from: 'system.adapter.admin.0', q: 0, lc: 1663915537418, c: 'javascript.0'}`
|
|
1105
1238
|
if (this._checkPermissions(socket, 'getState', callback, id)) {
|
|
1106
1239
|
if (typeof callback === 'function') {
|
|
1107
1240
|
if (this.states && this.states[id]) {
|
|
@@ -1122,6 +1255,10 @@ class SocketCommands {
|
|
|
1122
1255
|
};
|
|
1123
1256
|
|
|
1124
1257
|
this.commands['setState'] = (socket, id, state, callback) => {
|
|
1258
|
+
// Write one state.
|
|
1259
|
+
// @param {string} id - State ID like, 'system.adapter.admin.0.memRss'
|
|
1260
|
+
// @param {any} state - value or object like `{val: 123, ack: true}`
|
|
1261
|
+
// @param {function} callback - `function (error, state)`, where `state` is an object like `{val: 123, ts: 1663915537418, ack: true, from: 'system.adapter.admin.0', q: 0, lc: 1663915537418, c: 'javascript.0'}`
|
|
1125
1262
|
if (this._checkPermissions(socket, 'setState', callback, id)) {
|
|
1126
1263
|
if (typeof state !== 'object') {
|
|
1127
1264
|
state = {val: state};
|
|
@@ -1143,6 +1280,9 @@ class SocketCommands {
|
|
|
1143
1280
|
};
|
|
1144
1281
|
|
|
1145
1282
|
this.commands['getBinaryState'] = (socket, id, callback) => {
|
|
1283
|
+
// Read one binary state.
|
|
1284
|
+
// @param {string} id - State ID like, 'javascript.0.binary'
|
|
1285
|
+
// @param {function} callback - `function (error, base64)`
|
|
1146
1286
|
if (this._checkPermissions(socket, 'getState', callback, id)) {
|
|
1147
1287
|
if (typeof callback === 'function') {
|
|
1148
1288
|
try {
|
|
@@ -1180,6 +1320,10 @@ class SocketCommands {
|
|
|
1180
1320
|
};
|
|
1181
1321
|
|
|
1182
1322
|
this.commands['setBinaryState'] = (socket, id, base64, callback) => {
|
|
1323
|
+
// Write one binary state.
|
|
1324
|
+
// @param {string} id - State ID like, 'javascript.0.binary'
|
|
1325
|
+
// @param {string} base64 - State value as base64 string. Binary states has no acknowledge flag.
|
|
1326
|
+
// @param {function} callback - `function (error)`
|
|
1183
1327
|
if (this._checkPermissions(socket, 'setState', callback, id)) {
|
|
1184
1328
|
if (typeof callback === 'function') {
|
|
1185
1329
|
let data = null;
|
|
@@ -1207,15 +1351,38 @@ class SocketCommands {
|
|
|
1207
1351
|
}
|
|
1208
1352
|
};
|
|
1209
1353
|
|
|
1210
|
-
this.commands['subscribe'] = (socket, pattern, callback) =>
|
|
1211
|
-
|
|
1354
|
+
this.commands['subscribe'] = (socket, pattern, callback) => {
|
|
1355
|
+
// Subscribe on state changes by pattern. The events will come as 'stateChange' events to the socket.
|
|
1356
|
+
// @param {string} pattern - pattern like 'system.adapter.*' or array of states like ['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
|
|
1357
|
+
// @param {function} callback - `function (error)`
|
|
1358
|
+
return this._subscribeStates(socket, pattern, callback);
|
|
1359
|
+
}
|
|
1360
|
+
this.commands['subscribeStates'] = (socket, pattern, callback) => {
|
|
1361
|
+
// Subscribe on state changes by pattern. Same as `subscribe`. The events will come as 'stateChange' events to the socket.
|
|
1362
|
+
// @param {string} pattern - pattern like 'system.adapter.*' or array of states like ['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
|
|
1363
|
+
// @param {function} callback - `function (error)`
|
|
1364
|
+
return this._subscribeStates(socket, pattern, callback);
|
|
1365
|
+
}
|
|
1212
1366
|
|
|
1213
|
-
this.commands['unsubscribe'] = (socket, pattern, callback) =>
|
|
1214
|
-
|
|
1367
|
+
this.commands['unsubscribe'] = (socket, pattern, callback) => {
|
|
1368
|
+
// Unsubscribe from state changes by pattern.
|
|
1369
|
+
// @param {string} pattern - pattern like 'system.adapter.*' or array of states like ['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
|
|
1370
|
+
// @param {function} callback - `function (error)`
|
|
1371
|
+
return this._unsubscribeStates(socket, pattern, callback);
|
|
1372
|
+
}
|
|
1373
|
+
this.commands['unsubscribeStates'] = (socket, pattern, callback) => {
|
|
1374
|
+
// Unsubscribe from state changes by pattern. Same as `unsubscribe`.
|
|
1375
|
+
// @param {string} pattern - pattern like 'system.adapter.*' or array of states like ['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
|
|
1376
|
+
// @param {function} callback - `function (error)`
|
|
1377
|
+
return this._unsubscribeStates(socket, pattern, callback);
|
|
1378
|
+
}
|
|
1215
1379
|
}
|
|
1216
1380
|
|
|
1217
1381
|
__initCommandsObjects() {
|
|
1218
1382
|
this.commands['getObject'] = (socket, id, callback) => {
|
|
1383
|
+
// Get one object
|
|
1384
|
+
// @param {string} id - object ID.
|
|
1385
|
+
// @param {function} callback - `function (error, obj)`
|
|
1219
1386
|
if (this._checkPermissions(socket, 'getObject', callback, id)) {
|
|
1220
1387
|
try {
|
|
1221
1388
|
this.adapter.getForeignObject(id, {user: socket._acl.user}, (error, obj) => {
|
|
@@ -1234,6 +1401,9 @@ class SocketCommands {
|
|
|
1234
1401
|
|
|
1235
1402
|
// not admin version of "all objects"
|
|
1236
1403
|
this.commands['getObjects'] = (socket, callback) => {
|
|
1404
|
+
// Get all objects that are relevant for web: all states and enums with rooms
|
|
1405
|
+
// @param {string} id - object ID.
|
|
1406
|
+
// @param {function} callback - `function (error, obj)`
|
|
1237
1407
|
if (this._checkPermissions(socket, 'getObjects', callback)) {
|
|
1238
1408
|
try {
|
|
1239
1409
|
this.adapter.getForeignObjects('*', 'state', 'rooms', {user: socket._acl.user}, (error, objs) => {
|
|
@@ -1256,6 +1426,9 @@ class SocketCommands {
|
|
|
1256
1426
|
};
|
|
1257
1427
|
|
|
1258
1428
|
this.commands['subscribeObjects'] = (socket, pattern, callback) => {
|
|
1429
|
+
// Subscribe on object changes by pattern. The events will come as 'objectChange' events to the socket.
|
|
1430
|
+
// @param {string} pattern - pattern like 'system.adapter.*' or array of IDs like ['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
|
|
1431
|
+
// @param {function} callback - `function (error)`
|
|
1259
1432
|
if (this._checkPermissions(socket, 'subscribeObjects', callback, pattern)) {
|
|
1260
1433
|
try {
|
|
1261
1434
|
if (pattern && typeof pattern === 'object' && pattern instanceof Array) {
|
|
@@ -1277,6 +1450,9 @@ class SocketCommands {
|
|
|
1277
1450
|
};
|
|
1278
1451
|
|
|
1279
1452
|
this.commands['unsubscribeObjects'] = (socket, pattern, callback) => {
|
|
1453
|
+
// Unsubscribe on object changes by pattern.
|
|
1454
|
+
// @param {string} pattern - pattern like 'system.adapter.*' or array of IDs like ['system.adapter.admin.0.memRss', 'system.adapter.admin.0.memHeapTotal']
|
|
1455
|
+
// @param {function} callback - `function (error)`
|
|
1280
1456
|
if (this._checkPermissions(socket, 'unsubscribeObjects', callback, pattern)) {
|
|
1281
1457
|
try {
|
|
1282
1458
|
if (pattern && typeof pattern === 'object' && pattern instanceof Array) {
|
|
@@ -1298,6 +1474,11 @@ class SocketCommands {
|
|
|
1298
1474
|
};
|
|
1299
1475
|
|
|
1300
1476
|
this.commands['getObjectView'] = (socket, design, search, params, callback) => {
|
|
1477
|
+
// Make a query to the object database.
|
|
1478
|
+
// @param {string} design - 'system' or other designs like `custom`, but it must exist object `_design/custom`. Too 99,9% use `system`.
|
|
1479
|
+
// @param {string} search - object type, like `state`, `instance`, `adapter`, `host`, ...
|
|
1480
|
+
// @param {string} params - parameters for the query in form `{startkey: 'system.adapter.', endkey: 'system.adapter.\u9999'}`
|
|
1481
|
+
// @param {function} callback - `function (error)`
|
|
1301
1482
|
if (typeof callback === 'function') {
|
|
1302
1483
|
if (this._checkPermissions(socket, 'getObjectView', callback, search)) {
|
|
1303
1484
|
try {
|
|
@@ -1313,6 +1494,10 @@ class SocketCommands {
|
|
|
1313
1494
|
};
|
|
1314
1495
|
|
|
1315
1496
|
this.commands['setObject'] = (socket, id, obj, callback) => {
|
|
1497
|
+
// Set object.
|
|
1498
|
+
// @param {string} id - object ID
|
|
1499
|
+
// @param {object} obj - object itself
|
|
1500
|
+
// @param {function} callback - `function (error)`
|
|
1316
1501
|
if (this._checkPermissions(socket, 'setObject', callback, id)) {
|
|
1317
1502
|
try {
|
|
1318
1503
|
this.adapter.setForeignObject(id, obj, {user: socket._acl.user}, (error, ...args) =>
|