@iobroker/adapter-react-v5 2.1.4 → 2.1.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.
Files changed (85) hide show
  1. package/Components/404.js.map +1 -1
  2. package/Components/ColorPicker.js.map +1 -1
  3. package/Components/ComplexCron.js.map +1 -1
  4. package/Components/FileBrowser.js +1 -1
  5. package/Components/FileBrowser.js.map +1 -1
  6. package/Components/FileViewer.js.map +1 -1
  7. package/Components/Icon.js.map +1 -1
  8. package/Components/IconPicker.js.map +1 -1
  9. package/Components/IconSelector.js.map +1 -1
  10. package/Components/Image.js.map +1 -1
  11. package/Components/Loader.js.map +1 -1
  12. package/Components/Loaders/PT.css +1 -1
  13. package/Components/Loaders/PT.js.map +1 -1
  14. package/Components/Loaders/Vendor.css +1 -1
  15. package/Components/Loaders/Vendor.js.map +1 -1
  16. package/Components/Logo.js +3 -3
  17. package/Components/Logo.js.map +1 -1
  18. package/Components/MDUtils.js.map +1 -1
  19. package/Components/ObjectBrowser.js +23 -28
  20. package/Components/ObjectBrowser.js.map +1 -1
  21. package/Components/Router.js.map +1 -1
  22. package/Components/SaveCloseButtons.js.map +1 -1
  23. package/Components/Schedule.js.map +1 -1
  24. package/Components/SelectWithIcon.js +1 -1
  25. package/Components/SelectWithIcon.js.map +1 -1
  26. package/Components/SimpleCron/cron2text.js.map +1 -1
  27. package/Components/SimpleCron/cronText.js.map +1 -1
  28. package/Components/SimpleCron/index.js.map +1 -1
  29. package/Components/SimpleCron/jquery.cron.locale.js.map +1 -1
  30. package/Components/TabContainer.js.map +1 -1
  31. package/Components/TabContent.js.map +1 -1
  32. package/Components/TabHeader.js.map +1 -1
  33. package/Components/TextWithIcon.js.map +1 -1
  34. package/Components/ToggleThemeMenu.js.map +1 -1
  35. package/Components/TreeTable.js.map +1 -1
  36. package/Components/Utils.js +3 -0
  37. package/Components/Utils.js.map +1 -1
  38. package/Components/copy-to-clipboard.js.map +1 -1
  39. package/Components/loader.css +1 -1
  40. package/Connection.js +3374 -0
  41. package/Connection.js.map +1 -0
  42. package/Dialogs/ComplexCron.js.map +1 -1
  43. package/Dialogs/Confirm.js.map +1 -1
  44. package/Dialogs/Cron.js.map +1 -1
  45. package/Dialogs/Error.js.map +1 -1
  46. package/Dialogs/Message.js.map +1 -1
  47. package/Dialogs/SelectID.js.map +1 -1
  48. package/Dialogs/SimpleCron.js.map +1 -1
  49. package/Dialogs/TextInput.js.map +1 -1
  50. package/GenericApp.js +4 -1
  51. package/GenericApp.js.map +1 -1
  52. package/Prompt.js +21 -0
  53. package/Prompt.js.map +1 -0
  54. package/README.md +5 -1
  55. package/Theme.js +422 -0
  56. package/Theme.js.map +1 -0
  57. package/i18n/de.json +3 -3
  58. package/i18n/en.json +3 -3
  59. package/i18n/es.json +3 -3
  60. package/i18n/fr.json +3 -3
  61. package/i18n/it.json +3 -3
  62. package/i18n/nl.json +3 -3
  63. package/i18n/pl.json +3 -3
  64. package/i18n/pt.json +3 -3
  65. package/i18n/ru.json +3 -3
  66. package/i18n/zh-cn.json +3 -3
  67. package/i18n.js +184 -0
  68. package/i18n.js.map +1 -0
  69. package/icons/IconAdapter.js.map +1 -1
  70. package/icons/IconAlias.js.map +1 -1
  71. package/icons/IconChannel.js.map +1 -1
  72. package/icons/IconClearFilter.js.map +1 -1
  73. package/icons/IconClosed.js.map +1 -1
  74. package/icons/IconCopy.js.map +1 -1
  75. package/icons/IconDevice.js.map +1 -1
  76. package/icons/IconDocument.js.map +1 -1
  77. package/icons/IconExpert.js.map +1 -1
  78. package/icons/IconFx.js.map +1 -1
  79. package/icons/IconInstance.js.map +1 -1
  80. package/icons/IconLogout.js.map +1 -1
  81. package/icons/IconOpen.js.map +1 -1
  82. package/icons/IconState.js.map +1 -1
  83. package/index.css +1 -1
  84. package/package.json +6 -4
  85. package/gulpfile.js +0 -113
package/Connection.js ADDED
@@ -0,0 +1,3374 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = exports.PROGRESS = exports.ERRORS = void 0;
7
+
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
+
12
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
13
+
14
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
15
+
16
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
+
18
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
19
+
20
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
21
+
22
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
23
+
24
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25
+
26
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
27
+
28
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
29
+
30
+ /** Possible progress states. */
31
+ var PROGRESS = {
32
+ /** The socket is connecting. */
33
+ CONNECTING: 0,
34
+
35
+ /** The socket is successfully connected. */
36
+ CONNECTED: 1,
37
+
38
+ /** All objects are loaded. */
39
+ OBJECTS_LOADED: 2,
40
+
41
+ /** The socket is ready for use. */
42
+ READY: 3
43
+ };
44
+ exports.PROGRESS = PROGRESS;
45
+ var PERMISSION_ERROR = 'permissionError';
46
+ var NOT_CONNECTED = 'notConnectedError';
47
+ var TIMEOUT_FOR_ADMIN4 = 1300;
48
+ var ERRORS = {
49
+ PERMISSION_ERROR: PERMISSION_ERROR,
50
+ NOT_CONNECTED: NOT_CONNECTED
51
+ };
52
+ exports.ERRORS = ERRORS;
53
+
54
+ function fixAdminUI(obj) {
55
+ if (obj && obj.common && !obj.common.adminUI) {
56
+ if (obj.common.noConfig) {
57
+ obj.common.adminUI = obj.common.adminUI || {};
58
+ obj.common.adminUI.config = 'none';
59
+ } else if (obj.common.jsonConfig) {
60
+ obj.common.adminUI = obj.common.adminUI || {};
61
+ obj.common.adminUI.config = 'json';
62
+ } else if (obj.common.materialize) {
63
+ obj.common.adminUI = obj.common.adminUI || {};
64
+ obj.common.adminUI.config = 'materialize';
65
+ } else {
66
+ obj.common.adminUI = obj.common.adminUI || {};
67
+ obj.common.adminUI.config = 'html';
68
+ }
69
+
70
+ if (obj.common.jsonCustom) {
71
+ obj.common.adminUI = obj.common.adminUI || {};
72
+ obj.common.adminUI.custom = 'json';
73
+ } else if (obj.common.supportCustoms) {
74
+ obj.common.adminUI = obj.common.adminUI || {};
75
+ obj.common.adminUI.custom = 'json';
76
+ }
77
+
78
+ if (obj.common.materializeTab && obj.common.adminTab) {
79
+ obj.common.adminUI = obj.common.adminUI || {};
80
+ obj.common.adminUI.tab = 'materialize';
81
+ } else if (obj.common.adminTab) {
82
+ obj.common.adminUI = obj.common.adminUI || {};
83
+ obj.common.adminUI.tab = 'html';
84
+ }
85
+
86
+ obj.common.adminUI && console.debug("Please add to \"".concat(obj._id.replace(/\.\d+$/, ''), "\" common.adminUI=").concat(JSON.stringify(obj.common.adminUI)));
87
+ }
88
+
89
+ return obj;
90
+ }
91
+
92
+ var Connection = /*#__PURE__*/function () {
93
+ /**
94
+ * @param {import('./types').ConnectionProps} props
95
+ */
96
+ function Connection(props) {
97
+ var _this = this;
98
+
99
+ _classCallCheck(this, Connection);
100
+
101
+ props = props || {
102
+ protocol: window.location.protocol,
103
+ host: window.location.hostname
104
+ };
105
+ this.props = props;
106
+ this.autoSubscribes = this.props.autoSubscribes || [];
107
+ this.autoSubscribeLog = this.props.autoSubscribeLog;
108
+ this.props.protocol = this.props.protocol || window.location.protocol;
109
+ this.props.host = this.props.host || window.location.hostname;
110
+ this.props.port = this.props.port || (window.location.port === '3000' ? Connection.isWeb() ? 8082 : 8081 : window.location.port);
111
+ this.props.ioTimeout = Math.max(this.props.ioTimeout || 20000, 20000);
112
+ this.props.cmdTimeout = Math.max(this.props.cmdTimeout || 5000, 5000); // breaking change. Do not load all objects by default is true
113
+
114
+ this.doNotLoadAllObjects = this.props.doNotLoadAllObjects === undefined ? true : this.props.doNotLoadAllObjects;
115
+ this.doNotLoadACL = this.props.doNotLoadACL === undefined ? true : this.props.doNotLoadACL;
116
+ /** @type {Record<string, ioBroker.State>} */
117
+
118
+ this.states = {};
119
+ this.objects = null;
120
+ this.acl = null;
121
+ this.firstConnect = true;
122
+ this.waitForRestart = false;
123
+ /** @type {ioBroker.Languages} */
124
+
125
+ this.systemLang = 'en';
126
+ this.connected = false;
127
+ this._waitForFirstConnection = new Promise(function (resolve) {
128
+ _this._waitForFirstConnectionResolve = resolve;
129
+ });
130
+ /** @type {Record<string, { reg: RegExp; cbs: ioBroker.StateChangeHandler[]}>} */
131
+
132
+ this.statesSubscribes = {}; // subscribe for states
133
+
134
+ /** @type {Record<string, { reg: RegExp; cbs: import('./types').ObjectChangeHandler[]}>} */
135
+
136
+ this.objectsSubscribes = {}; // subscribe for objects
137
+
138
+ this.onProgress = this.props.onProgress || function () {};
139
+
140
+ this.onError = this.props.onError || function (err) {
141
+ console.error(err);
142
+ };
143
+
144
+ this.loaded = false;
145
+ this.loadTimer = null;
146
+ this.loadCounter = 0;
147
+ this.admin5only = this.props.admin5only || false;
148
+ /** @type {((connected: boolean) => void)[]} */
149
+
150
+ this.onConnectionHandlers = [];
151
+ /** @type {((message: string) => void)[]} */
152
+
153
+ this.onLogHandlers = [];
154
+ /** @type {Record<string, Promise<any>>} */
155
+
156
+ this._promises = {};
157
+
158
+ this.log.error = function (text) {
159
+ return _this.log(text, 'error');
160
+ };
161
+
162
+ this.log.warn = function (text) {
163
+ return _this.log(text, 'warn');
164
+ };
165
+
166
+ this.log.info = function (text) {
167
+ return _this.log(text, 'info');
168
+ };
169
+
170
+ this.log.debug = function (text) {
171
+ return _this.log(text, 'debug');
172
+ };
173
+
174
+ this.log.silly = function (text) {
175
+ return _this.log(text, 'silly');
176
+ };
177
+
178
+ this.startSocket();
179
+ }
180
+ /**
181
+ * Checks if this connection is running in a web adapter and not in an admin.
182
+ * @returns {boolean} True if running in a web adapter or in a socketio adapter.
183
+ */
184
+
185
+
186
+ _createClass(Connection, [{
187
+ key: "startSocket",
188
+ value:
189
+ /**
190
+ * Starts the socket.io connection.
191
+ * @returns {void}
192
+ */
193
+ function startSocket() {
194
+ var _this2 = this;
195
+
196
+ // if socket io is not yet loaded
197
+ if (typeof window.io === 'undefined') {
198
+ // if in index.html the onLoad function not defined
199
+ if (typeof window.registerSocketOnLoad !== 'function') {
200
+ // poll if loaded
201
+ this.scriptLoadCounter = this.scriptLoadCounter || 0;
202
+ this.scriptLoadCounter++;
203
+
204
+ if (this.scriptLoadCounter < 30) {
205
+ // wait till the script loaded
206
+ setTimeout(function () {
207
+ return _this2.startSocket();
208
+ }, 100);
209
+ return;
210
+ } else {
211
+ window.alert('Cannot load socket.io.js!');
212
+ }
213
+ } else {
214
+ // register on load
215
+ window.registerSocketOnLoad(function () {
216
+ return _this2.startSocket();
217
+ });
218
+ }
219
+
220
+ return;
221
+ } else {
222
+ // socket was initialized, do not repeat
223
+ if (this._socket) {
224
+ return;
225
+ }
226
+ }
227
+
228
+ var host = this.props.host;
229
+ var port = this.props.port;
230
+ var protocol = this.props.protocol.replace(':', ''); // if web adapter, socket io could be on other port or even host
231
+
232
+ if (window.socketUrl) {
233
+ var parts = window.socketUrl.split(':');
234
+ host = parts[0] || host;
235
+ port = parts[1] || port;
236
+
237
+ if (host.includes('://')) {
238
+ parts = host.split('://');
239
+ protocol = parts[0];
240
+ host = parts[1];
241
+ }
242
+ }
243
+
244
+ var url = port ? "".concat(protocol, "://").concat(host, ":").concat(port) : "".concat(protocol, "://").concat(host);
245
+ this._socket = window.io.connect(url, {
246
+ query: 'ws=true',
247
+ name: this.props.name,
248
+ timeout: this.props.ioTimeout
249
+ });
250
+
251
+ this._socket.on('connect', function (noTimeout) {
252
+ // If the user is not admin it takes some time to install the handlers, because all rights must be checked
253
+ if (noTimeout !== true) {
254
+ setTimeout(function () {
255
+ return _this2.getVersion().then(function (info) {
256
+ var _info$version$split = info.version.split('.'),
257
+ _info$version$split2 = _slicedToArray(_info$version$split, 3),
258
+ major = _info$version$split2[0],
259
+ minor = _info$version$split2[1],
260
+ patch = _info$version$split2[2];
261
+
262
+ var v = parseInt(major, 10) * 10000 + parseInt(minor, 10) * 100 + parseInt(patch, 10);
263
+
264
+ if (v < 40102) {
265
+ _this2._authTimer = null; // possible this is old version of admin
266
+
267
+ _this2.onPreConnect(false, false);
268
+ } else {
269
+ _this2._socket.emit('authenticate', function (isOk, isSecure) {
270
+ return _this2.onPreConnect(isOk, isSecure);
271
+ });
272
+ }
273
+ });
274
+ }, 500);
275
+ } else {
276
+ // iobroker websocket waits, till all handlers are installed
277
+ _this2._socket.emit('authenticate', function (isOk, isSecure) {
278
+ return _this2.onPreConnect(isOk, isSecure);
279
+ });
280
+ }
281
+ });
282
+
283
+ this._socket.on('reconnect', function () {
284
+ _this2.onProgress(PROGRESS.READY);
285
+
286
+ _this2.connected = true;
287
+
288
+ if (_this2.waitForRestart) {
289
+ window.location.reload(false);
290
+ } else {
291
+ _this2._subscribe(true);
292
+
293
+ _this2.onConnectionHandlers.forEach(function (cb) {
294
+ return cb(true);
295
+ });
296
+ }
297
+ });
298
+
299
+ this._socket.on('disconnect', function () {
300
+ _this2.connected = false;
301
+ _this2.subscribed = false;
302
+
303
+ _this2.onProgress(PROGRESS.CONNECTING);
304
+
305
+ _this2.onConnectionHandlers.forEach(function (cb) {
306
+ return cb(false);
307
+ });
308
+ });
309
+
310
+ this._socket.on('reauthenticate', function () {
311
+ return _this2.authenticate();
312
+ });
313
+
314
+ this._socket.on('log', function (message) {
315
+ _this2.props.onLog && _this2.props.onLog(message);
316
+
317
+ _this2.onLogHandlers.forEach(function (cb) {
318
+ return cb(message);
319
+ });
320
+ });
321
+
322
+ this._socket.on('error', function (err) {
323
+ var _err = err || '';
324
+
325
+ if (typeof _err.toString !== 'function') {
326
+ _err = JSON.stringify(_err);
327
+ console.error("Received strange error: ".concat(_err));
328
+ }
329
+
330
+ _err = _err.toString();
331
+
332
+ if (_err.includes('User not authorized')) {
333
+ _this2.authenticate();
334
+ } else {
335
+ window.alert("Socket Error: ".concat(err));
336
+ }
337
+ });
338
+
339
+ this._socket.on('connect_error', function (err) {
340
+ return console.error("Connect error: ".concat(err));
341
+ });
342
+
343
+ this._socket.on('permissionError', function (err) {
344
+ return _this2.onError({
345
+ message: 'no permission',
346
+ operation: err.operation,
347
+ type: err.type,
348
+ id: err.id || ''
349
+ });
350
+ });
351
+
352
+ this._socket.on('objectChange', function (id, obj) {
353
+ return setTimeout(function () {
354
+ return _this2.objectChange(id, obj);
355
+ }, 0);
356
+ });
357
+
358
+ this._socket.on('stateChange', function (id, state) {
359
+ return setTimeout(function () {
360
+ return _this2.stateChange(id, state);
361
+ }, 0);
362
+ });
363
+
364
+ this._socket.on('cmdStdout', function (id, text) {
365
+ return _this2.onCmdStdoutHandler && _this2.onCmdStdoutHandler(id, text);
366
+ });
367
+
368
+ this._socket.on('cmdStderr', function (id, text) {
369
+ return _this2.onCmdStderrHandler && _this2.onCmdStderrHandler(id, text);
370
+ });
371
+
372
+ this._socket.on('cmdExit', function (id, exitCode) {
373
+ return _this2.onCmdExitHandler && _this2.onCmdExitHandler(id, exitCode);
374
+ });
375
+ }
376
+ /**
377
+ * Called internally.
378
+ * @private
379
+ * @param {boolean} isOk
380
+ * @param {boolean} isSecure
381
+ */
382
+
383
+ }, {
384
+ key: "onPreConnect",
385
+ value: function onPreConnect(isOk, isSecure) {
386
+ var _this3 = this;
387
+
388
+ if (this._authTimer) {
389
+ clearTimeout(this._authTimer);
390
+ this._authTimer = null;
391
+ }
392
+
393
+ this.connected = true;
394
+ this.isSecure = isSecure;
395
+
396
+ if (this.waitForRestart) {
397
+ window.location.reload(false);
398
+ } else {
399
+ if (this.firstConnect) {
400
+ // retry strategy
401
+ this.loadTimer = setTimeout(function () {
402
+ _this3.loadTimer = null;
403
+ _this3.loadCounter++;
404
+
405
+ if (_this3.loadCounter < 10) {
406
+ _this3.onConnect();
407
+ }
408
+ }, 1000);
409
+
410
+ if (!this.loaded) {
411
+ this.onConnect();
412
+ }
413
+ } else {
414
+ this.onProgress(PROGRESS.READY);
415
+ }
416
+
417
+ this._subscribe(true);
418
+
419
+ this.onConnectionHandlers.forEach(function (cb) {
420
+ return cb(true);
421
+ });
422
+ }
423
+
424
+ if (this._waitForFirstConnectionResolve) {
425
+ this._waitForFirstConnectionResolve();
426
+
427
+ this._waitForFirstConnectionResolve = null;
428
+ }
429
+ }
430
+ /**
431
+ * Checks if the socket is connected.
432
+ * @returns {boolean} true if connected.
433
+ */
434
+
435
+ }, {
436
+ key: "isConnected",
437
+ value: function isConnected() {
438
+ return this.connected;
439
+ }
440
+ /**
441
+ * Checks if the socket is connected.
442
+ * @returns {Promise<void>} Promise resolves if once connected.
443
+ */
444
+
445
+ }, {
446
+ key: "waitForFirstConnection",
447
+ value: function waitForFirstConnection() {
448
+ return this._waitForFirstConnection;
449
+ }
450
+ /**
451
+ * Called internally.
452
+ * @private
453
+ */
454
+
455
+ }, {
456
+ key: "_getUserPermissions",
457
+ value: function _getUserPermissions(cb) {
458
+ if (this.doNotLoadACL) {
459
+ return cb && cb();
460
+ } else {
461
+ this._socket.emit('getUserPermissions', cb);
462
+ }
463
+ }
464
+ /**
465
+ * Called internally.
466
+ * @private
467
+ */
468
+
469
+ }, {
470
+ key: "onConnect",
471
+ value: function onConnect() {
472
+ var _this4 = this;
473
+
474
+ this._getUserPermissions(function (err, acl) {
475
+ if (err) {
476
+ return _this4.onError('Cannot read user permissions: ' + err);
477
+ } else if (!_this4.doNotLoadACL) {
478
+ if (_this4.loaded) {
479
+ return;
480
+ }
481
+
482
+ _this4.loaded = true;
483
+ clearTimeout(_this4.loadTimer);
484
+ _this4.loadTimer = null;
485
+
486
+ _this4.onProgress(PROGRESS.CONNECTED);
487
+
488
+ _this4.firstConnect = false;
489
+ _this4.acl = acl;
490
+ } // Read system configuration
491
+
492
+
493
+ return (_this4.admin5only && !window.vendorPrefix ? _this4.getCompactSystemConfig() : _this4.getSystemConfig()).then(function (data) {
494
+ if (_this4.doNotLoadACL) {
495
+ if (_this4.loaded) {
496
+ return undefined;
497
+ }
498
+
499
+ _this4.loaded = true;
500
+ clearTimeout(_this4.loadTimer);
501
+ _this4.loadTimer = null;
502
+
503
+ _this4.onProgress(PROGRESS.CONNECTED);
504
+
505
+ _this4.firstConnect = false;
506
+ }
507
+
508
+ _this4.systemConfig = data;
509
+
510
+ if (_this4.systemConfig && _this4.systemConfig.common) {
511
+ _this4.systemLang = _this4.systemConfig.common.language;
512
+ } else {
513
+ _this4.systemLang = window.navigator.userLanguage || window.navigator.language;
514
+
515
+ if (_this4.systemLang !== 'en' && _this4.systemLang !== 'de' && _this4.systemLang !== 'ru') {
516
+ _this4.systemConfig.common.language = 'en';
517
+ _this4.systemLang = 'en';
518
+ }
519
+ }
520
+
521
+ _this4.props.onLanguage && _this4.props.onLanguage(_this4.systemLang);
522
+
523
+ if (!_this4.doNotLoadAllObjects) {
524
+ return _this4.getObjects().then(function () {
525
+ _this4.onProgress(PROGRESS.READY);
526
+
527
+ _this4.props.onReady && _this4.props.onReady(_this4.objects);
528
+ });
529
+ } else {
530
+ _this4.objects = _this4.admin5only ? {} : {
531
+ 'system.config': data
532
+ };
533
+
534
+ _this4.onProgress(PROGRESS.READY);
535
+
536
+ _this4.props.onReady && _this4.props.onReady(_this4.objects);
537
+ }
538
+
539
+ return undefined;
540
+ })["catch"](function (e) {
541
+ return _this4.onError('Cannot read system config: ' + e);
542
+ });
543
+ });
544
+ }
545
+ /**
546
+ * Called internally.
547
+ * @private
548
+ */
549
+
550
+ }, {
551
+ key: "authenticate",
552
+ value: function authenticate() {
553
+ if (window.location.search.includes('&href=')) {
554
+ window.location = "".concat(window.location.protocol, "//").concat(window.location.host).concat(window.location.pathname).concat(window.location.search).concat(window.location.hash);
555
+ } else {
556
+ window.location = "".concat(window.location.protocol, "//").concat(window.location.host).concat(window.location.pathname, "?login&href=").concat(window.location.search).concat(window.location.hash);
557
+ }
558
+ }
559
+ /**
560
+ * Subscribe to changes of the given state.
561
+ * @param {string} id The ioBroker state ID.
562
+ * @param {ioBroker.StateChangeHandler} cb The callback.
563
+ */
564
+
565
+ /**
566
+ * Subscribe to changes of the given state.
567
+ * @param {string} id The ioBroker state ID.
568
+ * @param {boolean} binary Set to true if the given state is binary and requires Base64 decoding.
569
+ * @param {ioBroker.StateChangeHandler} cb The callback.
570
+ */
571
+
572
+ }, {
573
+ key: "subscribeState",
574
+ value: function subscribeState(id, binary, cb) {
575
+ if (typeof binary === 'function') {
576
+ cb = binary;
577
+ binary = false;
578
+ }
579
+
580
+ if (!this.statesSubscribes[id]) {
581
+ var reg = id.replace(/\./g, '\\.').replace(/\*/g, '.*').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/\+/g, '\\+').replace(/\[/g, '\\[');
582
+
583
+ if (reg.indexOf('*') === -1) {
584
+ reg += '$';
585
+ }
586
+
587
+ this.statesSubscribes[id] = {
588
+ reg: new RegExp(reg),
589
+ cbs: []
590
+ };
591
+ this.statesSubscribes[id].cbs.push(cb);
592
+
593
+ if (this.connected) {
594
+ this._socket.emit('subscribe', id);
595
+ }
596
+ } else {
597
+ !this.statesSubscribes[id].cbs.includes(cb) && this.statesSubscribes[id].cbs.push(cb);
598
+ }
599
+
600
+ if (typeof cb === 'function' && this.connected) {
601
+ if (binary) {
602
+ this.getBinaryState(id).then(function (base64) {
603
+ return cb(id, base64);
604
+ })["catch"](function (e) {
605
+ return console.error("Cannot getForeignStates \"".concat(id, "\": ").concat(JSON.stringify(e)));
606
+ });
607
+ } else {
608
+ if (Connection.isWeb()) {
609
+ this._socket.emit('getStates', id, function (err, states) {
610
+ err && console.error("Cannot getForeignStates \"".concat(id, "\": ").concat(JSON.stringify(err)));
611
+ states && Object.keys(states).forEach(function (id) {
612
+ return cb(id, states[id]);
613
+ });
614
+ });
615
+ } else {
616
+ this._socket.emit('getForeignStates', id, function (err, states) {
617
+ err && console.error("Cannot getForeignStates \"".concat(id, "\": ").concat(JSON.stringify(err)));
618
+ states && Object.keys(states).forEach(function (id) {
619
+ return cb(id, states[id]);
620
+ });
621
+ });
622
+ }
623
+ }
624
+ }
625
+ }
626
+ /**
627
+ * Unsubscribes all callbacks from changes of the given state.
628
+ * @param {string} id The ioBroker state ID.
629
+ */
630
+
631
+ /**
632
+ * Unsubscribes the given callback from changes of the given state.
633
+ * @param {string} id The ioBroker state ID.
634
+ * @param {ioBroker.StateChangeHandler} cb The callback.
635
+ */
636
+
637
+ }, {
638
+ key: "unsubscribeState",
639
+ value: function unsubscribeState(id, cb) {
640
+ if (this.statesSubscribes[id]) {
641
+ if (cb) {
642
+ var pos = this.statesSubscribes[id].cbs.indexOf(cb);
643
+ pos !== -1 && this.statesSubscribes[id].cbs.splice(pos, 1);
644
+ } else {
645
+ this.statesSubscribes[id].cbs = [];
646
+ }
647
+
648
+ if (!this.statesSubscribes[id].cbs || !this.statesSubscribes[id].cbs.length) {
649
+ delete this.statesSubscribes[id];
650
+ this.connected && this._socket.emit('unsubscribe', id);
651
+ }
652
+ }
653
+ }
654
+ /**
655
+ * Subscribe to changes of the given object.
656
+ * @param {string} id The ioBroker object ID.
657
+ * @param {import('./types').ObjectChangeHandler} cb The callback.
658
+ * @returns {Promise<void>}
659
+ */
660
+
661
+ }, {
662
+ key: "subscribeObject",
663
+ value: function subscribeObject(id, cb) {
664
+ if (!this.objectsSubscribes[id]) {
665
+ var reg = id.replace(/\./g, '\\.').replace(/\*/g, '.*');
666
+
667
+ if (!reg.includes('*')) {
668
+ reg += '$';
669
+ }
670
+
671
+ this.objectsSubscribes[id] = {
672
+ reg: new RegExp(reg),
673
+ cbs: []
674
+ };
675
+ this.objectsSubscribes[id].cbs.push(cb);
676
+ this.connected && this._socket.emit('subscribeObjects', id);
677
+ } else {
678
+ !this.objectsSubscribes[id].cbs.includes(cb) && this.objectsSubscribes[id].cbs.push(cb);
679
+ }
680
+
681
+ return Promise.resolve();
682
+ }
683
+ /**
684
+ * Unsubscribes all callbacks from changes of the given object.
685
+ * @param {string} id The ioBroker object ID.
686
+ * @returns {Promise<void>}
687
+ */
688
+
689
+ /**
690
+ * Unsubscribes the given callback from changes of the given object.
691
+ * @param {string} id The ioBroker object ID.
692
+ * @param {import('./types').ObjectChangeHandler} cb The callback.
693
+ * @returns {Promise<void>}
694
+ */
695
+
696
+ }, {
697
+ key: "unsubscribeObject",
698
+ value: function unsubscribeObject(id, cb) {
699
+ if (this.objectsSubscribes[id]) {
700
+ if (cb) {
701
+ var pos = this.objectsSubscribes[id].cbs.indexOf(cb);
702
+ pos !== -1 && this.objectsSubscribes[id].cbs.splice(pos, 1);
703
+ } else {
704
+ this.objectsSubscribes[id].cbs = [];
705
+ }
706
+
707
+ if (this.connected && (!this.objectsSubscribes[id].cbs || !this.objectsSubscribes[id].cbs.length)) {
708
+ delete this.objectsSubscribes[id];
709
+ this.connected && this._socket.emit('unsubscribeObjects', id);
710
+ }
711
+ }
712
+
713
+ return Promise.resolve();
714
+ }
715
+ /**
716
+ * Called internally.
717
+ * @private
718
+ * @param {string} id
719
+ * @param {ioBroker.Object | null | undefined} obj
720
+ */
721
+
722
+ }, {
723
+ key: "objectChange",
724
+ value: function objectChange(id, obj) {
725
+ var _this5 = this;
726
+
727
+ // update main.objects cache
728
+ if (!this.objects) {
729
+ return;
730
+ }
731
+ /** @type {import("./types").OldObject} */
732
+
733
+
734
+ var oldObj;
735
+ var changed = false;
736
+
737
+ if (obj) {
738
+ if (obj._rev && this.objects[id]) {
739
+ this.objects[id]._rev = obj._rev;
740
+ }
741
+
742
+ if (this.objects[id]) {
743
+ oldObj = {
744
+ _id: id,
745
+ type: this.objects[id].type
746
+ };
747
+ }
748
+
749
+ if (!this.objects[id] || JSON.stringify(this.objects[id]) !== JSON.stringify(obj)) {
750
+ this.objects[id] = obj;
751
+ changed = true;
752
+ }
753
+ } else if (this.objects[id]) {
754
+ oldObj = {
755
+ _id: id,
756
+ type: this.objects[id].type
757
+ };
758
+ delete this.objects[id];
759
+ changed = true;
760
+ }
761
+
762
+ Object.keys(this.objectsSubscribes).forEach(function (_id) {
763
+ if (_id === id || _this5.objectsSubscribes[_id].reg.test(id)) {
764
+ //@ts-ignore
765
+ _this5.objectsSubscribes[_id].cbs.forEach(function (cb) {
766
+ return cb(id, obj, oldObj);
767
+ });
768
+ }
769
+ });
770
+
771
+ if (changed && this.props.onObjectChange) {
772
+ this.props.onObjectChange(id, obj);
773
+ }
774
+ }
775
+ /**
776
+ * Called internally.
777
+ * @private
778
+ * @param {string} id
779
+ * @param {ioBroker.State | null | undefined} state
780
+ */
781
+
782
+ }, {
783
+ key: "stateChange",
784
+ value: function stateChange(id, state) {
785
+ for (var task in this.statesSubscribes) {
786
+ if (this.statesSubscribes.hasOwnProperty(task) && this.statesSubscribes[task].reg.test(id)) {
787
+ this.statesSubscribes[task].cbs.forEach(function (cb) {
788
+ return cb(id, state);
789
+ });
790
+ }
791
+ }
792
+ }
793
+ /**
794
+ * Gets all states.
795
+ * @param {boolean} disableProgressUpdate don't call onProgress() when done
796
+ * @returns {Promise<Record<string, ioBroker.State>>}
797
+ */
798
+
799
+ }, {
800
+ key: "getStates",
801
+ value: function getStates(disableProgressUpdate) {
802
+ var _this6 = this;
803
+
804
+ if (!this.connected) {
805
+ return Promise.reject(NOT_CONNECTED);
806
+ }
807
+
808
+ return new Promise(function (resolve, reject) {
809
+ return _this6._socket.emit('getStates', function (err, res) {
810
+ _this6.states = res; //@ts-ignore
811
+
812
+ !disableProgressUpdate && _this6.onProgress(PROGRESS.STATES_LOADED);
813
+ return err ? reject(err) : resolve(_this6.states);
814
+ });
815
+ });
816
+ }
817
+ /**
818
+ * Gets the given state.
819
+ * @param {string} id The state ID.
820
+ * @returns {Promise<ioBroker.State | null | undefined>}
821
+ */
822
+
823
+ }, {
824
+ key: "getState",
825
+ value: function getState(id) {
826
+ var _this7 = this;
827
+
828
+ if (!this.connected) {
829
+ return Promise.reject(NOT_CONNECTED);
830
+ }
831
+
832
+ return new Promise(function (resolve, reject) {
833
+ return _this7._socket.emit('getState', id, function (err, state) {
834
+ return err ? reject(err) : resolve(state);
835
+ });
836
+ });
837
+ }
838
+ /**
839
+ * Gets the given binary state.
840
+ * @param {string} id The state ID.
841
+ * @returns {Promise<Buffer | undefined>}
842
+ */
843
+
844
+ }, {
845
+ key: "getBinaryState",
846
+ value: function getBinaryState(id) {
847
+ var _this8 = this;
848
+
849
+ if (!this.connected) {
850
+ return Promise.reject(NOT_CONNECTED);
851
+ } // the data will come in base64
852
+
853
+
854
+ return new Promise(function (resolve, reject) {
855
+ return _this8._socket.emit('getBinaryState', id, function (err, state) {
856
+ return err ? reject(err) : resolve(state);
857
+ });
858
+ });
859
+ }
860
+ /**
861
+ * Sets the given binary state.
862
+ * @param {string} id The state ID.
863
+ * @param {string} base64 The Base64 encoded binary data.
864
+ * @returns {Promise<void>}
865
+ */
866
+
867
+ }, {
868
+ key: "setBinaryState",
869
+ value: function setBinaryState(id, base64) {
870
+ var _this9 = this;
871
+
872
+ if (!this.connected) {
873
+ return Promise.reject(NOT_CONNECTED);
874
+ } // the data will come in base64
875
+
876
+
877
+ return new Promise(function (resolve, reject) {
878
+ return _this9._socket.emit('setBinaryState', id, base64, function (err) {
879
+ return err ? reject(err) : resolve();
880
+ });
881
+ });
882
+ }
883
+ /**
884
+ * Sets the given state value.
885
+ * @param {string} id The state ID.
886
+ * @param {string | number | boolean | ioBroker.State | ioBroker.SettableState | null} val The state value.
887
+ * @returns {Promise<void>}
888
+ */
889
+
890
+ }, {
891
+ key: "setState",
892
+ value: function setState(id, val) {
893
+ var _this10 = this;
894
+
895
+ if (!this.connected) {
896
+ return Promise.reject(NOT_CONNECTED);
897
+ }
898
+
899
+ return new Promise(function (resolve, reject) {
900
+ return _this10._socket.emit('setState', id, val, function (err) {
901
+ return err ? reject(err) : resolve();
902
+ });
903
+ });
904
+ }
905
+ /**
906
+ * Gets all objects.
907
+ * @param {(objects?: Record<string, ioBroker.Object>) => void} update Callback that is executed when all objects are retrieved.
908
+ * @returns {void}
909
+ */
910
+
911
+ /**
912
+ * Gets all objects.
913
+ * @param {boolean} update Set to true to retrieve all objects from the server (instead of using the local cache).
914
+ * @param {boolean} disableProgressUpdate don't call onProgress() when done
915
+ * @returns {Promise<Record<string, ioBroker.Object>> | undefined}
916
+ */
917
+
918
+ }, {
919
+ key: "getObjects",
920
+ value: function getObjects(update, disableProgressUpdate) {
921
+ var _this11 = this;
922
+
923
+ if (!this.connected) {
924
+ return Promise.reject(NOT_CONNECTED);
925
+ } else {
926
+ return new Promise(function (resolve, reject) {
927
+ if (!update && _this11.objects) {
928
+ return resolve(_this11.objects);
929
+ }
930
+
931
+ _this11._socket.emit(Connection.isWeb() ? 'getObjects' : 'getAllObjects', function (err, res) {
932
+ _this11.objects = res;
933
+ disableProgressUpdate && _this11.onProgress(PROGRESS.OBJECTS_LOADED);
934
+ err ? reject(err) : resolve(_this11.objects);
935
+ });
936
+ });
937
+ }
938
+ }
939
+ /**
940
+ * Called internally.
941
+ * @private
942
+ * @param {boolean} isEnable
943
+ */
944
+
945
+ }, {
946
+ key: "_subscribe",
947
+ value: function _subscribe(isEnable) {
948
+ var _this12 = this;
949
+
950
+ if (isEnable && !this.subscribed) {
951
+ this.subscribed = true;
952
+ this.autoSubscribes.forEach(function (id) {
953
+ return _this12._socket.emit('subscribeObjects', id);
954
+ }); // re subscribe objects
955
+
956
+ Object.keys(this.objectsSubscribes).forEach(function (id) {
957
+ return _this12._socket.emit('subscribeObjects', id);
958
+ }); // re-subscribe logs
959
+
960
+ this.autoSubscribeLog && this._socket.emit('requireLog', true); // re subscribe states
961
+
962
+ Object.keys(this.statesSubscribes).forEach(function (id) {
963
+ return _this12._socket.emit('subscribe', id);
964
+ });
965
+ } else if (!isEnable && this.subscribed) {
966
+ this.subscribed = false; // un-subscribe objects
967
+
968
+ this.autoSubscribes.forEach(function (id) {
969
+ return _this12._socket.emit('unsubscribeObjects', id);
970
+ });
971
+ Object.keys(this.objectsSubscribes).forEach(function (id) {
972
+ return _this12._socket.emit('unsubscribeObjects', id);
973
+ }); // un-subscribe logs
974
+
975
+ this.autoSubscribeLog && this._socket.emit('requireLog', false); // un-subscribe states
976
+
977
+ Object.keys(this.statesSubscribes).forEach(function (id) {
978
+ return _this12._socket.emit('unsubscribe', id);
979
+ });
980
+ }
981
+ }
982
+ /**
983
+ * Requests log updates.
984
+ * @param {boolean} isEnabled Set to true to get logs.
985
+ * @returns {Promise<void>}
986
+ */
987
+
988
+ }, {
989
+ key: "requireLog",
990
+ value: function requireLog(isEnabled) {
991
+ var _this13 = this;
992
+
993
+ if (!this.connected) {
994
+ return Promise.reject(NOT_CONNECTED);
995
+ }
996
+
997
+ return new Promise(function (resolve, reject) {
998
+ return _this13._socket.emit('requireLog', isEnabled, function (err) {
999
+ return err ? reject(err) : resolve();
1000
+ });
1001
+ });
1002
+ }
1003
+ /**
1004
+ * Deletes the given object.
1005
+ * @param {string} id The object ID.
1006
+ * @param {boolean} maintenance Force deletion of non conform IDs.
1007
+ * @returns {Promise<void>}
1008
+ */
1009
+
1010
+ }, {
1011
+ key: "delObject",
1012
+ value: function delObject(id, maintenance) {
1013
+ var _this14 = this;
1014
+
1015
+ if (!this.connected) {
1016
+ return Promise.reject(NOT_CONNECTED);
1017
+ }
1018
+
1019
+ return new Promise(function (resolve, reject) {
1020
+ return _this14._socket.emit('delObject', id, {
1021
+ maintenance: !!maintenance
1022
+ }, function (err) {
1023
+ return err ? reject(err) : resolve();
1024
+ });
1025
+ });
1026
+ }
1027
+ /**
1028
+ * Deletes the given object and all its children.
1029
+ * @param {string} id The object ID.
1030
+ * @param {boolean} maintenance Force deletion of non conform IDs.
1031
+ * @returns {Promise<void>}
1032
+ */
1033
+
1034
+ }, {
1035
+ key: "delObjects",
1036
+ value: function delObjects(id, maintenance) {
1037
+ var _this15 = this;
1038
+
1039
+ if (!this.connected) {
1040
+ return Promise.reject(NOT_CONNECTED);
1041
+ }
1042
+
1043
+ return new Promise(function (resolve, reject) {
1044
+ return _this15._socket.emit('delObjects', id, {
1045
+ maintenance: !!maintenance
1046
+ }, function (err) {
1047
+ return err ? reject(err) : resolve();
1048
+ });
1049
+ });
1050
+ }
1051
+ /**
1052
+ * Sets the object.
1053
+ * @param {string} id The object ID.
1054
+ * @param {ioBroker.SettableObject} obj The object.
1055
+ * @returns {Promise<void>}
1056
+ */
1057
+
1058
+ }, {
1059
+ key: "setObject",
1060
+ value: function setObject(id, obj) {
1061
+ var _this16 = this;
1062
+
1063
+ if (!this.connected) {
1064
+ return Promise.reject(NOT_CONNECTED);
1065
+ }
1066
+
1067
+ if (!obj) {
1068
+ return Promise.reject('Null object is not allowed');
1069
+ }
1070
+
1071
+ obj = JSON.parse(JSON.stringify(obj));
1072
+
1073
+ if (obj.hasOwnProperty('from')) {
1074
+ delete obj.from;
1075
+ }
1076
+
1077
+ if (obj.hasOwnProperty('user')) {
1078
+ delete obj.user;
1079
+ }
1080
+
1081
+ if (obj.hasOwnProperty('ts')) {
1082
+ delete obj.ts;
1083
+ }
1084
+
1085
+ return new Promise(function (resolve, reject) {
1086
+ return _this16._socket.emit('setObject', id, obj, function (err) {
1087
+ return err ? reject(err) : resolve();
1088
+ });
1089
+ });
1090
+ }
1091
+ /**
1092
+ * Gets the object with the given id from the server.
1093
+ * @param {string} id The object ID.
1094
+ * @returns {ioBroker.GetObjectPromise} The object.
1095
+ */
1096
+
1097
+ }, {
1098
+ key: "getObject",
1099
+ value: function getObject(id) {
1100
+ var _this17 = this;
1101
+
1102
+ if (!this.connected) {
1103
+ return Promise.reject(NOT_CONNECTED);
1104
+ }
1105
+
1106
+ return new Promise(function (resolve, reject) {
1107
+ return _this17._socket.emit('getObject', id, function (err, obj) {
1108
+ return err ? reject(err) : resolve(obj);
1109
+ });
1110
+ });
1111
+ }
1112
+ /**
1113
+ * Get all adapter instances.
1114
+ * @param {boolean} [update] Force update.
1115
+ * @returns {Promise<ioBroker.Object[]>}
1116
+ */
1117
+
1118
+ /**
1119
+ * Get all instances of the given adapter.
1120
+ * @param {string} adapter The name of the adapter.
1121
+ * @param {boolean} [update] Force update.
1122
+ * @returns {Promise<ioBroker.Object[]>}
1123
+ */
1124
+
1125
+ }, {
1126
+ key: "getAdapterInstances",
1127
+ value: function getAdapterInstances(adapter, update) {
1128
+ var _this18 = this;
1129
+
1130
+ if (Connection.isWeb()) {
1131
+ return Promise.reject('Allowed only in admin');
1132
+ }
1133
+
1134
+ if (typeof adapter === 'boolean') {
1135
+ update = adapter;
1136
+ adapter = '';
1137
+ }
1138
+
1139
+ adapter = adapter || '';
1140
+
1141
+ if (!update && this._promises['instances_' + adapter]) {
1142
+ return this._promises['instances_' + adapter];
1143
+ }
1144
+
1145
+ if (!this.connected) {
1146
+ return Promise.reject(NOT_CONNECTED);
1147
+ }
1148
+
1149
+ this._promises['instances_' + adapter] = new Promise(function (resolve, reject) {
1150
+ var timeout = setTimeout(function () {
1151
+ timeout = null;
1152
+
1153
+ _this18.getObjectView("system.adapter.".concat(adapter, "."), "system.adapter.".concat(adapter, ".\u9999"), 'instance').then(function (items) {
1154
+ return resolve(Object.keys(items).map(function (id) {
1155
+ return fixAdminUI(items[id]);
1156
+ }));
1157
+ })["catch"](function (e) {
1158
+ return reject(e);
1159
+ });
1160
+ }, TIMEOUT_FOR_ADMIN4);
1161
+
1162
+ _this18._socket.emit('getAdapterInstances', adapter, function (err, instances) {
1163
+ if (timeout) {
1164
+ clearTimeout(timeout);
1165
+ timeout = null;
1166
+ return err ? reject(err) : resolve(instances);
1167
+ }
1168
+ });
1169
+ });
1170
+ return this._promises['instances_' + adapter];
1171
+ }
1172
+ /**
1173
+ * Get all adapters.
1174
+ * @param {boolean} [update] Force update.
1175
+ * @returns {Promise<ioBroker.Object[]>}
1176
+ */
1177
+
1178
+ /**
1179
+ * Get adapters with the given name.
1180
+ * @param {string} adapter The name of the adapter.
1181
+ * @param {boolean} [update] Force update.
1182
+ * @returns {Promise<ioBroker.Object[]>}
1183
+ */
1184
+
1185
+ }, {
1186
+ key: "getAdapters",
1187
+ value: function getAdapters(adapter, update) {
1188
+ var _this19 = this;
1189
+
1190
+ if (Connection.isWeb()) {
1191
+ return Promise.reject('Allowed only in admin');
1192
+ }
1193
+
1194
+ if (typeof adapter === 'boolean') {
1195
+ update = adapter;
1196
+ adapter = '';
1197
+ }
1198
+
1199
+ adapter = adapter || '';
1200
+
1201
+ if (!update && this._promises['adapter_' + adapter]) {
1202
+ return this._promises['adapter_' + adapter];
1203
+ }
1204
+
1205
+ if (!this.connected) {
1206
+ return Promise.reject(NOT_CONNECTED);
1207
+ }
1208
+
1209
+ this._promises['adapter_' + adapter] = new Promise(function (resolve, reject) {
1210
+ var timeout = setTimeout(function () {
1211
+ timeout = null;
1212
+
1213
+ _this19.getObjectView("system.adapter.".concat(adapter, "."), "system.adapter.".concat(adapter, ".\u9999"), 'adapter').then(function (items) {
1214
+ return resolve(Object.keys(items).map(function (id) {
1215
+ return fixAdminUI(items[id]);
1216
+ }));
1217
+ })["catch"](function (e) {
1218
+ return reject(e);
1219
+ });
1220
+ }, TIMEOUT_FOR_ADMIN4);
1221
+
1222
+ _this19._socket.emit('getAdapters', adapter, function (err, adapters) {
1223
+ if (timeout) {
1224
+ clearTimeout(timeout);
1225
+ timeout = null;
1226
+ return err ? reject(err) : resolve(adapters);
1227
+ }
1228
+ });
1229
+ });
1230
+ return this._promises['adapter_' + adapter];
1231
+ }
1232
+ /**
1233
+ * Called internally.
1234
+ * @private
1235
+ * @param {any[]} objs
1236
+ * @param {(err?: any) => void} cb
1237
+ */
1238
+
1239
+ }, {
1240
+ key: "_renameGroups",
1241
+ value: function _renameGroups(objs, cb) {
1242
+ var _this20 = this;
1243
+
1244
+ if (!objs || !objs.length) {
1245
+ cb && cb();
1246
+ } else {
1247
+ var obj = objs.pop();
1248
+ var oldId = obj._id;
1249
+ obj._id = obj.newId;
1250
+ delete obj.newId;
1251
+ this.setObject(obj._id, obj).then(function () {
1252
+ return _this20.delObject(oldId);
1253
+ }).then(function () {
1254
+ return setTimeout(function () {
1255
+ return _this20._renameGroups(objs, cb);
1256
+ }, 0);
1257
+ })["catch"](function (err) {
1258
+ return cb && cb(err);
1259
+ });
1260
+ }
1261
+ }
1262
+ /**
1263
+ * Rename a group.
1264
+ * @param {string} id The id.
1265
+ * @param {string} newId The new id.
1266
+ * @param {string | { [lang in ioBroker.Languages]?: string; }} newName The new name.
1267
+ */
1268
+
1269
+ }, {
1270
+ key: "renameGroup",
1271
+ value: function renameGroup(id, newId, newName) {
1272
+ var _this21 = this;
1273
+
1274
+ if (Connection.isWeb()) {
1275
+ return Promise.reject('Allowed only in admin');
1276
+ }
1277
+
1278
+ return this.getGroups(true).then(function (groups) {
1279
+ if (groups.length) {
1280
+ // find all elements
1281
+ var groupsToRename = groups.filter(function (group) {
1282
+ return group._id.startsWith(id + '.');
1283
+ });
1284
+ groupsToRename.forEach(function (group) {
1285
+ return group.newId = newId + group._id.substring(id.length);
1286
+ });
1287
+ return new Promise(function (resolve, reject) {
1288
+ return _this21._renameGroups(groupsToRename, function (err) {
1289
+ return err ? reject(err) : resolve();
1290
+ });
1291
+ }).then(function () {
1292
+ var obj = groups.find(function (group) {
1293
+ return group._id === id;
1294
+ });
1295
+
1296
+ if (obj) {
1297
+ obj._id = newId;
1298
+
1299
+ if (newName !== undefined) {
1300
+ obj.common = obj.common || {};
1301
+ obj.common.name = newName;
1302
+ }
1303
+
1304
+ return _this21.setObject(obj._id, obj).then(function () {
1305
+ return _this21.delObject(id);
1306
+ });
1307
+ }
1308
+ });
1309
+ }
1310
+ });
1311
+ }
1312
+ /**
1313
+ * Sends a message to a specific instance or all instances of some specific adapter.
1314
+ * @param {string} instance The instance to send this message to.
1315
+ * @param {string} [command] Command name of the target instance.
1316
+ * @param {ioBroker.MessagePayload} [data] The message data to send.
1317
+ * @returns {Promise<ioBroker.Message | undefined>}
1318
+ */
1319
+
1320
+ }, {
1321
+ key: "sendTo",
1322
+ value: function sendTo(instance, command, data) {
1323
+ var _this22 = this;
1324
+
1325
+ if (!this.connected) {
1326
+ return Promise.reject(NOT_CONNECTED);
1327
+ }
1328
+
1329
+ return new Promise(function (resolve) {
1330
+ return _this22._socket.emit('sendTo', instance, command, data, function (result) {
1331
+ return resolve(result);
1332
+ });
1333
+ });
1334
+ }
1335
+ /**
1336
+ * Extend an object and create it if it might not exist.
1337
+ * @param {string} id The id.
1338
+ * @param {ioBroker.PartialObject} obj The object.
1339
+ */
1340
+
1341
+ }, {
1342
+ key: "extendObject",
1343
+ value: function extendObject(id, obj) {
1344
+ var _this23 = this;
1345
+
1346
+ if (!this.connected) {
1347
+ return Promise.reject(NOT_CONNECTED);
1348
+ }
1349
+
1350
+ obj = JSON.parse(JSON.stringify(obj));
1351
+
1352
+ if (obj.hasOwnProperty('from')) {
1353
+ delete obj.from;
1354
+ }
1355
+
1356
+ if (obj.hasOwnProperty('user')) {
1357
+ delete obj.user;
1358
+ }
1359
+
1360
+ if (obj.hasOwnProperty('ts')) {
1361
+ delete obj.ts;
1362
+ }
1363
+
1364
+ return new Promise(function (resolve, reject) {
1365
+ return _this23._socket.emit('extendObject', id, obj, function (err) {
1366
+ return err ? reject(err) : resolve();
1367
+ });
1368
+ });
1369
+ }
1370
+ /**
1371
+ * Register a handler for log messages.
1372
+ * @param {(message: string) => void} handler The handler.
1373
+ */
1374
+
1375
+ }, {
1376
+ key: "registerLogHandler",
1377
+ value: function registerLogHandler(handler) {
1378
+ !this.onLogHandlers.includes(handler) && this.onLogHandlers.push(handler);
1379
+ }
1380
+ /**
1381
+ * Unregister a handler for log messages.
1382
+ * @param {(message: string) => void} handler The handler.
1383
+ */
1384
+
1385
+ }, {
1386
+ key: "unregisterLogHandler",
1387
+ value: function unregisterLogHandler(handler) {
1388
+ var pos = this.onLogHandlers.indexOf(handler);
1389
+ pos !== -1 && this.onLogHandlers.splice(pos, 1);
1390
+ }
1391
+ /**
1392
+ * Register a handler for the connection state.
1393
+ * @param {(connected: boolean) => void} handler The handler.
1394
+ */
1395
+
1396
+ }, {
1397
+ key: "registerConnectionHandler",
1398
+ value: function registerConnectionHandler(handler) {
1399
+ !this.onConnectionHandlers.includes(handler) && this.onConnectionHandlers.push(handler);
1400
+ }
1401
+ /**
1402
+ * Unregister a handler for the connection state.
1403
+ * @param {(connected: boolean) => void} handler The handler.
1404
+ */
1405
+
1406
+ }, {
1407
+ key: "unregisterConnectionHandler",
1408
+ value: function unregisterConnectionHandler(handler) {
1409
+ var pos = this.onConnectionHandlers.indexOf(handler);
1410
+ pos !== -1 && this.onConnectionHandlers.splice(pos, 1);
1411
+ }
1412
+ /**
1413
+ * Set the handler for standard output of a command.
1414
+ * @param {(id: string, text: string) => void} handler The handler.
1415
+ */
1416
+
1417
+ }, {
1418
+ key: "registerCmdStdoutHandler",
1419
+ value: function registerCmdStdoutHandler(handler) {
1420
+ this.onCmdStdoutHandler = handler;
1421
+ }
1422
+ /**
1423
+ * Unset the handler for standard output of a command.
1424
+ * @param {(id: string, text: string) => void} handler The handler.
1425
+ */
1426
+
1427
+ }, {
1428
+ key: "unregisterCmdStdoutHandler",
1429
+ value: function unregisterCmdStdoutHandler(handler) {
1430
+ this.onCmdStdoutHandler = null;
1431
+ }
1432
+ /**
1433
+ * Set the handler for standard error of a command.
1434
+ * @param {(id: string, text: string) => void} handler The handler.
1435
+ */
1436
+
1437
+ }, {
1438
+ key: "registerCmdStderrHandler",
1439
+ value: function registerCmdStderrHandler(handler) {
1440
+ this.onCmdStderrHandler = handler;
1441
+ }
1442
+ /**
1443
+ * Unset the handler for standard error of a command.
1444
+ * @param {(id: string, text: string) => void} handler The handler.
1445
+ */
1446
+
1447
+ }, {
1448
+ key: "unregisterCmdStderrHandler",
1449
+ value: function unregisterCmdStderrHandler(handler) {
1450
+ this.onCmdStderrHandler = null;
1451
+ }
1452
+ /**
1453
+ * Set the handler for exit of a command.
1454
+ * @param {(id: string, exitCode: number) => void} handler The handler.
1455
+ */
1456
+
1457
+ }, {
1458
+ key: "registerCmdExitHandler",
1459
+ value: function registerCmdExitHandler(handler) {
1460
+ this.onCmdExitHandler = handler;
1461
+ }
1462
+ /**
1463
+ * Unset the handler for exit of a command.
1464
+ * @param {(id: string, exitCode: number) => void} handler The handler.
1465
+ */
1466
+
1467
+ }, {
1468
+ key: "unregisterCmdExitHandler",
1469
+ value: function unregisterCmdExitHandler(handler) {
1470
+ this.onCmdExitHandler = null;
1471
+ }
1472
+ /**
1473
+ * Get all enums with the given name.
1474
+ * @param {string} [_enum] The name of the enum
1475
+ * @param {boolean} [update] Force update.
1476
+ * @returns {Promise<Record<string, ioBroker.Object>>}
1477
+ */
1478
+
1479
+ }, {
1480
+ key: "getEnums",
1481
+ value: function getEnums(_enum, update) {
1482
+ var _this24 = this;
1483
+
1484
+ if (!update && this._promises['enums_' + (_enum || 'all')]) {
1485
+ return this._promises['enums_' + (_enum || 'all')];
1486
+ }
1487
+
1488
+ if (!this.connected) {
1489
+ return Promise.reject(NOT_CONNECTED);
1490
+ }
1491
+
1492
+ this._promises['enums_' + (_enum || 'all')] = new Promise(function (resolve, reject) {
1493
+ _this24._socket.emit('getObjectView', 'system', 'enum', {
1494
+ startkey: 'enum.' + (_enum || ''),
1495
+ endkey: 'enum.' + (_enum ? _enum + '.' : '') + "\u9999"
1496
+ }, function (err, res) {
1497
+ if (!err && res) {
1498
+ var _res = {};
1499
+
1500
+ for (var i = 0; i < res.rows.length; i++) {
1501
+ if (_enum && res.rows[i].id === 'enum.' + _enum) {
1502
+ continue;
1503
+ }
1504
+
1505
+ _res[res.rows[i].id] = res.rows[i].value;
1506
+ }
1507
+
1508
+ resolve(_res);
1509
+ } else {
1510
+ reject(err);
1511
+ }
1512
+ });
1513
+ });
1514
+ return this._promises['enums_' + (_enum || 'all')];
1515
+ }
1516
+ /**
1517
+ * Query a predefined object view.
1518
+ * @param {string} start The start ID.
1519
+ * @param {string} end The end ID.
1520
+ * @param {string} type The type of object.
1521
+ * @returns {Promise<Record<string, ioBroker.Object>>}
1522
+ */
1523
+
1524
+ }, {
1525
+ key: "getObjectView",
1526
+ value: function getObjectView(start, end, type) {
1527
+ var _this25 = this;
1528
+
1529
+ if (!this.connected) {
1530
+ return Promise.reject(NOT_CONNECTED);
1531
+ }
1532
+
1533
+ start = start || '';
1534
+ end = end || "\u9999";
1535
+ return new Promise(function (resolve, reject) {
1536
+ _this25._socket.emit('getObjectView', 'system', type, {
1537
+ startkey: start,
1538
+ endkey: end
1539
+ }, function (err, res) {
1540
+ if (!err) {
1541
+ var _res = {};
1542
+
1543
+ if (res && res.rows) {
1544
+ for (var i = 0; i < res.rows.length; i++) {
1545
+ _res[res.rows[i].id] = res.rows[i].value;
1546
+ }
1547
+ }
1548
+
1549
+ resolve(_res);
1550
+ } else {
1551
+ reject(err);
1552
+ }
1553
+ });
1554
+ });
1555
+ }
1556
+ /**
1557
+ * Get the stored certificates.
1558
+ * @param {boolean} [update] Force update.
1559
+ * @returns {Promise<{name: string; type: 'public' | 'private' | 'chained'}[]>}
1560
+ */
1561
+
1562
+ }, {
1563
+ key: "getCertificates",
1564
+ value: function getCertificates(update) {
1565
+ if (Connection.isWeb()) {
1566
+ return Promise.reject('Allowed only in admin');
1567
+ }
1568
+
1569
+ if (this._promises.cert && !update) {
1570
+ return this._promises.cert;
1571
+ }
1572
+
1573
+ if (!this.connected) {
1574
+ return Promise.reject(NOT_CONNECTED);
1575
+ }
1576
+
1577
+ this._promises.cert = this.getObject('system.certificates').then(function (res) {
1578
+ var certs = [];
1579
+
1580
+ if (res && res["native"] && res["native"].certificates) {
1581
+ Object.keys(res["native"].certificates).forEach(function (c) {
1582
+ var cert = res["native"].certificates[c];
1583
+
1584
+ if (!cert) {
1585
+ return;
1586
+ }
1587
+
1588
+ var _cert = {
1589
+ name: c,
1590
+ type: ''
1591
+ }; // If it is filename, it could be everything
1592
+
1593
+ if (cert.length < 700 && (cert.indexOf('/') !== -1 || cert.indexOf('\\') !== -1)) {
1594
+ if (c.toLowerCase().includes('private')) {
1595
+ _cert.type = 'private';
1596
+ } else if (cert.toLowerCase().includes('private')) {
1597
+ _cert.type = 'private';
1598
+ } else if (c.toLowerCase().includes('public')) {
1599
+ _cert.type = 'public';
1600
+ } else if (cert.toLowerCase().includes('public')) {
1601
+ _cert.type = 'public';
1602
+ }
1603
+
1604
+ certs.push(_cert);
1605
+ } else {
1606
+ _cert.type = cert.substring(0, '-----BEGIN RSA PRIVATE KEY'.length) === '-----BEGIN RSA PRIVATE KEY' || cert.substring(0, '-----BEGIN PRIVATE KEY'.length) === '-----BEGIN PRIVATE KEY' ? 'private' : 'public';
1607
+
1608
+ if (_cert.type === 'public') {
1609
+ var m = cert.split('-----END CERTIFICATE-----');
1610
+
1611
+ if (m.filter(function (t) {
1612
+ return t.replace(/\r\n|\r|\n/, '').trim();
1613
+ }).length > 1) {
1614
+ _cert.type = 'chained';
1615
+ }
1616
+ }
1617
+
1618
+ certs.push(_cert);
1619
+ }
1620
+ });
1621
+ }
1622
+
1623
+ return certs;
1624
+ });
1625
+ return this._promises.cert;
1626
+ }
1627
+ /**
1628
+ * Get the logs from a host (only for admin connection).
1629
+ * @param {string} host
1630
+ * @param {number} [linesNumber]
1631
+ * @returns {Promise<string[]>}
1632
+ */
1633
+
1634
+ }, {
1635
+ key: "getLogs",
1636
+ value: function getLogs(host, linesNumber) {
1637
+ var _this26 = this;
1638
+
1639
+ if (Connection.isWeb()) {
1640
+ return Promise.reject('Allowed only in admin');
1641
+ }
1642
+
1643
+ if (!this.connected) {
1644
+ return Promise.reject(NOT_CONNECTED);
1645
+ }
1646
+
1647
+ return new Promise(function (resolve) {
1648
+ return _this26._socket.emit('sendToHost', host, 'getLogs', linesNumber || 200, function (lines) {
1649
+ return resolve(lines);
1650
+ });
1651
+ });
1652
+ }
1653
+ /**
1654
+ * Get the log files (only for admin connection).
1655
+ * @returns {Promise<string[]>}
1656
+ */
1657
+
1658
+ }, {
1659
+ key: "getLogsFiles",
1660
+ value: function getLogsFiles(host) {
1661
+ var _this27 = this;
1662
+
1663
+ if (Connection.isWeb()) {
1664
+ return Promise.reject('Allowed only in admin');
1665
+ }
1666
+
1667
+ if (!this.connected) {
1668
+ return Promise.reject(NOT_CONNECTED);
1669
+ }
1670
+
1671
+ return new Promise(function (resolve, reject) {
1672
+ return _this27._socket.emit('readLogs', host, function (err, files) {
1673
+ return err ? reject(err) : resolve(files);
1674
+ });
1675
+ });
1676
+ }
1677
+ /**
1678
+ * Delete the logs from a host (only for admin connection).
1679
+ * @param {string} host
1680
+ * @returns {Promise<void>}
1681
+ */
1682
+
1683
+ }, {
1684
+ key: "delLogs",
1685
+ value: function delLogs(host) {
1686
+ var _this28 = this;
1687
+
1688
+ if (Connection.isWeb()) {
1689
+ return Promise.reject('Allowed only in admin');
1690
+ }
1691
+
1692
+ if (!this.connected) {
1693
+ return Promise.reject(NOT_CONNECTED);
1694
+ }
1695
+
1696
+ return new Promise(function (resolve, reject) {
1697
+ return _this28._socket.emit('sendToHost', host, 'delLogs', null, function (error) {
1698
+ return error ? reject(error) : resolve();
1699
+ });
1700
+ });
1701
+ }
1702
+ /**
1703
+ * Read the meta items.
1704
+ * @returns {Promise<ioBroker.Object[]>}
1705
+ */
1706
+
1707
+ }, {
1708
+ key: "readMetaItems",
1709
+ value: function readMetaItems() {
1710
+ var _this29 = this;
1711
+
1712
+ if (!this.connected) {
1713
+ return Promise.reject(NOT_CONNECTED);
1714
+ }
1715
+
1716
+ return new Promise(function (resolve, reject) {
1717
+ return _this29._socket.emit('getObjectView', 'system', 'meta', {
1718
+ startkey: '',
1719
+ endkey: "\u9999"
1720
+ }, function (err, objs) {
1721
+ return err ? reject(err) : resolve(objs.rows && objs.rows.map(function (obj) {
1722
+ return obj.value;
1723
+ }));
1724
+ });
1725
+ });
1726
+ }
1727
+ /**
1728
+ * Read the directory of an adapter.
1729
+ * @param {string} adapter The adapter name.
1730
+ * @param {string} fileName The directory name.
1731
+ * @returns {Promise<ioBroker.ReadDirResult[]>}
1732
+ */
1733
+
1734
+ }, {
1735
+ key: "readDir",
1736
+ value: function readDir(adapter, fileName) {
1737
+ var _this30 = this;
1738
+
1739
+ if (!this.connected) {
1740
+ return Promise.reject(NOT_CONNECTED);
1741
+ }
1742
+
1743
+ return new Promise(function (resolve, reject) {
1744
+ return _this30._socket.emit('readDir', adapter, fileName, function (err, files) {
1745
+ return err ? reject(err) : resolve(files);
1746
+ });
1747
+ });
1748
+ }
1749
+ /**
1750
+ * Read a file of an adapter.
1751
+ * @param {string} adapter The adapter name.
1752
+ * @param {string} fileName The file name.
1753
+ * @param {boolean} base64 If it must be a base64 format
1754
+ * @returns {Promise<string>}
1755
+ */
1756
+
1757
+ }, {
1758
+ key: "readFile",
1759
+ value: function readFile(adapter, fileName, base64) {
1760
+ var _this31 = this;
1761
+
1762
+ if (!this.connected) {
1763
+ return Promise.reject(NOT_CONNECTED);
1764
+ }
1765
+
1766
+ return new Promise(function (resolve, reject) {
1767
+ if (!base64) {
1768
+ _this31._socket.emit('readFile', adapter, fileName, function (err, data, type) {
1769
+ //@ts-ignore
1770
+ err ? reject(err) : resolve({
1771
+ data: data,
1772
+ type: type
1773
+ });
1774
+ });
1775
+ } else {
1776
+ _this31._socket.emit('readFile64', adapter, fileName, base64, function (err, data) {
1777
+ return err ? reject(err) : resolve(data);
1778
+ });
1779
+ }
1780
+ });
1781
+ }
1782
+ /**
1783
+ * Write a file of an adapter.
1784
+ * @param {string} adapter The adapter name.
1785
+ * @param {string} fileName The file name.
1786
+ * @param {Buffer | string} data The data (if it's a Buffer, it will be converted to Base64).
1787
+ * @returns {Promise<void>}
1788
+ */
1789
+
1790
+ }, {
1791
+ key: "writeFile64",
1792
+ value: function writeFile64(adapter, fileName, data) {
1793
+ var _this32 = this;
1794
+
1795
+ if (!this.connected) {
1796
+ return Promise.reject(NOT_CONNECTED);
1797
+ }
1798
+
1799
+ return new Promise(function (resolve, reject) {
1800
+ if (typeof data === 'string') {
1801
+ _this32._socket.emit('writeFile', adapter, fileName, data, function (err) {
1802
+ return err ? reject(err) : resolve();
1803
+ });
1804
+ } else {
1805
+ var base64 = btoa(new Uint8Array(data).reduce(function (data, _byte) {
1806
+ return data + String.fromCharCode(_byte);
1807
+ }, ''));
1808
+
1809
+ _this32._socket.emit('writeFile64', adapter, fileName, base64, function (err) {
1810
+ return err ? reject(err) : resolve();
1811
+ });
1812
+ }
1813
+ });
1814
+ }
1815
+ /**
1816
+ * Rename a file or folder of an adapter.
1817
+ *
1818
+ * All files in folder will be renamed too.
1819
+ * @param {string} adapter The adapter name.
1820
+ * @param {string} oldName The file name of the file to be renamed.
1821
+ * @param {string} newName The new file name.
1822
+ * @returns {Promise<void>}
1823
+ */
1824
+
1825
+ }, {
1826
+ key: "rename",
1827
+ value: function rename(adapter, oldName, newName) {
1828
+ var _this33 = this;
1829
+
1830
+ if (!this.connected) {
1831
+ return Promise.reject(NOT_CONNECTED);
1832
+ }
1833
+
1834
+ return new Promise(function (resolve, reject) {
1835
+ return _this33._socket.emit('rename', adapter, oldName, newName, function (err) {
1836
+ return err ? reject(err) : resolve();
1837
+ });
1838
+ });
1839
+ }
1840
+ /**
1841
+ * Delete a file of an adapter.
1842
+ * @param {string} adapter The adapter name.
1843
+ * @param {string} fileName The file name.
1844
+ * @returns {Promise<void>}
1845
+ */
1846
+
1847
+ }, {
1848
+ key: "deleteFile",
1849
+ value: function deleteFile(adapter, fileName) {
1850
+ var _this34 = this;
1851
+
1852
+ if (!this.connected) {
1853
+ return Promise.reject(NOT_CONNECTED);
1854
+ }
1855
+
1856
+ return new Promise(function (resolve, reject) {
1857
+ return _this34._socket.emit('unlink', adapter, fileName, function (err) {
1858
+ return err ? reject(err) : resolve();
1859
+ });
1860
+ });
1861
+ }
1862
+ /**
1863
+ * Delete a folder of an adapter.
1864
+ * All files in folder will be deleted.
1865
+ * @param {string} adapter The adapter name.
1866
+ * @param {string} folderName The folder name.
1867
+ * @returns {Promise<void>}
1868
+ */
1869
+
1870
+ }, {
1871
+ key: "deleteFolder",
1872
+ value: function deleteFolder(adapter, folderName) {
1873
+ var _this35 = this;
1874
+
1875
+ if (!this.connected) {
1876
+ return Promise.reject(NOT_CONNECTED);
1877
+ }
1878
+
1879
+ return new Promise(function (resolve, reject) {
1880
+ return _this35._socket.emit('deleteFolder', adapter, folderName, function (err) {
1881
+ return err ? reject(err) : resolve();
1882
+ });
1883
+ });
1884
+ }
1885
+ /**
1886
+ * Get the list of all hosts.
1887
+ * @param {boolean} [update] Force update.
1888
+ * @returns {Promise<ioBroker.Object[]>}
1889
+ */
1890
+
1891
+ }, {
1892
+ key: "getHosts",
1893
+ value: function getHosts(update) {
1894
+ var _this36 = this;
1895
+
1896
+ if (Connection.isWeb()) {
1897
+ return Promise.reject('Allowed only in admin');
1898
+ }
1899
+
1900
+ if (!update && this._promises.hosts) {
1901
+ return this._promises.hosts;
1902
+ }
1903
+
1904
+ if (!this.connected) {
1905
+ return Promise.reject(NOT_CONNECTED);
1906
+ }
1907
+
1908
+ this._promises.hosts = new Promise(function (resolve, reject) {
1909
+ return _this36._socket.emit('getObjectView', 'system', 'host', {
1910
+ startkey: 'system.host.',
1911
+ endkey: "system.host.\u9999"
1912
+ }, function (err, doc) {
1913
+ if (err) {
1914
+ reject(err);
1915
+ } else {
1916
+ resolve(doc.rows.map(function (item) {
1917
+ return item.value;
1918
+ }));
1919
+ }
1920
+ });
1921
+ });
1922
+ return this._promises.hosts;
1923
+ }
1924
+ /**
1925
+ * Get the list of all users.
1926
+ * @param {boolean} [update] Force update.
1927
+ * @returns {Promise<ioBroker.Object[]>}
1928
+ */
1929
+
1930
+ }, {
1931
+ key: "getUsers",
1932
+ value: function getUsers(update) {
1933
+ var _this37 = this;
1934
+
1935
+ if (Connection.isWeb()) {
1936
+ return Promise.reject('Allowed only in admin');
1937
+ }
1938
+
1939
+ if (!update && this._promises.users) {
1940
+ return this._promises.users;
1941
+ }
1942
+
1943
+ if (!this.connected) {
1944
+ return Promise.reject(NOT_CONNECTED);
1945
+ }
1946
+
1947
+ this._promises.users = new Promise(function (resolve, reject) {
1948
+ return _this37._socket.emit('getObjectView', 'system', 'user', {
1949
+ startkey: 'system.user.',
1950
+ endkey: "system.user.\u9999"
1951
+ }, function (err, doc) {
1952
+ if (err) {
1953
+ reject(err);
1954
+ } else {
1955
+ resolve(doc.rows.map(function (item) {
1956
+ return item.value;
1957
+ }));
1958
+ }
1959
+ });
1960
+ });
1961
+ return this._promises.users;
1962
+ }
1963
+ /**
1964
+ * Get the list of all groups.
1965
+ * @param {boolean} [update] Force update.
1966
+ * @returns {Promise<ioBroker.Object[]>}
1967
+ */
1968
+
1969
+ }, {
1970
+ key: "getGroups",
1971
+ value: function getGroups(update) {
1972
+ var _this38 = this;
1973
+
1974
+ if (!update && this._promises.groups) {
1975
+ return this._promises.groups;
1976
+ }
1977
+
1978
+ if (!this.connected) {
1979
+ return Promise.reject(NOT_CONNECTED);
1980
+ }
1981
+
1982
+ this._promises.groups = new Promise(function (resolve, reject) {
1983
+ return _this38._socket.emit('getObjectView', 'system', 'group', {
1984
+ startkey: 'system.group.',
1985
+ endkey: "system.group.\u9999"
1986
+ }, function (err, doc) {
1987
+ if (err) {
1988
+ reject(err);
1989
+ } else {
1990
+ resolve(doc.rows.map(function (item) {
1991
+ return item.value;
1992
+ }));
1993
+ }
1994
+ });
1995
+ });
1996
+ return this._promises.groups;
1997
+ }
1998
+ /**
1999
+ * Get the host information.
2000
+ * @param {string} host
2001
+ * @param {boolean} [update] Force update.
2002
+ * @param {number} [timeoutMs] optional read timeout.
2003
+ * @returns {Promise<any>}
2004
+ */
2005
+
2006
+ }, {
2007
+ key: "getHostInfo",
2008
+ value: function getHostInfo(host, update, timeoutMs) {
2009
+ var _this39 = this;
2010
+
2011
+ if (Connection.isWeb()) {
2012
+ return Promise.reject('Allowed only in admin');
2013
+ }
2014
+
2015
+ if (!host.startsWith('system.host.')) {
2016
+ host += 'system.host.' + host;
2017
+ }
2018
+
2019
+ if (!update && this._promises['hostInfo' + host]) {
2020
+ return this._promises['hostInfo' + host];
2021
+ }
2022
+
2023
+ if (!this.connected) {
2024
+ return Promise.reject(NOT_CONNECTED);
2025
+ }
2026
+
2027
+ this._promises['hostInfo' + host] = new Promise(function (resolve, reject) {
2028
+ var timeout = setTimeout(function () {
2029
+ if (timeout) {
2030
+ timeout = null;
2031
+ reject('getHostInfo timeout');
2032
+ }
2033
+ }, timeoutMs || _this39.props.cmdTimeout);
2034
+
2035
+ _this39._socket.emit('sendToHost', host, 'getHostInfo', null, function (data) {
2036
+ if (timeout) {
2037
+ clearTimeout(timeout);
2038
+ timeout = null;
2039
+
2040
+ if (data === PERMISSION_ERROR) {
2041
+ reject('May not read "getHostInfo"');
2042
+ } else if (!data) {
2043
+ reject('Cannot read "getHostInfo"');
2044
+ } else {
2045
+ resolve(data);
2046
+ }
2047
+ }
2048
+ });
2049
+ });
2050
+ return this._promises['hostInfo' + host];
2051
+ }
2052
+ /**
2053
+ * Get the host information (short version).
2054
+ * @param {string} host
2055
+ * @param {boolean} [update] Force update.
2056
+ * @param {number} [timeoutMs] optional read timeout.
2057
+ * @returns {Promise<any>}
2058
+ */
2059
+
2060
+ }, {
2061
+ key: "getHostInfoShort",
2062
+ value: function getHostInfoShort(host, update, timeoutMs) {
2063
+ var _this40 = this;
2064
+
2065
+ if (Connection.isWeb()) {
2066
+ return Promise.reject('Allowed only in admin');
2067
+ }
2068
+
2069
+ if (!host.startsWith('system.host.')) {
2070
+ host += 'system.host.' + host;
2071
+ }
2072
+
2073
+ if (!update && this._promises['hostInfoShort' + host]) {
2074
+ return this._promises['hostInfoShort' + host];
2075
+ }
2076
+
2077
+ if (!this.connected) {
2078
+ return Promise.reject(NOT_CONNECTED);
2079
+ }
2080
+
2081
+ this._promises['hostInfoShort' + host] = new Promise(function (resolve, reject) {
2082
+ var timeout = setTimeout(function () {
2083
+ if (timeout) {
2084
+ timeout = null;
2085
+ reject('hostInfoShort timeout');
2086
+ }
2087
+ }, timeoutMs || _this40.props.cmdTimeout);
2088
+
2089
+ _this40._socket.emit('sendToHost', host, 'getHostInfoShort', null, function (data) {
2090
+ if (timeout) {
2091
+ clearTimeout(timeout);
2092
+ timeout = null;
2093
+
2094
+ if (data === PERMISSION_ERROR) {
2095
+ reject('May not read "getHostInfoShort"');
2096
+ } else if (!data) {
2097
+ reject('Cannot read "getHostInfoShort"');
2098
+ } else {
2099
+ resolve(data);
2100
+ }
2101
+ }
2102
+ });
2103
+ });
2104
+ return this._promises['hostInfoShort' + host];
2105
+ }
2106
+ /**
2107
+ * Get the repository.
2108
+ * @param {string} host
2109
+ * @param {any} [args]
2110
+ * @param {boolean} [update] Force update.
2111
+ * @param {number} [timeoutMs] timeout in ms.
2112
+ * @returns {Promise<any>}
2113
+ */
2114
+
2115
+ }, {
2116
+ key: "getRepository",
2117
+ value: function getRepository(host, args, update, timeoutMs) {
2118
+ var _this41 = this;
2119
+
2120
+ if (Connection.isWeb()) {
2121
+ return Promise.reject('Allowed only in admin');
2122
+ }
2123
+
2124
+ if (!update && this._promises.repo) {
2125
+ return this._promises.repo;
2126
+ }
2127
+
2128
+ if (!this.connected) {
2129
+ return Promise.reject(NOT_CONNECTED);
2130
+ }
2131
+
2132
+ if (!host.startsWith('system.host.')) {
2133
+ host += 'system.host.' + host;
2134
+ }
2135
+
2136
+ this._promises.repo = new Promise(function (resolve, reject) {
2137
+ var timeout = setTimeout(function () {
2138
+ if (timeout) {
2139
+ timeout = null;
2140
+ reject('getRepository timeout');
2141
+ }
2142
+ }, timeoutMs || _this41.props.cmdTimeout);
2143
+
2144
+ _this41._socket.emit('sendToHost', host, 'getRepository', args, function (data) {
2145
+ if (timeout) {
2146
+ clearTimeout(timeout);
2147
+ timeout = null;
2148
+
2149
+ if (data === PERMISSION_ERROR) {
2150
+ reject('May not read "getRepository"');
2151
+ } else if (!data) {
2152
+ reject('Cannot read "getRepository"');
2153
+ } else {
2154
+ resolve(data);
2155
+ }
2156
+ }
2157
+ });
2158
+ });
2159
+ return this._promises.repo;
2160
+ }
2161
+ /**
2162
+ * Get the installed.
2163
+ * @param {string} host
2164
+ * @param {boolean} [update] Force update.
2165
+ * @param {number} [cmdTimeout] timeout in ms (optional)
2166
+ * @returns {Promise<any>}
2167
+ */
2168
+
2169
+ }, {
2170
+ key: "getInstalled",
2171
+ value: function getInstalled(host, update, cmdTimeout) {
2172
+ var _this42 = this;
2173
+
2174
+ if (Connection.isWeb()) {
2175
+ return Promise.reject('Allowed only in admin');
2176
+ }
2177
+
2178
+ this._promises.installed = this._promises.installed || {};
2179
+
2180
+ if (!update && this._promises.installed[host]) {
2181
+ return this._promises.installed[host];
2182
+ }
2183
+
2184
+ if (!this.connected) {
2185
+ return Promise.reject(NOT_CONNECTED);
2186
+ }
2187
+
2188
+ if (!host.startsWith('system.host.')) {
2189
+ host += 'system.host.' + host;
2190
+ }
2191
+
2192
+ this._promises.installed[host] = new Promise(function (resolve, reject) {
2193
+ var timeout = setTimeout(function () {
2194
+ if (timeout) {
2195
+ timeout = null;
2196
+ reject('getInstalled timeout');
2197
+ }
2198
+ }, cmdTimeout || _this42.props.cmdTimeout);
2199
+
2200
+ _this42._socket.emit('sendToHost', host, 'getInstalled', null, function (data) {
2201
+ if (timeout) {
2202
+ clearTimeout(timeout);
2203
+ timeout = null;
2204
+
2205
+ if (data === PERMISSION_ERROR) {
2206
+ reject('May not read "getInstalled"');
2207
+ } else if (!data) {
2208
+ reject('Cannot read "getInstalled"');
2209
+ } else {
2210
+ resolve(data);
2211
+ }
2212
+ }
2213
+ });
2214
+ });
2215
+ return this._promises.installed[host];
2216
+ }
2217
+ /**
2218
+ * Execute a command on a host.
2219
+ * @param {string} host The host name.
2220
+ * @param {string} cmd The command.
2221
+ * @param {string} cmdId The command ID.
2222
+ * @param {number} cmdTimeout Timeout of command in ms
2223
+ * @returns {Promise<void>}
2224
+ */
2225
+
2226
+ }, {
2227
+ key: "cmdExec",
2228
+ value: function cmdExec(host, cmd, cmdId, cmdTimeout) {
2229
+ var _this43 = this;
2230
+
2231
+ if (Connection.isWeb()) {
2232
+ return Promise.reject('Allowed only in admin');
2233
+ }
2234
+
2235
+ if (!this.connected) {
2236
+ return Promise.reject(NOT_CONNECTED);
2237
+ }
2238
+
2239
+ if (!host.startsWith(host)) {
2240
+ host += 'system.host.' + host;
2241
+ }
2242
+
2243
+ return new Promise(function (resolve, reject) {
2244
+ var timeout = cmdTimeout && setTimeout(function () {
2245
+ if (timeout) {
2246
+ timeout = null;
2247
+ reject('cmdExec timeout');
2248
+ }
2249
+ }, cmdTimeout);
2250
+
2251
+ _this43._socket.emit('cmdExec', host, cmdId, cmd, null, function (err) {
2252
+ if (!cmdTimeout || timeout) {
2253
+ timeout && clearTimeout(timeout);
2254
+ timeout = null;
2255
+
2256
+ if (err) {
2257
+ reject(err);
2258
+ } else {
2259
+ resolve();
2260
+ }
2261
+ }
2262
+ });
2263
+ });
2264
+ }
2265
+ /**
2266
+ * Checks if a given feature is supported.
2267
+ * @param {string} feature The feature to check.
2268
+ * @param {boolean} [update] Force update.
2269
+ * @returns {Promise<any>}
2270
+ */
2271
+
2272
+ }, {
2273
+ key: "checkFeatureSupported",
2274
+ value: function checkFeatureSupported(feature, update) {
2275
+ var _this44 = this;
2276
+
2277
+ if (!update && this._promises['supportedFeatures_' + feature]) {
2278
+ return this._promises['supportedFeatures_' + feature];
2279
+ }
2280
+
2281
+ if (!this.connected) {
2282
+ return Promise.reject(NOT_CONNECTED);
2283
+ }
2284
+
2285
+ this._promises['supportedFeatures_' + feature] = new Promise(function (resolve, reject) {
2286
+ return _this44._socket.emit('checkFeatureSupported', feature, function (err, features) {
2287
+ err ? reject(err) : resolve(features);
2288
+ });
2289
+ });
2290
+ return this._promises['supportedFeatures_' + feature];
2291
+ }
2292
+ /**
2293
+ * Read the base settings of a given host.
2294
+ * @param {string} host
2295
+ * @returns {Promise<any>}
2296
+ */
2297
+
2298
+ }, {
2299
+ key: "readBaseSettings",
2300
+ value: function readBaseSettings(host) {
2301
+ var _this45 = this;
2302
+
2303
+ if (Connection.isWeb()) {
2304
+ return Promise.reject('Allowed only in admin');
2305
+ }
2306
+
2307
+ return this.checkFeatureSupported('CONTROLLER_READWRITE_BASE_SETTINGS').then(function (result) {
2308
+ if (result) {
2309
+ if (!_this45.connected) {
2310
+ return Promise.reject(NOT_CONNECTED);
2311
+ }
2312
+
2313
+ return new Promise(function (resolve, reject) {
2314
+ var timeout = setTimeout(function () {
2315
+ if (timeout) {
2316
+ timeout = null;
2317
+ reject('readBaseSettings timeout');
2318
+ }
2319
+ }, _this45.props.cmdTimeout);
2320
+
2321
+ if (host.startsWith('system.host.')) {
2322
+ host = host.replace(/^system\.host\./, '');
2323
+ }
2324
+
2325
+ _this45._socket.emit('sendToHost', host, 'readBaseSettings', null, function (data) {
2326
+ if (timeout) {
2327
+ clearTimeout(timeout);
2328
+ timeout = null;
2329
+
2330
+ if (data === PERMISSION_ERROR) {
2331
+ reject('May not read "BaseSettings"');
2332
+ } else if (!data) {
2333
+ reject('Cannot read "BaseSettings"');
2334
+ } else {
2335
+ resolve(data);
2336
+ }
2337
+ }
2338
+ });
2339
+ });
2340
+ } else {
2341
+ return Promise.reject('Not supported');
2342
+ }
2343
+ });
2344
+ }
2345
+ /**
2346
+ * Write the base settings of a given host.
2347
+ * @param {string} host
2348
+ * @param {any} config
2349
+ * @returns {Promise<any>}
2350
+ */
2351
+
2352
+ }, {
2353
+ key: "writeBaseSettings",
2354
+ value: function writeBaseSettings(host, config) {
2355
+ var _this46 = this;
2356
+
2357
+ if (Connection.isWeb()) {
2358
+ return Promise.reject('Allowed only in admin');
2359
+ }
2360
+
2361
+ return this.checkFeatureSupported('CONTROLLER_READWRITE_BASE_SETTINGS').then(function (result) {
2362
+ if (result) {
2363
+ if (!_this46.connected) {
2364
+ return Promise.reject(NOT_CONNECTED);
2365
+ }
2366
+
2367
+ return new Promise(function (resolve, reject) {
2368
+ var timeout = setTimeout(function () {
2369
+ if (timeout) {
2370
+ timeout = null;
2371
+ reject('writeBaseSettings timeout');
2372
+ }
2373
+ }, _this46.props.cmdTimeout);
2374
+
2375
+ _this46._socket.emit('sendToHost', host, 'writeBaseSettings', config, function (data) {
2376
+ if (timeout) {
2377
+ clearTimeout(timeout);
2378
+ timeout = null;
2379
+
2380
+ if (data === PERMISSION_ERROR) {
2381
+ reject('May not write "BaseSettings"');
2382
+ } else if (!data) {
2383
+ reject('Cannot write "BaseSettings"');
2384
+ } else {
2385
+ resolve(data);
2386
+ }
2387
+ }
2388
+ });
2389
+ });
2390
+ } else {
2391
+ return Promise.reject('Not supported');
2392
+ }
2393
+ });
2394
+ }
2395
+ /**
2396
+ * Send command to restart the iobroker on host
2397
+ * @param {string} host
2398
+ * @returns {Promise<any>}
2399
+ */
2400
+
2401
+ }, {
2402
+ key: "restartController",
2403
+ value: function restartController(host) {
2404
+ var _this47 = this;
2405
+
2406
+ if (Connection.isWeb()) {
2407
+ return Promise.reject('Allowed only in admin');
2408
+ }
2409
+
2410
+ return new Promise(function (resolve, reject) {
2411
+ _this47._socket.emit('sendToHost', host, 'restartController', null, function (error) {
2412
+ error ? reject(error) : resolve(true);
2413
+ });
2414
+ });
2415
+ }
2416
+ /**
2417
+ * Read statistics information from host
2418
+ * @param {string} host
2419
+ * @param {string} typeOfDiag one of none, normal, no-city, extended
2420
+ * @returns {Promise<any>}
2421
+ */
2422
+
2423
+ }, {
2424
+ key: "getDiagData",
2425
+ value: function getDiagData(host, typeOfDiag) {
2426
+ var _this48 = this;
2427
+
2428
+ if (Connection.isWeb()) {
2429
+ return Promise.reject('Allowed only in admin');
2430
+ }
2431
+
2432
+ return new Promise(function (resolve) {
2433
+ _this48._socket.emit('sendToHost', host, 'getDiagData', typeOfDiag, function (result) {
2434
+ return resolve(result);
2435
+ });
2436
+ });
2437
+ }
2438
+ /**
2439
+ * Read all states (which might not belong to this adapter) which match the given pattern.
2440
+ * @param {string} pattern
2441
+ * @returns {ioBroker.GetStatesPromise}
2442
+ */
2443
+
2444
+ }, {
2445
+ key: "getForeignStates",
2446
+ value: function getForeignStates(pattern) {
2447
+ var _this49 = this;
2448
+
2449
+ if (!this.connected) {
2450
+ return Promise.reject(NOT_CONNECTED);
2451
+ }
2452
+
2453
+ if (Connection.isWeb()) {
2454
+ return new Promise(function (resolve, reject) {
2455
+ return _this49._socket.emit('getStates', pattern || '*', function (err, states) {
2456
+ return err ? reject(err) : resolve(states);
2457
+ });
2458
+ });
2459
+ } else {
2460
+ return new Promise(function (resolve, reject) {
2461
+ return _this49._socket.emit('getForeignStates', pattern || '*', function (err, states) {
2462
+ return err ? reject(err) : resolve(states);
2463
+ });
2464
+ });
2465
+ }
2466
+ }
2467
+ /**
2468
+ * Get foreign objects by pattern, by specific type and resolve their enums.
2469
+ * @param {string} pattern
2470
+ * @param {string} [type]
2471
+ * @returns {ioBroker.GetObjectsPromise}
2472
+ */
2473
+
2474
+ }, {
2475
+ key: "getForeignObjects",
2476
+ value: function getForeignObjects(pattern, type) {
2477
+ var _this50 = this;
2478
+
2479
+ if (!this.connected) {
2480
+ return Promise.reject(NOT_CONNECTED);
2481
+ }
2482
+
2483
+ return new Promise(function (resolve, reject) {
2484
+ return _this50._socket.emit('getForeignObjects', pattern || '*', type, function (err, states) {
2485
+ return err ? reject(err) : resolve(states);
2486
+ });
2487
+ });
2488
+ }
2489
+ /**
2490
+ * Gets the system configuration.
2491
+ * @param {boolean} [update] Force update.
2492
+ * @returns {Promise<ioBroker.OtherObject>}
2493
+ */
2494
+
2495
+ }, {
2496
+ key: "getSystemConfig",
2497
+ value: function getSystemConfig(update) {
2498
+ if (!update && this._promises.systemConfig) {
2499
+ return this._promises.systemConfig;
2500
+ }
2501
+
2502
+ if (!this.connected) {
2503
+ return Promise.reject(NOT_CONNECTED);
2504
+ }
2505
+
2506
+ this._promises.systemConfig = this.getObject('system.config').then(function (systemConfig) {
2507
+ //@ts-ignore
2508
+ systemConfig = systemConfig || {}; //@ts-ignore
2509
+
2510
+ systemConfig.common = systemConfig.common || {}; //@ts-ignore
2511
+
2512
+ systemConfig["native"] = systemConfig["native"] || {};
2513
+ return systemConfig;
2514
+ });
2515
+ return this._promises.systemConfig;
2516
+ }
2517
+ /**
2518
+ * Sets the system configuration.
2519
+ * @param {ioBroker.SettableObjectWorker<ioBroker.OtherObject>} obj
2520
+ * @returns {Promise<ioBroker.SettableObjectWorker<ioBroker.OtherObject>>}
2521
+ */
2522
+
2523
+ }, {
2524
+ key: "setSystemConfig",
2525
+ value: function setSystemConfig(obj) {
2526
+ var _this51 = this;
2527
+
2528
+ return this.setObject('system.config', obj).then(function () {
2529
+ return _this51._promises.systemConfig = Promise.resolve(obj);
2530
+ });
2531
+ }
2532
+ /**
2533
+ * Get the raw socket.io socket.
2534
+ * @returns {any}
2535
+ */
2536
+
2537
+ }, {
2538
+ key: "getRawSocket",
2539
+ value: function getRawSocket() {
2540
+ return this._socket;
2541
+ }
2542
+ /**
2543
+ * Get the history of a given state.
2544
+ * @param {string} id
2545
+ * @param {ioBroker.GetHistoryOptions} options
2546
+ * @returns {Promise<ioBroker.GetHistoryResult>}
2547
+ */
2548
+
2549
+ }, {
2550
+ key: "getHistory",
2551
+ value: function getHistory(id, options) {
2552
+ var _this52 = this;
2553
+
2554
+ if (!this.connected) {
2555
+ return Promise.reject(NOT_CONNECTED);
2556
+ }
2557
+
2558
+ return new Promise(function (resolve, reject) {
2559
+ return _this52._socket.emit('getHistory', id, options, function (err, values) {
2560
+ return err ? reject(err) : resolve(values);
2561
+ });
2562
+ });
2563
+ }
2564
+ /**
2565
+ * Get the history of a given state.
2566
+ * @param {string} id
2567
+ * @param {ioBroker.GetHistoryOptions} options
2568
+ * @returns {Promise<{values: ioBroker.GetHistoryResult; sesionId: string; stepIgnore: number}>}
2569
+ */
2570
+
2571
+ }, {
2572
+ key: "getHistoryEx",
2573
+ value: function getHistoryEx(id, options) {
2574
+ var _this53 = this;
2575
+
2576
+ if (!this.connected) {
2577
+ return Promise.reject(NOT_CONNECTED);
2578
+ }
2579
+
2580
+ return new Promise(function (resolve, reject) {
2581
+ return _this53._socket.emit('getHistory', id, options, function (err, values, stepIgnore, sessionId) {
2582
+ return err ? reject(err) : resolve({
2583
+ values: values,
2584
+ sessionId: sessionId,
2585
+ stepIgnore: stepIgnore
2586
+ });
2587
+ });
2588
+ });
2589
+ }
2590
+ /**
2591
+ * Change the password of the given user.
2592
+ * @param {string} user
2593
+ * @param {string} password
2594
+ * @returns {Promise<void>}
2595
+ */
2596
+
2597
+ }, {
2598
+ key: "changePassword",
2599
+ value: function changePassword(user, password) {
2600
+ var _this54 = this;
2601
+
2602
+ if (Connection.isWeb()) {
2603
+ return Promise.reject('Allowed only in admin');
2604
+ }
2605
+
2606
+ return new Promise(function (resolve, reject) {
2607
+ return _this54._socket.emit('changePassword', user, password, function (err) {
2608
+ return err ? reject(err) : resolve();
2609
+ });
2610
+ });
2611
+ }
2612
+ /**
2613
+ * Get the IP addresses of the given host.
2614
+ * @param {string} host
2615
+ * @param {boolean} [update] Force update.
2616
+ * @returns {Promise<string[]>}
2617
+ */
2618
+
2619
+ }, {
2620
+ key: "getIpAddresses",
2621
+ value: function getIpAddresses(host, update) {
2622
+ if (Connection.isWeb()) {
2623
+ return Promise.reject('Allowed only in admin');
2624
+ }
2625
+
2626
+ if (!host.startsWith('system.host.')) {
2627
+ host = 'system.host.' + host;
2628
+ }
2629
+
2630
+ if (!update && this._promises['IPs_' + host]) {
2631
+ return this._promises['IPs_' + host];
2632
+ }
2633
+
2634
+ this._promises['IPs_' + host] = this.getObject(host).then(function (obj) {
2635
+ return obj && obj.common ? obj.common.address || [] : [];
2636
+ });
2637
+ return this._promises['IPs_' + host];
2638
+ }
2639
+ /**
2640
+ * Get the IP addresses with interface names of the given host or find host by IP.
2641
+ * @param {string} ipOrHostName
2642
+ * @param {boolean} [update] Force update.
2643
+ * @returns {Promise<any[<name, address, family>]>}
2644
+ */
2645
+
2646
+ }, {
2647
+ key: "getHostByIp",
2648
+ value: function getHostByIp(ipOrHostName, update) {
2649
+ var _this55 = this;
2650
+
2651
+ if (Connection.isWeb()) {
2652
+ return Promise.reject('Allowed only in admin');
2653
+ }
2654
+
2655
+ if (ipOrHostName.startsWith('system.host.')) {
2656
+ ipOrHostName = ipOrHostName.replace(/^system\.host\./, '');
2657
+ }
2658
+
2659
+ if (!update && this._promises['rIPs_' + ipOrHostName]) {
2660
+ return this._promises['rIPs_' + ipOrHostName];
2661
+ }
2662
+
2663
+ this._promises['rIPs_' + ipOrHostName] = new Promise(function (resolve) {
2664
+ return _this55._socket.emit('getHostByIp', ipOrHostName, function (ip, host) {
2665
+ var _host$native, _host$native$hardware;
2666
+
2667
+ var IPs4 = [{
2668
+ name: '[IPv4] 0.0.0.0 - Listen on all IPs',
2669
+ address: '0.0.0.0',
2670
+ family: 'ipv4'
2671
+ }];
2672
+ var IPs6 = [{
2673
+ name: '[IPv6] :: - Listen on all IPs',
2674
+ address: '::',
2675
+ family: 'ipv6'
2676
+ }];
2677
+
2678
+ if ((_host$native = host["native"]) !== null && _host$native !== void 0 && (_host$native$hardware = _host$native.hardware) !== null && _host$native$hardware !== void 0 && _host$native$hardware.networkInterfaces) {
2679
+ for (var eth in host["native"].hardware.networkInterfaces) {
2680
+ if (!host["native"].hardware.networkInterfaces.hasOwnProperty(eth)) {
2681
+ continue;
2682
+ }
2683
+
2684
+ for (var num = 0; num < host["native"].hardware.networkInterfaces[eth].length; num++) {
2685
+ if (host["native"].hardware.networkInterfaces[eth][num].family !== 'IPv6') {
2686
+ IPs4.push({
2687
+ name: "[".concat(host["native"].hardware.networkInterfaces[eth][num].family, "] ").concat(host["native"].hardware.networkInterfaces[eth][num].address, " - ").concat(eth),
2688
+ address: host["native"].hardware.networkInterfaces[eth][num].address,
2689
+ family: 'ipv4'
2690
+ });
2691
+ } else {
2692
+ IPs6.push({
2693
+ name: "[".concat(host["native"].hardware.networkInterfaces[eth][num].family, "] ").concat(host["native"].hardware.networkInterfaces[eth][num].address, " - ").concat(eth),
2694
+ address: host["native"].hardware.networkInterfaces[eth][num].address,
2695
+ family: 'ipv6'
2696
+ });
2697
+ }
2698
+ }
2699
+ }
2700
+ }
2701
+
2702
+ for (var i = 0; i < IPs6.length; i++) {
2703
+ IPs4.push(IPs6[i]);
2704
+ }
2705
+
2706
+ resolve(IPs4);
2707
+ });
2708
+ });
2709
+ return this._promises['rIPs_' + ipOrHostName];
2710
+ }
2711
+ /**
2712
+ * Encrypt a text
2713
+ * @param {string} text
2714
+ * @returns {Promise<string>}
2715
+ */
2716
+
2717
+ }, {
2718
+ key: "encrypt",
2719
+ value: function encrypt(text) {
2720
+ var _this56 = this;
2721
+
2722
+ if (Connection.isWeb()) {
2723
+ return Promise.reject('Allowed only in admin');
2724
+ }
2725
+
2726
+ return new Promise(function (resolve, reject) {
2727
+ return _this56._socket.emit('encrypt', text, function (err, text) {
2728
+ return err ? reject(err) : resolve(text);
2729
+ });
2730
+ });
2731
+ }
2732
+ /**
2733
+ * Decrypt a text
2734
+ * @param {string} encryptedText
2735
+ * @returns {Promise<string>}
2736
+ */
2737
+
2738
+ }, {
2739
+ key: "decrypt",
2740
+ value: function decrypt(encryptedText) {
2741
+ var _this57 = this;
2742
+
2743
+ if (Connection.isWeb()) {
2744
+ return Promise.reject('Allowed only in admin');
2745
+ }
2746
+
2747
+ return new Promise(function (resolve, reject) {
2748
+ return _this57._socket.emit('decrypt', encryptedText, function (err, text) {
2749
+ return err ? reject(err) : resolve(text);
2750
+ });
2751
+ });
2752
+ }
2753
+ /**
2754
+ * Gets the version.
2755
+ * @returns {Promise<{version: string; serverName: string}>}
2756
+ */
2757
+
2758
+ }, {
2759
+ key: "getVersion",
2760
+ value: function getVersion(update) {
2761
+ var _this58 = this;
2762
+
2763
+ if (update && this._promises.version) {
2764
+ this._promises.version = null;
2765
+ }
2766
+
2767
+ this._promises.version = this._promises.version || new Promise(function (resolve, reject) {
2768
+ return _this58._socket.emit('getVersion', function (err, version, serverName) {
2769
+ // support of old socket.io
2770
+ if (err && !version && typeof err === 'string' && err.match(/\d+\.\d+\.\d+/)) {
2771
+ resolve({
2772
+ version: err,
2773
+ serverName: 'socketio'
2774
+ });
2775
+ } else {
2776
+ return err ? reject(err) : resolve({
2777
+ version: version,
2778
+ serverName: serverName
2779
+ });
2780
+ }
2781
+ });
2782
+ });
2783
+ return this._promises.version;
2784
+ }
2785
+ /**
2786
+ * Gets the web server name.
2787
+ * @returns {Promise<string>}
2788
+ */
2789
+
2790
+ }, {
2791
+ key: "getWebServerName",
2792
+ value: function getWebServerName() {
2793
+ var _this59 = this;
2794
+
2795
+ this._promises.webName = this._promises.webName || new Promise(function (resolve, reject) {
2796
+ return _this59._socket.emit('getAdapterName', function (err, name) {
2797
+ return err ? reject(err) : resolve(name);
2798
+ });
2799
+ });
2800
+ return this._promises.webName;
2801
+ }
2802
+ /**
2803
+ * Gets the admin version.
2804
+ * @deprecated use getVersion()
2805
+ * @returns {Promise<{version: string; serverName: string}>}
2806
+ */
2807
+
2808
+ }, {
2809
+ key: "getAdminVersion",
2810
+ value: function getAdminVersion() {
2811
+ console.log('Deprecated: use getVersion');
2812
+ return this.getVersion();
2813
+ }
2814
+ /**
2815
+ * Change access rights for file
2816
+ * @param {string} [adapter] adapter name
2817
+ * @param {string} [filename] file name with full path. it could be like vis.0/*
2818
+ * @param {object} [options] like {mode: 0x644}
2819
+ * @returns {Promise<{entries: array}>}
2820
+ */
2821
+
2822
+ }, {
2823
+ key: "chmodFile",
2824
+ value: function chmodFile(adapter, filename, options) {
2825
+ var _this60 = this;
2826
+
2827
+ if (Connection.isWeb()) {
2828
+ return Promise.reject('Allowed only in admin');
2829
+ }
2830
+
2831
+ if (!this.connected) {
2832
+ return Promise.reject(NOT_CONNECTED);
2833
+ }
2834
+
2835
+ return new Promise(function (resolve, reject) {
2836
+ return _this60._socket.emit('chmodFile', adapter, filename, options, function (err, entries, id) {
2837
+ return err ? reject(err) : resolve({
2838
+ entries: entries,
2839
+ id: id
2840
+ });
2841
+ });
2842
+ });
2843
+ }
2844
+ /**
2845
+ * Change owner or/and owner group for file
2846
+ * @param {string} [adapter] adapter name
2847
+ * @param {string} [filename] file name with full path. it could be like vis.0/*
2848
+ * @param {object} [options] like {owner: 'newOwner', ownerGroup: 'newGroup'}
2849
+ * @returns {Promise<{entries: array}>}
2850
+ */
2851
+
2852
+ }, {
2853
+ key: "chownFile",
2854
+ value: function chownFile(adapter, filename, options) {
2855
+ var _this61 = this;
2856
+
2857
+ if (Connection.isWeb()) {
2858
+ return Promise.reject('Allowed only in admin');
2859
+ }
2860
+
2861
+ if (!this.connected) {
2862
+ return Promise.reject(NOT_CONNECTED);
2863
+ }
2864
+
2865
+ return new Promise(function (resolve, reject) {
2866
+ return _this61._socket.emit('chownFile', adapter, filename, options, function (err, entries, id) {
2867
+ return err ? reject(err) : resolve({
2868
+ entries: entries,
2869
+ id: id
2870
+ });
2871
+ });
2872
+ });
2873
+ }
2874
+ /**
2875
+ * Check if the file exists
2876
+ * @param {string} [adapter] adapter name
2877
+ * @param {string} [filename] file name with full path. it could be like vis.0/*
2878
+ * @returns {Promise<boolean>}
2879
+ */
2880
+
2881
+ }, {
2882
+ key: "fileExists",
2883
+ value: function fileExists(adapter, filename) {
2884
+ var _this62 = this;
2885
+
2886
+ if (!this.connected) {
2887
+ return Promise.reject(NOT_CONNECTED);
2888
+ }
2889
+
2890
+ return new Promise(function (resolve, reject) {
2891
+ return _this62._socket.emit('fileExists', adapter, filename, function (err, exists) {
2892
+ return err ? reject(err) : resolve(exists);
2893
+ });
2894
+ });
2895
+ }
2896
+ /**
2897
+ * Get the alarm notifications from a host (only for admin connection).
2898
+ * @param {string} host
2899
+ * @param {string} [category] - optional
2900
+ * @returns {Promise<any>}
2901
+ */
2902
+
2903
+ }, {
2904
+ key: "getNotifications",
2905
+ value: function getNotifications(host, category) {
2906
+ var _this63 = this;
2907
+
2908
+ if (Connection.isWeb()) {
2909
+ return Promise.reject('Allowed only in admin');
2910
+ }
2911
+
2912
+ if (!this.connected) {
2913
+ return Promise.reject(NOT_CONNECTED);
2914
+ }
2915
+
2916
+ return new Promise(function (resolve) {
2917
+ return _this63._socket.emit('sendToHost', host, 'getNotifications', {
2918
+ category: category
2919
+ }, function (notifications) {
2920
+ return resolve(notifications);
2921
+ });
2922
+ });
2923
+ }
2924
+ /**
2925
+ * Clear the alarm notifications on a host (only for admin connection).
2926
+ * @param {string} host
2927
+ * @param {string} [category] - optional
2928
+ * @returns {Promise<any>}
2929
+ */
2930
+
2931
+ }, {
2932
+ key: "clearNotifications",
2933
+ value: function clearNotifications(host, category) {
2934
+ var _this64 = this;
2935
+
2936
+ if (Connection.isWeb()) {
2937
+ return Promise.reject('Allowed only in admin');
2938
+ }
2939
+
2940
+ if (!this.connected) {
2941
+ return Promise.reject(NOT_CONNECTED);
2942
+ }
2943
+
2944
+ return new Promise(function (resolve) {
2945
+ return _this64._socket.emit('sendToHost', host, 'clearNotifications', {
2946
+ category: category
2947
+ }, function (notifications) {
2948
+ return resolve(notifications);
2949
+ });
2950
+ });
2951
+ }
2952
+ /**
2953
+ * Read if only easy mode is allowed (only for admin connection).
2954
+ * @returns {Promise<boolean>}
2955
+ */
2956
+
2957
+ }, {
2958
+ key: "getIsEasyModeStrict",
2959
+ value: function getIsEasyModeStrict() {
2960
+ var _this65 = this;
2961
+
2962
+ if (Connection.isWeb()) {
2963
+ return Promise.reject('Allowed only in admin');
2964
+ }
2965
+
2966
+ if (!this.connected) {
2967
+ return Promise.reject(NOT_CONNECTED);
2968
+ }
2969
+
2970
+ return new Promise(function (resolve, reject) {
2971
+ return _this65._socket.emit('getIsEasyModeStrict', function (error, isStrict) {
2972
+ return error ? reject(error) : resolve(isStrict);
2973
+ });
2974
+ });
2975
+ }
2976
+ /**
2977
+ * Read easy mode configuration (only for admin connection).
2978
+ * @returns {Promise<any>}
2979
+ */
2980
+
2981
+ }, {
2982
+ key: "getEasyMode",
2983
+ value: function getEasyMode() {
2984
+ var _this66 = this;
2985
+
2986
+ if (Connection.isWeb()) {
2987
+ return Promise.reject('Allowed only in admin');
2988
+ }
2989
+
2990
+ if (!this.connected) {
2991
+ return Promise.reject(NOT_CONNECTED);
2992
+ }
2993
+
2994
+ return new Promise(function (resolve, reject) {
2995
+ return _this66._socket.emit('getEasyMode', function (error, config) {
2996
+ return error ? reject(error) : resolve(config);
2997
+ });
2998
+ });
2999
+ }
3000
+ /**
3001
+ * Read current user
3002
+ * @returns {Promise<string>}
3003
+ */
3004
+
3005
+ }, {
3006
+ key: "getCurrentUser",
3007
+ value: function getCurrentUser() {
3008
+ var _this67 = this;
3009
+
3010
+ if (!this.connected) {
3011
+ return Promise.reject(NOT_CONNECTED);
3012
+ }
3013
+
3014
+ return new Promise(function (resolve) {
3015
+ return _this67._socket.emit('authEnabled', function (isSecure, user) {
3016
+ return resolve(user);
3017
+ });
3018
+ });
3019
+ }
3020
+ }, {
3021
+ key: "getCurrentSession",
3022
+ value: function getCurrentSession(cmdTimeout) {
3023
+ if (!this.connected) {
3024
+ return Promise.reject(NOT_CONNECTED);
3025
+ }
3026
+
3027
+ return new Promise(function (resolve, reject) {
3028
+ var controller = new AbortController();
3029
+ var timeout = setTimeout(function () {
3030
+ if (timeout) {
3031
+ timeout = null;
3032
+ controller.abort();
3033
+ reject('getCurrentSession timeout');
3034
+ }
3035
+ }, cmdTimeout || 5000);
3036
+ return fetch('./session', {
3037
+ signal: controller.signal
3038
+ }).then(function (res) {
3039
+ return res.json();
3040
+ }).then(function (json) {
3041
+ if (timeout) {
3042
+ clearTimeout(timeout);
3043
+ timeout = null;
3044
+ resolve(json);
3045
+ }
3046
+ })["catch"](function (e) {
3047
+ reject('getCurrentSession: ' + e);
3048
+ });
3049
+ });
3050
+ }
3051
+ /**
3052
+ * Read adapter ratings
3053
+ * @returns {Promise<any>}
3054
+ */
3055
+
3056
+ }, {
3057
+ key: "getRatings",
3058
+ value: function getRatings(update) {
3059
+ var _this68 = this;
3060
+
3061
+ if (Connection.isWeb()) {
3062
+ return Promise.reject('Allowed only in admin');
3063
+ }
3064
+
3065
+ if (!this.connected) {
3066
+ return Promise.reject(NOT_CONNECTED);
3067
+ }
3068
+
3069
+ return new Promise(function (resolve, reject) {
3070
+ return _this68._socket.emit('getRatings', update, function (err, ratings) {
3071
+ return err ? reject(err) : resolve(ratings);
3072
+ });
3073
+ });
3074
+ }
3075
+ /**
3076
+ * Read current web, socketio or admin namespace, like admin.0
3077
+ * @returns {Promise<string>}
3078
+ */
3079
+
3080
+ }, {
3081
+ key: "getCurrentInstance",
3082
+ value: function getCurrentInstance() {
3083
+ var _this69 = this;
3084
+
3085
+ if (!this.connected) {
3086
+ return Promise.reject(NOT_CONNECTED);
3087
+ }
3088
+
3089
+ this._promises.currentInstance = this._promises.currentInstance || new Promise(function (resolve, reject) {
3090
+ return _this69._socket.emit('getCurrentInstance', function (err, namespace) {
3091
+ return err ? reject(err) : resolve(namespace);
3092
+ });
3093
+ });
3094
+ return this._promises.currentInstance;
3095
+ } // returns very optimized information for adapters to minimize connection load
3096
+
3097
+ }, {
3098
+ key: "getCompactAdapters",
3099
+ value: function getCompactAdapters(update) {
3100
+ var _this70 = this;
3101
+
3102
+ if (Connection.isWeb()) {
3103
+ return Promise.reject('Allowed only in admin');
3104
+ }
3105
+
3106
+ if (!update && this._promises.compactAdapters) {
3107
+ return this._promises.compactAdapters;
3108
+ }
3109
+
3110
+ if (!this.connected) {
3111
+ return Promise.reject(NOT_CONNECTED);
3112
+ }
3113
+
3114
+ this._promises.compactAdapters = new Promise(function (resolve, reject) {
3115
+ return _this70._socket.emit('getCompactAdapters', function (err, adapters) {
3116
+ return err ? reject(err) : resolve(adapters);
3117
+ });
3118
+ });
3119
+ return this._promises.compactAdapters;
3120
+ } // returns very optimized information for adapters to minimize connection load
3121
+
3122
+ }, {
3123
+ key: "getCompactInstances",
3124
+ value: function getCompactInstances(update) {
3125
+ var _this71 = this;
3126
+
3127
+ if (Connection.isWeb()) {
3128
+ return Promise.reject('Allowed only in admin');
3129
+ }
3130
+
3131
+ if (!update && this._promises.compactInstances) {
3132
+ return this._promises.compactInstances;
3133
+ }
3134
+
3135
+ if (!this.connected) {
3136
+ return Promise.reject(NOT_CONNECTED);
3137
+ }
3138
+
3139
+ this._promises.compactInstances = new Promise(function (resolve, reject) {
3140
+ return _this71._socket.emit('getCompactInstances', function (err, instances) {
3141
+ return err ? reject(err) : resolve(instances);
3142
+ });
3143
+ });
3144
+ return this._promises.compactInstances;
3145
+ } // returns very optimized information for adapters to minimize connection load
3146
+ // reads only version of installed adapter
3147
+
3148
+ }, {
3149
+ key: "getCompactInstalled",
3150
+ value: function getCompactInstalled(host, update, cmdTimeout) {
3151
+ var _this72 = this;
3152
+
3153
+ if (Connection.isWeb()) {
3154
+ return Promise.reject('Allowed only in admin');
3155
+ }
3156
+
3157
+ this._promises.installedCompact = this._promises.installedCompact || {};
3158
+
3159
+ if (!update && this._promises.installedCompact[host]) {
3160
+ return this._promises.installedCompact[host];
3161
+ }
3162
+
3163
+ if (!this.connected) {
3164
+ return Promise.reject(NOT_CONNECTED);
3165
+ }
3166
+
3167
+ if (!host.startsWith('system.host.')) {
3168
+ host += 'system.host.' + host;
3169
+ }
3170
+
3171
+ this._promises.installedCompact[host] = new Promise(function (resolve, reject) {
3172
+ var timeout = setTimeout(function () {
3173
+ if (timeout) {
3174
+ timeout = null;
3175
+ reject('getCompactInstalled timeout');
3176
+ }
3177
+ }, cmdTimeout || _this72.props.cmdTimeout);
3178
+
3179
+ _this72._socket.emit('getCompactInstalled', host, function (data) {
3180
+ if (timeout) {
3181
+ clearTimeout(timeout);
3182
+ timeout = null;
3183
+
3184
+ if (data === PERMISSION_ERROR) {
3185
+ reject('May not read "getCompactInstalled"');
3186
+ } else if (!data) {
3187
+ reject('Cannot read "getCompactInstalled"');
3188
+ } else {
3189
+ resolve(data);
3190
+ }
3191
+ }
3192
+ });
3193
+ });
3194
+ return this._promises.installedCompact[host];
3195
+ } // returns very optimized information for adapters to minimize connection load
3196
+
3197
+ }, {
3198
+ key: "getCompactSystemConfig",
3199
+ value: function getCompactSystemConfig(update) {
3200
+ var _this73 = this;
3201
+
3202
+ if (!update && this._promises.systemConfigCommon) {
3203
+ return this._promises.systemConfigCommon;
3204
+ }
3205
+
3206
+ if (!this.connected) {
3207
+ return Promise.reject(NOT_CONNECTED);
3208
+ }
3209
+
3210
+ this._promises.systemConfigCommon = new Promise(function (resolve, reject) {
3211
+ return _this73._socket.emit('getCompactSystemConfig', function (err, systemConfig) {
3212
+ return err ? reject(err) : resolve(systemConfig);
3213
+ });
3214
+ });
3215
+ return this._promises.systemConfigCommon;
3216
+ }
3217
+ /**
3218
+ * Get the repository in compact form (only version and icon).
3219
+ * @param {string} host
3220
+ * @param {boolean} [update] Force update.
3221
+ * @param {number} [timeoutMs] timeout in ms.
3222
+ * @returns {Promise<any>}
3223
+ */
3224
+
3225
+ }, {
3226
+ key: "getCompactRepository",
3227
+ value: function getCompactRepository(host, update, timeoutMs) {
3228
+ var _this74 = this;
3229
+
3230
+ if (Connection.isWeb()) {
3231
+ return Promise.reject('Allowed only in admin');
3232
+ }
3233
+
3234
+ if (!update && this._promises.repoCompact) {
3235
+ return this._promises.repoCompact;
3236
+ }
3237
+
3238
+ if (!this.connected) {
3239
+ return Promise.reject(NOT_CONNECTED);
3240
+ }
3241
+
3242
+ if (!host.startsWith('system.host.')) {
3243
+ host += 'system.host.' + host;
3244
+ }
3245
+
3246
+ this._promises.repoCompact = new Promise(function (resolve, reject) {
3247
+ var timeout = setTimeout(function () {
3248
+ if (timeout) {
3249
+ timeout = null;
3250
+ reject('getCompactRepository timeout');
3251
+ }
3252
+ }, timeoutMs || _this74.props.cmdTimeout);
3253
+
3254
+ _this74._socket.emit('getCompactRepository', host, function (data) {
3255
+ if (timeout) {
3256
+ clearTimeout(timeout);
3257
+ timeout = null;
3258
+
3259
+ if (data === PERMISSION_ERROR) {
3260
+ reject('May not read "getCompactRepository"');
3261
+ } else if (!data) {
3262
+ reject('Cannot read "getCompactRepository"');
3263
+ } else {
3264
+ resolve(data);
3265
+ }
3266
+ }
3267
+ });
3268
+ });
3269
+ return this._promises.repoCompact;
3270
+ }
3271
+ /**
3272
+ * Get the list of all hosts in compact form (only _id, common.name, common.icon, common.color, native.hardware.networkInterfaces)
3273
+ * @param {boolean} [update] Force update.
3274
+ * @returns {Promise<ioBroker.Object[]>}
3275
+ */
3276
+
3277
+ }, {
3278
+ key: "getCompactHosts",
3279
+ value: function getCompactHosts(update) {
3280
+ var _this75 = this;
3281
+
3282
+ if (Connection.isWeb()) {
3283
+ return Promise.reject('Allowed only in admin');
3284
+ }
3285
+
3286
+ if (!update && this._promises.hostsCompact) {
3287
+ return this._promises.hostsCompact;
3288
+ }
3289
+
3290
+ if (!this.connected) {
3291
+ return Promise.reject(NOT_CONNECTED);
3292
+ }
3293
+
3294
+ this._promises.hostsCompact = new Promise(function (resolve, reject) {
3295
+ return _this75._socket.emit('getCompactHosts', function (err, hosts) {
3296
+ return err ? reject(err) : resolve(hosts);
3297
+ });
3298
+ });
3299
+ return this._promises.hostsCompact;
3300
+ }
3301
+ /**
3302
+ * Get uuid
3303
+ * @returns {Promise<ioBroker.Object[]>}
3304
+ */
3305
+
3306
+ }, {
3307
+ key: "getUuid",
3308
+ value: function getUuid() {
3309
+ if (this._promises.uuid) {
3310
+ return this._promises.uuid;
3311
+ }
3312
+
3313
+ if (!this.connected) {
3314
+ return Promise.reject(NOT_CONNECTED);
3315
+ }
3316
+
3317
+ this._promises.uuid = this.getObject('system.meta.uuid') //@ts-ignore
3318
+ .then(function (obj) {
3319
+ var _obj$native;
3320
+
3321
+ return obj === null || obj === void 0 ? void 0 : (_obj$native = obj["native"]) === null || _obj$native === void 0 ? void 0 : _obj$native.uuid;
3322
+ });
3323
+ return this._promises.uuid;
3324
+ }
3325
+ /**
3326
+ * Send log to ioBroker log
3327
+ * @param {string} [text] Log text
3328
+ * @param {string} [level] `info`, `debug`, `warn`, `error` or `silly`
3329
+ * @returns {void}
3330
+ */
3331
+
3332
+ }, {
3333
+ key: "log",
3334
+ value: function log(text, level) {
3335
+ text && this._socket.emit('log', text, level || 'debug');
3336
+ }
3337
+ /**
3338
+ * Logout current user
3339
+ * @returns {Promise<null>}
3340
+ */
3341
+
3342
+ }, {
3343
+ key: "logout",
3344
+ value: function logout() {
3345
+ var _this76 = this;
3346
+
3347
+ if (!this.connected) {
3348
+ return Promise.reject(NOT_CONNECTED);
3349
+ }
3350
+
3351
+ return new Promise(function (resolve, reject) {
3352
+ return _this76._socket.emit('logout', function (err) {
3353
+ return err ? reject(err) : resolve(null);
3354
+ });
3355
+ });
3356
+ }
3357
+ }], [{
3358
+ key: "isWeb",
3359
+ value: function isWeb() {
3360
+ return window.adapterName === 'material' || window.adapterName === 'vis' || window.socketUrl !== undefined;
3361
+ }
3362
+ }]);
3363
+
3364
+ return Connection;
3365
+ }();
3366
+
3367
+ Connection.Connection = {
3368
+ onLog: _propTypes["default"].func,
3369
+ onReady: _propTypes["default"].func,
3370
+ onProgress: _propTypes["default"].func
3371
+ };
3372
+ var _default = Connection;
3373
+ exports["default"] = _default;
3374
+ //# sourceMappingURL=Connection.js.map