@iobroker/socket-classes 0.5.3 → 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.
@@ -483,7 +483,7 @@ class SocketCommands {
483
483
 
484
484
  _subscribeStates(socket, pattern, callback) {
485
485
  if (this._checkPermissions(socket, 'subscribe', callback, pattern)) {
486
- if (pattern && typeof pattern === 'object' && pattern instanceof Array) {
486
+ if (Array.isArray(pattern)) {
487
487
  for (let p = 0; p < pattern.length; p++) {
488
488
  this.subscribe(socket, 'stateChange', pattern[p]);
489
489
  }
@@ -515,7 +515,7 @@ class SocketCommands {
515
515
 
516
516
  _subscribeFiles(socket, id, pattern, callback) {
517
517
  if (this._checkPermissions(socket, 'subscribeFiles', callback, pattern)) {
518
- if (pattern && typeof pattern === 'object' && pattern instanceof Array) {
518
+ if (Array.isArray(pattern)) {
519
519
  for (let p = 0; p < pattern.length; p++) {
520
520
  this.subscribe(socket, 'fileChange', id, pattern[p]);
521
521
  }
@@ -531,12 +531,12 @@ class SocketCommands {
531
531
 
532
532
  _unsubscribeFiles(socket, id, pattern, callback) {
533
533
  if (this._checkPermissions(socket, 'unsubscribeFiles', callback, pattern)) {
534
- if (pattern && typeof pattern === 'object' && pattern instanceof Array) {
534
+ if (Array.isArray(pattern)) {
535
535
  for (let p = 0; p < pattern.length; p++) {
536
536
  this.unsubscribe(socket, 'fileChange', id, pattern[p]);
537
537
  }
538
538
  } else {
539
- this.unsubscribe(socket, 'fileChange', pattern);
539
+ this.unsubscribe(socket, 'fileChange', id, pattern);
540
540
  }
541
541
 
542
542
  this.adapter.log.level === 'debug' && this._showSubscribes(socket, 'fileChange');
@@ -595,6 +595,10 @@ class SocketCommands {
595
595
 
596
596
  __initCommandsCommon() {
597
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)`
598
602
  if (socket && socket.___socket) {
599
603
  socket = socket.___socket;
600
604
  }
@@ -615,10 +619,15 @@ class SocketCommands {
615
619
  };
616
620
 
617
621
  this.commands['error'] = (socket, error) => {
622
+ // Write error into ioBroker log
623
+ // @param {string} error - error text
618
624
  this.adapter.log.error('Socket error: ' + error);
619
625
  };
620
626
 
621
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'.
622
631
  if (level === 'error') {
623
632
  this.adapter.log.error(text);
624
633
  } else if (level === 'warn') {
@@ -632,6 +641,10 @@ class SocketCommands {
632
641
 
633
642
  // new History
634
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)`
635
648
  if (this._checkPermissions(socket, 'getStateHistory', callback, id)) {
636
649
  if (typeof options === 'string') {
637
650
  options = {
@@ -653,6 +666,9 @@ class SocketCommands {
653
666
 
654
667
  // HTTP
655
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)`
656
672
  if (this._checkPermissions(socket, 'httpGet', callback, url)) {
657
673
  axios = axios || require('axios');
658
674
  this.adapter.log.debug('httpGet: ' + url);
@@ -672,6 +688,11 @@ class SocketCommands {
672
688
 
673
689
  // commands
674
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)`
675
696
  if (this._checkPermissions(socket, 'sendTo', callback, command)) {
676
697
  try {
677
698
  this.adapter.sendTo(adapterInstance, command, message, res =>
@@ -687,8 +708,12 @@ class SocketCommands {
687
708
  const protectedCommands = ['cmdExec', 'getLocationOnDisk', 'getDiagData', 'getDevList', 'delLogs', 'writeDirAsZip', 'writeObjectsAsZip', 'readObjectsAsZip', 'checkLogging', 'updateMultihost', 'rebuildAdapter'];
688
709
 
689
710
  this.commands['sendToHost'] = (socket, host, command, message, callback) => {
690
- // host can answer following commands: cmdExec, getRepository, getInstalled, getInstalledAdapter, getVersion, getDiagData, getLocationOnDisk, getDevList, getLogs, getHostInfo,
691
- // 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)`
692
717
  if (this._checkPermissions(socket, protectedCommands.includes(command) ? 'cmdExec' : 'sendToHost', callback, command)) {
693
718
  // Try to decode this file locally as redis has a limitation for files bigger than 20MB
694
719
  if (command === 'writeDirAsZip' && message && message.data.length > 1024 * 1024) {
@@ -733,6 +758,8 @@ class SocketCommands {
733
758
  };
734
759
 
735
760
  this.commands['authEnabled'] = (socket, callback) => {
761
+ // Ask server is authentication enabled and if the user authenticated
762
+ // @param {function} callback - `function (isAuthenticationUsed, userName)`
736
763
  if (this._checkPermissions(socket, 'authEnabled', callback)) {
737
764
  if (typeof callback === 'function') {
738
765
  callback(this.adapter.config.auth, (socket._acl.user || '').replace(/^system\.user\./, ''));
@@ -743,10 +770,14 @@ class SocketCommands {
743
770
  };
744
771
 
745
772
  this.commands['logout'] = (socket, callback) => {
773
+ // Logout user
774
+ // @param {function} callback - function (error)
746
775
  this.adapter.destroySession(socket._sessionID, callback);
747
776
  };
748
777
 
749
778
  this.commands['listPermissions'] = (socket, callback) => {
779
+ // List commands and permissions
780
+ // @param {function} callback - `function (permissions)`
750
781
  if (typeof callback === 'function') {
751
782
  callback(SocketCommands.COMMANDS_PERMISSIONS);
752
783
  } else {
@@ -755,6 +786,8 @@ class SocketCommands {
755
786
  };
756
787
 
757
788
  this.commands['getUserPermissions'] = (socket, callback) => {
789
+ // Get user permissions
790
+ // @param {function} callback - `function (error, permissions)`
758
791
  if (this._checkPermissions(socket, 'getUserPermissions', callback)) {
759
792
  if (typeof callback === 'function') {
760
793
  callback(null, socket._acl);
@@ -765,6 +798,8 @@ class SocketCommands {
765
798
  };
766
799
 
767
800
  this.commands['getVersion'] = (socket, callback) => {
801
+ // Get adapter version. Not the socket-classes version!
802
+ // @param {function} callback - `function (error, adapterVersion, adapterName)`
768
803
  if (this._checkPermissions(socket, 'getVersion', callback)) {
769
804
  if (typeof callback === 'function') {
770
805
  callback(null, this.adapter.version, this.adapter.name);
@@ -775,6 +810,8 @@ class SocketCommands {
775
810
  };
776
811
 
777
812
  this.commands['getAdapterName'] = (socket, callback) => {
813
+ // Get adapter name. Not the socket-classes version!
814
+ // @param {function} callback - `function (error, adapterVersion)`
778
815
  if (this._checkPermissions(socket, 'getAdapterName', callback)) {
779
816
  if (typeof callback === 'function') {
780
817
  callback(null, this.adapter.name || 'unknown');
@@ -783,12 +820,15 @@ class SocketCommands {
783
820
  }
784
821
  }
785
822
  };
786
-
787
823
  }
788
824
 
789
825
  __initCommandsFiles() {
790
826
  // file operations
791
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)`
792
832
  if (this._checkPermissions(socket, 'readFile', callback, fileName)) {
793
833
  try {
794
834
  this.adapter.readFile(_adapter, fileName, {user: socket._acl.user}, (error, ...args) =>
@@ -801,6 +841,10 @@ class SocketCommands {
801
841
  };
802
842
 
803
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)`
804
848
  if (this._checkPermissions(socket, 'readFile64', callback, fileName)) {
805
849
  try {
806
850
  this.adapter.readFile(_adapter, fileName, {user: socket._acl.user}, (error, buffer, type) => {
@@ -836,6 +880,12 @@ class SocketCommands {
836
880
  };
837
881
 
838
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)`
839
889
  if (typeof options === 'function') {
840
890
  callback = options;
841
891
  options = {user: socket._acl.user};
@@ -863,6 +913,12 @@ class SocketCommands {
863
913
 
864
914
  // this function is overloaded in admin (because admin accepts only base64)
865
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)`
866
922
  if (this._checkPermissions(socket, 'writeFile', callback, fileName)) {
867
923
  if (typeof options === 'function') {
868
924
  callback = options;
@@ -883,6 +939,10 @@ class SocketCommands {
883
939
  };
884
940
 
885
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)`
886
946
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
887
947
  try {
888
948
  this._unlink(_adapter, name, {user: socket._acl.user})
@@ -896,6 +956,10 @@ class SocketCommands {
896
956
  };
897
957
 
898
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)`
899
963
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
900
964
  try {
901
965
  this.adapter.unlink(_adapter, name, {user: socket._acl.user}, (error, ...args) =>
@@ -908,6 +972,10 @@ class SocketCommands {
908
972
  };
909
973
 
910
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)`
911
979
  if (this._checkPermissions(socket, 'unlink', callback, name)) {
912
980
  try {
913
981
  this._unlink(_adapter, name, {user: socket._acl.user})
@@ -921,6 +989,11 @@ class SocketCommands {
921
989
  };
922
990
 
923
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)`
924
997
  if (this._checkPermissions(socket, 'rename', callback, oldName)) {
925
998
  try {
926
999
  this.adapter.rename(_adapter, oldName, newName, {user: socket._acl.user}, (error, ...args) =>
@@ -933,6 +1006,11 @@ class SocketCommands {
933
1006
  };
934
1007
 
935
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)`
936
1014
  if (this._checkPermissions(socket, 'rename', callback, oldName)) {
937
1015
  try {
938
1016
  this._rename(_adapter, oldName, newName, {user: socket._acl.user})
@@ -946,6 +1024,10 @@ class SocketCommands {
946
1024
  };
947
1025
 
948
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)`
949
1031
  if (this._checkPermissions(socket, 'mkdir', callback, dirName)) {
950
1032
  try {
951
1033
  this.adapter.mkdir(_adapter, dirName, {user: socket._acl.user}, (error, ...args) =>
@@ -958,6 +1040,11 @@ class SocketCommands {
958
1040
  };
959
1041
 
960
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}`
961
1048
  if (typeof options === 'function') {
962
1049
  callback = options;
963
1050
  options = {};
@@ -981,6 +1068,11 @@ class SocketCommands {
981
1068
  };
982
1069
 
983
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)`
984
1076
  if (typeof options === 'function') {
985
1077
  callback = options;
986
1078
  options = {};
@@ -1004,6 +1096,11 @@ class SocketCommands {
1004
1096
  };
1005
1097
 
1006
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)`
1007
1104
  if (this._checkPermissions(socket, 'chownFile', callback, fileName)) {
1008
1105
  options = options || {};
1009
1106
  options.user = socket._acl.user;
@@ -1018,6 +1115,10 @@ class SocketCommands {
1018
1115
  };
1019
1116
 
1020
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)`
1021
1122
  if (this._checkPermissions(socket, 'fileExists', callback, fileName)) {
1022
1123
  try {
1023
1124
  this.adapter.fileExists(_adapter, fileName, {user: socket._acl.user}, (error, ...args) =>
@@ -1029,11 +1130,27 @@ class SocketCommands {
1029
1130
  }
1030
1131
  };
1031
1132
 
1032
- this.commands['subscribeFiles'] = (socket, id, pattern, callback) => this._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
+ }
1033
1140
 
1034
- this.commands['unsubscribeFiles'] = (socket, id, pattern, callback) => this._unsubscribeFiles(socket, id, pattern, callback);
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)`
1146
+
1147
+ return this._unsubscribeFiles(socket, id, pattern, callback);
1148
+ }
1035
1149
 
1036
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: {...}}`
1037
1154
  if (typeof callback === 'function') {
1038
1155
  if (this._checkPermissions(socket, 'getObject', callback)) {
1039
1156
  let _adapterName = adapterName !== undefined && adapterName !== null ? adapterName : this.adapterName || '';
@@ -1071,6 +1188,9 @@ class SocketCommands {
1071
1188
 
1072
1189
  __initCommandsStates() {
1073
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': {...}}}`
1074
1194
  if (this._checkPermissions(socket, 'getStates', callback, pattern)) {
1075
1195
  if (typeof pattern === 'function') {
1076
1196
  callback = pattern;
@@ -1092,7 +1212,10 @@ class SocketCommands {
1092
1212
 
1093
1213
  // this function is overloaded in admin
1094
1214
  this.commands['delObject'] = (socket, id, options, callback) => {
1095
- // only flot allowed
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)`
1096
1219
  if (id.startsWith('flot.')) {
1097
1220
  if (this._checkPermissions(socket, 'delObject', callback, id)) {
1098
1221
  try {
@@ -1109,6 +1232,9 @@ class SocketCommands {
1109
1232
  };
1110
1233
 
1111
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'}`
1112
1238
  if (this._checkPermissions(socket, 'getState', callback, id)) {
1113
1239
  if (typeof callback === 'function') {
1114
1240
  if (this.states && this.states[id]) {
@@ -1129,6 +1255,10 @@ class SocketCommands {
1129
1255
  };
1130
1256
 
1131
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'}`
1132
1262
  if (this._checkPermissions(socket, 'setState', callback, id)) {
1133
1263
  if (typeof state !== 'object') {
1134
1264
  state = {val: state};
@@ -1150,6 +1280,9 @@ class SocketCommands {
1150
1280
  };
1151
1281
 
1152
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)`
1153
1286
  if (this._checkPermissions(socket, 'getState', callback, id)) {
1154
1287
  if (typeof callback === 'function') {
1155
1288
  try {
@@ -1187,6 +1320,10 @@ class SocketCommands {
1187
1320
  };
1188
1321
 
1189
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)`
1190
1327
  if (this._checkPermissions(socket, 'setState', callback, id)) {
1191
1328
  if (typeof callback === 'function') {
1192
1329
  let data = null;
@@ -1214,15 +1351,38 @@ class SocketCommands {
1214
1351
  }
1215
1352
  };
1216
1353
 
1217
- this.commands['subscribe'] = (socket, pattern, callback) => this._subscribeStates(socket, pattern, callback);
1218
- this.commands['subscribeStates'] = (socket, pattern, callback) => this._subscribeStates(socket, pattern, callback);
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
+ }
1219
1366
 
1220
- this.commands['unsubscribe'] = (socket, pattern, callback) => this._unsubscribeStates(socket, pattern, callback);
1221
- this.commands['unsubscribeStates'] = (socket, pattern, callback) => this._unsubscribeStates(socket, pattern, callback);
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
+ }
1222
1379
  }
1223
1380
 
1224
1381
  __initCommandsObjects() {
1225
1382
  this.commands['getObject'] = (socket, id, callback) => {
1383
+ // Get one object
1384
+ // @param {string} id - object ID.
1385
+ // @param {function} callback - `function (error, obj)`
1226
1386
  if (this._checkPermissions(socket, 'getObject', callback, id)) {
1227
1387
  try {
1228
1388
  this.adapter.getForeignObject(id, {user: socket._acl.user}, (error, obj) => {
@@ -1241,6 +1401,9 @@ class SocketCommands {
1241
1401
 
1242
1402
  // not admin version of "all objects"
1243
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)`
1244
1407
  if (this._checkPermissions(socket, 'getObjects', callback)) {
1245
1408
  try {
1246
1409
  this.adapter.getForeignObjects('*', 'state', 'rooms', {user: socket._acl.user}, (error, objs) => {
@@ -1263,6 +1426,9 @@ class SocketCommands {
1263
1426
  };
1264
1427
 
1265
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)`
1266
1432
  if (this._checkPermissions(socket, 'subscribeObjects', callback, pattern)) {
1267
1433
  try {
1268
1434
  if (pattern && typeof pattern === 'object' && pattern instanceof Array) {
@@ -1284,6 +1450,9 @@ class SocketCommands {
1284
1450
  };
1285
1451
 
1286
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)`
1287
1456
  if (this._checkPermissions(socket, 'unsubscribeObjects', callback, pattern)) {
1288
1457
  try {
1289
1458
  if (pattern && typeof pattern === 'object' && pattern instanceof Array) {
@@ -1305,6 +1474,11 @@ class SocketCommands {
1305
1474
  };
1306
1475
 
1307
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)`
1308
1482
  if (typeof callback === 'function') {
1309
1483
  if (this._checkPermissions(socket, 'getObjectView', callback, search)) {
1310
1484
  try {
@@ -1320,6 +1494,10 @@ class SocketCommands {
1320
1494
  };
1321
1495
 
1322
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)`
1323
1501
  if (this._checkPermissions(socket, 'setObject', callback, id)) {
1324
1502
  try {
1325
1503
  this.adapter.setForeignObject(id, obj, {user: socket._acl.user}, (error, ...args) =>