@iobroker/adapter-react-v5 7.0.2 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Components/404.d.ts +3 -2
- package/Components/404.js +3 -2
- package/Components/ColorPicker.d.ts +22 -8
- package/Components/ColorPicker.js +34 -17
- package/Components/ComplexCron.js +24 -24
- package/Components/CopyToClipboard.d.ts +10 -1
- package/Components/CopyToClipboard.js +17 -8
- package/Components/CustomModal.d.ts +1 -1
- package/Components/CustomModal.js +8 -8
- package/Components/FileBrowser.d.ts +11 -11
- package/Components/FileBrowser.js +135 -152
- package/Components/FileViewer.js +34 -23
- package/Components/Icon.d.ts +16 -2
- package/Components/Icon.js +19 -8
- package/Components/IconPicker.js +10 -14
- package/Components/IconSelector.d.ts +1 -1
- package/Components/IconSelector.js +64 -74
- package/Components/Image.d.ts +8 -4
- package/Components/Image.js +13 -32
- package/Components/Loader.d.ts +2 -2
- package/Components/Loader.js +21 -18
- package/Components/Loaders/MV.d.ts +6 -1
- package/Components/Loaders/MV.js +23 -7
- package/Components/Loaders/PT.d.ts +7 -2
- package/Components/Loaders/PT.js +20 -7
- package/Components/Loaders/Vendor.d.ts +2 -2
- package/Components/Loaders/Vendor.js +15 -7
- package/Components/Logo.js +16 -18
- package/Components/MDUtils.d.ts +1 -1
- package/Components/MDUtils.js +8 -4
- package/Components/ObjectBrowser.d.ts +40 -39
- package/Components/ObjectBrowser.js +550 -435
- package/Components/Router.d.ts +1 -3
- package/Components/Router.js +3 -1
- package/Components/SaveCloseButtons.d.ts +3 -3
- package/Components/SaveCloseButtons.js +3 -3
- package/Components/Schedule.d.ts +15 -15
- package/Components/Schedule.js +177 -154
- package/Components/SelectWithIcon.d.ts +2 -2
- package/Components/SelectWithIcon.js +45 -34
- package/Components/SimpleCron/index.js +83 -43
- package/Components/TabContainer.js +2 -2
- package/Components/TabContent.js +1 -1
- package/Components/TabHeader.js +1 -1
- package/Components/TableResize.d.ts +2 -2
- package/Components/TableResize.js +5 -5
- package/Components/TextWithIcon.d.ts +1 -1
- package/Components/TextWithIcon.js +10 -8
- package/Components/ToggleThemeMenu.d.ts +2 -2
- package/Components/ToggleThemeMenu.js +3 -3
- package/Components/TreeTable.d.ts +18 -18
- package/Components/TreeTable.js +76 -72
- package/Components/UploadImage.d.ts +2 -2
- package/Components/UploadImage.js +25 -21
- package/Components/Utils.d.ts +42 -22
- package/Components/Utils.js +66 -65
- package/Components/withWidth.d.ts +2 -2
- package/Components/withWidth.js +10 -6
- package/Dialogs/ComplexCron.d.ts +2 -2
- package/Dialogs/ComplexCron.js +3 -3
- package/Dialogs/Confirm.d.ts +4 -4
- package/Dialogs/Confirm.js +18 -8
- package/Dialogs/Cron.d.ts +3 -3
- package/Dialogs/Cron.js +21 -17
- package/Dialogs/Error.d.ts +3 -3
- package/Dialogs/Error.js +6 -4
- package/Dialogs/Message.d.ts +3 -3
- package/Dialogs/Message.js +6 -4
- package/Dialogs/SelectFile.d.ts +4 -4
- package/Dialogs/SelectFile.js +6 -4
- package/Dialogs/SelectID.d.ts +12 -10
- package/Dialogs/SelectID.js +12 -8
- package/Dialogs/SimpleCron.d.ts +2 -2
- package/Dialogs/SimpleCron.js +2 -2
- package/Dialogs/TextInput.d.ts +2 -2
- package/Dialogs/TextInput.js +3 -3
- package/GenericApp.d.ts +19 -13
- package/GenericApp.js +128 -85
- package/LegacyConnection.d.ts +240 -248
- package/LegacyConnection.js +500 -525
- package/README.md +1234 -1170
- package/Theme.d.ts +1 -1
- package/Theme.js +9 -12
- package/assets/devices.json +1 -0
- package/assets/rooms.json +1 -0
- package/craco-module-federation.js +3 -12
- package/i18n/de.json +434 -434
- package/i18n/en.json +434 -434
- package/i18n/es.json +434 -434
- package/i18n/fr.json +434 -434
- package/i18n/it.json +434 -434
- package/i18n/nl.json +434 -434
- package/i18n/pl.json +434 -434
- package/i18n/pt.json +434 -434
- package/i18n/ru.json +434 -434
- package/i18n/uk.json +434 -434
- package/i18n/zh-cn.json +434 -434
- package/i18n.d.ts +26 -19
- package/i18n.js +28 -22
- package/icons/IconAdapter.js +2 -2
- package/icons/IconAlias.js +2 -2
- package/icons/IconChannel.js +2 -2
- package/icons/IconClearFilter.js +2 -2
- package/icons/IconClosed.js +2 -2
- package/icons/IconCopy.js +2 -2
- package/icons/IconDevice.js +2 -2
- package/icons/IconDocument.js +2 -2
- package/icons/IconDocumentReadOnly.js +2 -2
- package/icons/IconExpert.js +2 -2
- package/icons/IconFx.js +2 -2
- package/icons/IconInstance.js +2 -2
- package/icons/IconLogout.js +2 -2
- package/icons/IconNoIcon.js +2 -2
- package/icons/IconOpen.d.ts +2 -2
- package/icons/IconOpen.js +2 -2
- package/icons/IconProps.d.ts +4 -3
- package/icons/IconState.d.ts +2 -2
- package/icons/IconState.js +2 -2
- package/index.css +3 -2
- package/package.json +1 -1
- package/src/Components/404.tsx +32 -31
- package/src/Components/ColorPicker.tsx +142 -114
- package/src/Components/ComplexCron.tsx +174 -137
- package/src/Components/CopyToClipboard.tsx +22 -9
- package/src/Components/CustomModal.tsx +76 -69
- package/src/Components/FileBrowser.tsx +959 -852
- package/src/Components/FileViewer.tsx +146 -127
- package/src/Components/Icon.tsx +80 -52
- package/src/Components/IconPicker.tsx +83 -67
- package/src/Components/IconSelector.tsx +159 -141
- package/src/Components/Image.tsx +43 -26
- package/src/Components/Loader.tsx +56 -32
- package/src/Components/Logo.tsx +62 -52
- package/src/Components/MDUtils.tsx +10 -6
- package/src/Components/ObjectBrowser.tsx +3198 -2478
- package/src/Components/Router.tsx +11 -11
- package/src/Components/SaveCloseButtons.tsx +43 -39
- package/src/Components/Schedule.tsx +1091 -853
- package/src/Components/SelectWithIcon.tsx +135 -93
- package/src/Components/TabContainer.tsx +21 -19
- package/src/Components/TabContent.tsx +13 -12
- package/src/Components/TabHeader.tsx +10 -9
- package/src/Components/TableResize.tsx +52 -37
- package/src/Components/TextWithIcon.tsx +30 -19
- package/src/Components/ToggleThemeMenu.tsx +31 -13
- package/src/Components/TreeTable.tsx +468 -385
- package/src/Components/UploadImage.tsx +153 -121
- package/src/Components/Utils.tsx +135 -127
- package/src/Components/loader.css +40 -31
- package/src/Components/withWidth.tsx +23 -12
- package/src/Connection.tsx +1 -3
- package/src/Dialogs/ComplexCron.tsx +55 -61
- package/src/Dialogs/Confirm.tsx +88 -65
- package/src/Dialogs/Cron.tsx +122 -112
- package/src/Dialogs/Error.tsx +37 -42
- package/src/Dialogs/Message.tsx +39 -37
- package/src/Dialogs/SelectFile.tsx +95 -85
- package/src/Dialogs/SelectID.tsx +141 -129
- package/src/Dialogs/SimpleCron.tsx +44 -44
- package/src/Dialogs/TextInput.tsx +60 -68
- package/src/GenericApp.tsx +342 -242
- package/src/LegacyConnection.tsx +972 -842
- package/src/Prompt.tsx +3 -1
- package/src/Theme.tsx +19 -26
- package/src/icons/IconAdapter.tsx +16 -14
- package/src/icons/IconAlias.tsx +16 -14
- package/src/icons/IconChannel.tsx +55 -16
- package/src/icons/IconClearFilter.tsx +17 -15
- package/src/icons/IconClosed.tsx +16 -11
- package/src/icons/IconCopy.tsx +16 -11
- package/src/icons/IconDevice.tsx +121 -22
- package/src/icons/IconDocument.tsx +16 -11
- package/src/icons/IconDocumentReadOnly.tsx +21 -12
- package/src/icons/IconExpert.tsx +20 -12
- package/src/icons/IconFx.tsx +16 -14
- package/src/icons/IconInstance.tsx +16 -14
- package/src/icons/IconLogout.tsx +20 -18
- package/src/icons/IconNoIcon.tsx +16 -14
- package/src/icons/IconOpen.tsx +17 -12
- package/src/icons/IconProps.tsx +4 -3
- package/src/icons/IconState.tsx +34 -13
- package/src/index.css +3 -2
- package/tasks.js +91 -0
- package/types.d.ts +141 -0
- package/Components/Loaders/PT.css +0 -109
- package/Components/Loaders/Vendor.css +0 -13
- package/Components/loader.css +0 -222
- package/Components/types.d.ts +0 -82
- package/assets/devices/Alarm Systems.svg +0 -19
- package/assets/devices/Amplifier.svg +0 -22
- package/assets/devices/Awnings.svg +0 -5
- package/assets/devices/Battery Status.svg +0 -5
- package/assets/devices/Ceiling Spotlights.svg +0 -16
- package/assets/devices/Chandelier.svg +0 -7
- package/assets/devices/Climate.svg +0 -12
- package/assets/devices/Coffee Makers.svg +0 -6
- package/assets/devices/Cold Water.svg +0 -31
- package/assets/devices/Computer.svg +0 -21
- package/assets/devices/Consumption.svg +0 -8
- package/assets/devices/Curtains.svg +0 -43
- package/assets/devices/Dishwashers.svg +0 -12
- package/assets/devices/Doors.svg +0 -6
- package/assets/devices/Doorstep.svg +0 -35
- package/assets/devices/Dryer.svg +0 -14
- package/assets/devices/Fan.svg +0 -20
- package/assets/devices/Floor Lamps.svg +0 -5
- package/assets/devices/Garage Doors.svg +0 -9
- package/assets/devices/Gates.svg +0 -32
- package/assets/devices/Hairdryer.svg +0 -23
- package/assets/devices/Handle.svg +0 -6
- package/assets/devices/Hanging Lamps.svg +0 -9
- package/assets/devices/Heater.svg +0 -44
- package/assets/devices/Hoods.svg +0 -12
- package/assets/devices/Hot Water.svg +0 -10
- package/assets/devices/Humidity.svg +0 -41
- package/assets/devices/Iron.svg +0 -5
- package/assets/devices/Irrigation.svg +0 -23
- package/assets/devices/Led Strip.svg +0 -31
- package/assets/devices/Light.svg +0 -30
- package/assets/devices/Lightings.svg +0 -46
- package/assets/devices/Lock.svg +0 -19
- package/assets/devices/Louvre.svg +0 -7
- package/assets/devices/Mowing Machine.svg +0 -9
- package/assets/devices/Music.svg +0 -13
- package/assets/devices/Outdoor Blinds.svg +0 -7
- package/assets/devices/People.svg +0 -19
- package/assets/devices/Pool.svg +0 -8
- package/assets/devices/Power Consumption.svg +0 -13
- package/assets/devices/Printer.svg +0 -10
- package/assets/devices/Pump.svg +0 -10
- package/assets/devices/Receiver.svg +0 -19
- package/assets/devices/Sconces.svg +0 -10
- package/assets/devices/Security.svg +0 -34
- package/assets/devices/Shading.svg +0 -5
- package/assets/devices/Shutters.svg +0 -11
- package/assets/devices/SmokeDetector.svg +0 -13
- package/assets/devices/Sockets.svg +0 -13
- package/assets/devices/Speaker.svg +0 -35
- package/assets/devices/Stove.svg +0 -12
- package/assets/devices/Table Lamps.svg +0 -12
- package/assets/devices/Temperature Sensors.svg +0 -28
- package/assets/devices/Tv.svg +0 -8
- package/assets/devices/Vacuum Cleaner.svg +0 -16
- package/assets/devices/Ventilation.svg +0 -12
- package/assets/devices/Washing Machines.svg +0 -16
- package/assets/devices/Water Consumption.svg +0 -6
- package/assets/devices/Water Heater.svg +0 -8
- package/assets/devices/Water.svg +0 -40
- package/assets/devices/Weather.svg +0 -28
- package/assets/devices/Window.svg +0 -8
- package/assets/rooms/Anteroom.svg +0 -53
- package/assets/rooms/Attic.svg +0 -21
- package/assets/rooms/Balcony.svg +0 -13
- package/assets/rooms/Barn.svg +0 -6
- package/assets/rooms/Basement.svg +0 -5
- package/assets/rooms/Bathroom.svg +0 -38
- package/assets/rooms/Bedroom.svg +0 -5
- package/assets/rooms/Boiler Room.svg +0 -13
- package/assets/rooms/Carport.svg +0 -17
- package/assets/rooms/Cellar.svg +0 -89
- package/assets/rooms/Chamber.svg +0 -9
- package/assets/rooms/Corridor.svg +0 -53
- package/assets/rooms/Dining Area.svg +0 -37
- package/assets/rooms/Dining Room.svg +0 -37
- package/assets/rooms/Dining.svg +0 -37
- package/assets/rooms/Dressing Room.svg +0 -5
- package/assets/rooms/Driveway.svg +0 -15
- package/assets/rooms/Entrance.svg +0 -44
- package/assets/rooms/Equipment Room.svg +0 -15
- package/assets/rooms/Front Yard.svg +0 -64
- package/assets/rooms/Gallery.svg +0 -14
- package/assets/rooms/Garage.svg +0 -20
- package/assets/rooms/Garden.svg +0 -13
- package/assets/rooms/Ground Floor.svg +0 -95
- package/assets/rooms/Guest Bathroom.svg +0 -33
- package/assets/rooms/Guest Room.svg +0 -5
- package/assets/rooms/Gym.svg +0 -5
- package/assets/rooms/Hall.svg +0 -19
- package/assets/rooms/Home Theater.svg +0 -8
- package/assets/rooms/Kitchen.svg +0 -18
- package/assets/rooms/Laundry Room.svg +0 -12
- package/assets/rooms/Living Area.svg +0 -11
- package/assets/rooms/Living Room.svg +0 -10
- package/assets/rooms/Locker Room.svg +0 -17
- package/assets/rooms/Nursery.svg +0 -5
- package/assets/rooms/Office.svg +0 -8
- package/assets/rooms/Outdoors.svg +0 -7
- package/assets/rooms/Playroom.svg +0 -6
- package/assets/rooms/Pool.svg +0 -8
- package/assets/rooms/Rear Wall.svg +0 -30
- package/assets/rooms/Second Floor.svg +0 -95
- package/assets/rooms/Shed.svg +0 -16
- package/assets/rooms/Sleeping Area.svg +0 -22
- package/assets/rooms/Stairway.svg +0 -5
- package/assets/rooms/Stairwell.svg +0 -15
- package/assets/rooms/Storeroom.svg +0 -5
- package/assets/rooms/Summer House.svg +0 -27
- package/assets/rooms/Swimming Pool.svg +0 -21
- package/assets/rooms/Terrace.svg +0 -7
- package/assets/rooms/Toilet.svg +0 -10
- package/assets/rooms/Upstairs.svg +0 -6
- package/assets/rooms/Wardrobe.svg +0 -60
- package/assets/rooms/Washroom.svg +0 -20
- package/assets/rooms/Wc.svg +0 -10
- package/assets/rooms/Windscreen.svg +0 -60
- package/assets/rooms/Workshop.svg +0 -23
- package/assets/rooms/Workspace.svg +0 -8
package/LegacyConnection.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* MIT License
|
|
6
6
|
*
|
|
7
|
-
|
|
7
|
+
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.ERRORS = exports.PROGRESS = void 0;
|
|
10
10
|
exports.pattern2RegEx = pattern2RegEx;
|
|
@@ -82,7 +82,11 @@ function fixAdminUI(obj) {
|
|
|
82
82
|
obj.common.adminUI.tab = 'html';
|
|
83
83
|
}
|
|
84
84
|
// @ts-expect-error it is deprecated, but still could appear
|
|
85
|
-
obj.common.adminUI
|
|
85
|
+
if (obj.common.adminUI) {
|
|
86
|
+
console.debug(
|
|
87
|
+
// @ts-expect-error it is deprecated, but still could appear
|
|
88
|
+
`Please add to "${obj._id.replace(/\.\d+$/, '')}" common.adminUI=${JSON.stringify(obj.common.adminUI)}`);
|
|
89
|
+
}
|
|
86
90
|
}
|
|
87
91
|
return obj;
|
|
88
92
|
}
|
|
@@ -91,9 +95,7 @@ function pattern2RegEx(pattern) {
|
|
|
91
95
|
pattern = (pattern || '').toString();
|
|
92
96
|
const startsWithWildcard = pattern[0] === '*';
|
|
93
97
|
const endsWithWildcard = pattern[pattern.length - 1] === '*';
|
|
94
|
-
pattern = pattern
|
|
95
|
-
.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&')
|
|
96
|
-
.replace(/\*/g, '.*');
|
|
98
|
+
pattern = pattern.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&').replace(/\*/g, '.*');
|
|
97
99
|
return (startsWithWildcard ? '' : '^') + pattern + (endsWithWildcard ? '' : '$');
|
|
98
100
|
}
|
|
99
101
|
class Connection {
|
|
@@ -124,7 +126,9 @@ class Connection {
|
|
|
124
126
|
this.autoSubscribeLog = this.props.autoSubscribeLog || false;
|
|
125
127
|
this.props.protocol = this.props.protocol || window.location.protocol;
|
|
126
128
|
this.props.host = this.props.host || window.location.hostname;
|
|
127
|
-
this.props.port =
|
|
129
|
+
this.props.port =
|
|
130
|
+
this.props.port ||
|
|
131
|
+
(window.location.port === '3000' ? (Connection.isWeb() ? 8082 : 8081) : window.location.port);
|
|
128
132
|
this.props.ioTimeout = Math.max(this.props.ioTimeout || 20000, 20000);
|
|
129
133
|
this.props.cmdTimeout = Math.max(this.props.cmdTimeout || 5000, 5000);
|
|
130
134
|
this._instanceSubscriptions = {};
|
|
@@ -136,21 +140,24 @@ class Connection {
|
|
|
136
140
|
this._waitForFirstConnectionResolve = resolve;
|
|
137
141
|
});
|
|
138
142
|
this.onProgress = this.props.onProgress || (() => { });
|
|
139
|
-
this.onError =
|
|
143
|
+
this.onError =
|
|
144
|
+
this.props.onError ||
|
|
145
|
+
((err) => console.error(err));
|
|
140
146
|
this.admin5only = this.props.admin5only || false;
|
|
141
147
|
this.startSocket();
|
|
142
148
|
}
|
|
143
149
|
/**
|
|
144
150
|
* Checks if this connection is running in a web adapter and not in an admin.
|
|
145
|
-
*
|
|
151
|
+
*
|
|
152
|
+
* @returns True if running in a web adapter or in a socketio adapter.
|
|
146
153
|
*/
|
|
147
154
|
static isWeb() {
|
|
148
155
|
const adapterName = window.adapterName;
|
|
149
|
-
return adapterName === 'material' ||
|
|
156
|
+
return (adapterName === 'material' ||
|
|
150
157
|
adapterName === 'vis' ||
|
|
151
158
|
(adapterName === null || adapterName === void 0 ? void 0 : adapterName.startsWith('vis-')) ||
|
|
152
159
|
adapterName === 'echarts-show' ||
|
|
153
|
-
window.socketUrl !== undefined;
|
|
160
|
+
window.socketUrl !== undefined);
|
|
154
161
|
}
|
|
155
162
|
/**
|
|
156
163
|
* Starts the socket.io connection.
|
|
@@ -184,8 +191,7 @@ class Connection {
|
|
|
184
191
|
let port = this.props.port;
|
|
185
192
|
let protocol = this.props.protocol.replace(':', '');
|
|
186
193
|
let path = window.location.pathname;
|
|
187
|
-
if (window.location.hostname === 'iobroker.net' ||
|
|
188
|
-
window.location.hostname === 'iobroker.pro') {
|
|
194
|
+
if (window.location.hostname === 'iobroker.net' || window.location.hostname === 'iobroker.pro') {
|
|
189
195
|
path = '';
|
|
190
196
|
}
|
|
191
197
|
else {
|
|
@@ -229,8 +235,7 @@ class Connection {
|
|
|
229
235
|
this._socket.on('connect', (noTimeout) => {
|
|
230
236
|
// If the user is not admin, it takes some time to install the handlers, because all rights must be checked
|
|
231
237
|
if (noTimeout !== true) {
|
|
232
|
-
setTimeout(() => this.getVersion()
|
|
233
|
-
.then(info => {
|
|
238
|
+
setTimeout(() => this.getVersion().then(info => {
|
|
234
239
|
const [major, minor, patch] = info.version.split('.');
|
|
235
240
|
const v = parseInt(major, 10) * 10000 + parseInt(minor, 10) * 100 + parseInt(patch, 10);
|
|
236
241
|
if (v < 40102) {
|
|
@@ -302,7 +307,7 @@ class Connection {
|
|
|
302
307
|
/**
|
|
303
308
|
* Called internally.
|
|
304
309
|
*/
|
|
305
|
-
onPreConnect(
|
|
310
|
+
onPreConnect(_isOk, isSecure) {
|
|
306
311
|
if (this._authTimer) {
|
|
307
312
|
clearTimeout(this._authTimer);
|
|
308
313
|
this._authTimer = null;
|
|
@@ -319,11 +324,11 @@ class Connection {
|
|
|
319
324
|
this.loadTimer = null;
|
|
320
325
|
this.loadCounter++;
|
|
321
326
|
if (this.loadCounter < 10) {
|
|
322
|
-
this.onConnect();
|
|
327
|
+
void this.onConnect().catch(e => this.onError(e));
|
|
323
328
|
}
|
|
324
329
|
}, 1000);
|
|
325
330
|
if (!this.loaded) {
|
|
326
|
-
this.onConnect();
|
|
331
|
+
void this.onConnect().catch(e => this.onError(e));
|
|
327
332
|
}
|
|
328
333
|
}
|
|
329
334
|
else {
|
|
@@ -341,15 +346,13 @@ class Connection {
|
|
|
341
346
|
* Checks if running in ioBroker cloud
|
|
342
347
|
*/
|
|
343
348
|
static isCloud() {
|
|
344
|
-
if (window.location.hostname.includes('amazonaws.com') ||
|
|
345
|
-
window.location.hostname.includes('iobroker.in')) {
|
|
349
|
+
if (window.location.hostname.includes('amazonaws.com') || window.location.hostname.includes('iobroker.in')) {
|
|
346
350
|
return true;
|
|
347
351
|
}
|
|
348
352
|
if (typeof window.socketUrl === 'undefined') {
|
|
349
353
|
return false;
|
|
350
354
|
}
|
|
351
|
-
return
|
|
352
|
-
window.socketUrl.includes('amazonaws'));
|
|
355
|
+
return window.socketUrl.includes('iobroker.in') || window.socketUrl.includes('amazonaws');
|
|
353
356
|
}
|
|
354
357
|
/**
|
|
355
358
|
* Checks if the socket is connected.
|
|
@@ -372,7 +375,7 @@ class Connection {
|
|
|
372
375
|
return null;
|
|
373
376
|
}
|
|
374
377
|
return new Promise((resolve, reject) => {
|
|
375
|
-
this._socket.emit('getUserPermissions', (err, acl) =>
|
|
378
|
+
this._socket.emit('getUserPermissions', (err, acl) => err ? reject(new Error(err)) : resolve(acl));
|
|
376
379
|
});
|
|
377
380
|
}
|
|
378
381
|
/**
|
|
@@ -383,8 +386,9 @@ class Connection {
|
|
|
383
386
|
try {
|
|
384
387
|
acl = await this._getUserPermissions();
|
|
385
388
|
}
|
|
386
|
-
catch (
|
|
387
|
-
|
|
389
|
+
catch (e) {
|
|
390
|
+
const knownError = e;
|
|
391
|
+
this.onError(`Cannot read user permissions: ${knownError.message}`);
|
|
388
392
|
return;
|
|
389
393
|
}
|
|
390
394
|
if (!this.doNotLoadACL) {
|
|
@@ -449,7 +453,6 @@ class Connection {
|
|
|
449
453
|
}
|
|
450
454
|
/**
|
|
451
455
|
* Called internally.
|
|
452
|
-
* @private
|
|
453
456
|
*/
|
|
454
457
|
static authenticate() {
|
|
455
458
|
if (window.location.search.includes('&href=')) {
|
|
@@ -461,14 +464,12 @@ class Connection {
|
|
|
461
464
|
}
|
|
462
465
|
/**
|
|
463
466
|
* Subscribe to changes of the given state.
|
|
467
|
+
*
|
|
468
|
+
* @param id The ioBroker state ID or array of states
|
|
469
|
+
* @param binary Set to true if the given state is binary and requires Base64 decoding
|
|
470
|
+
* @param cb The callback
|
|
464
471
|
*/
|
|
465
|
-
subscribeState(
|
|
466
|
-
/** The ioBroker state ID. */
|
|
467
|
-
id,
|
|
468
|
-
/** Set to true if the given state is binary and requires Base64 decoding. */
|
|
469
|
-
binary,
|
|
470
|
-
/** The callback. */
|
|
471
|
-
cb) {
|
|
472
|
+
subscribeState(id, binary, cb) {
|
|
472
473
|
if (typeof binary === 'function') {
|
|
473
474
|
cb = binary;
|
|
474
475
|
binary = false;
|
|
@@ -504,8 +505,7 @@ class Connection {
|
|
|
504
505
|
}
|
|
505
506
|
}
|
|
506
507
|
else {
|
|
507
|
-
!this.statesSubscribes[_id].cbs.includes(cb) &&
|
|
508
|
-
this.statesSubscribes[_id].cbs.push(cb);
|
|
508
|
+
!this.statesSubscribes[_id].cbs.includes(cb) && this.statesSubscribes[_id].cbs.push(cb);
|
|
509
509
|
}
|
|
510
510
|
}
|
|
511
511
|
if (!this.connected) {
|
|
@@ -578,7 +578,9 @@ class Connection {
|
|
|
578
578
|
this._socket.emit(Connection.isWeb() ? 'getStates' : 'getForeignStates', id, (err, states) => {
|
|
579
579
|
err && console.error(`Cannot getForeignStates "${id}": ${JSON.stringify(err)}`);
|
|
580
580
|
states && Object.keys(states).forEach(_id => cb(_id, states[_id]));
|
|
581
|
-
states
|
|
581
|
+
states
|
|
582
|
+
? resolve()
|
|
583
|
+
: reject(new Error(`Cannot getForeignStates "${id}": ${JSON.stringify(err)}`));
|
|
582
584
|
});
|
|
583
585
|
}
|
|
584
586
|
else {
|
|
@@ -627,12 +629,11 @@ class Connection {
|
|
|
627
629
|
}
|
|
628
630
|
/**
|
|
629
631
|
* Subscribe to changes of the given object.
|
|
632
|
+
*
|
|
633
|
+
* @param id The ioBroker object ID or array of objects
|
|
634
|
+
* @param cb The callback
|
|
630
635
|
*/
|
|
631
|
-
subscribeObject(
|
|
632
|
-
/** The ioBroker object ID. */
|
|
633
|
-
id,
|
|
634
|
-
/** The callback. */
|
|
635
|
-
cb) {
|
|
636
|
+
subscribeObject(id, cb) {
|
|
636
637
|
let ids;
|
|
637
638
|
if (!Array.isArray(id)) {
|
|
638
639
|
ids = [id];
|
|
@@ -652,8 +653,7 @@ class Connection {
|
|
|
652
653
|
toSubscribe.push(_id);
|
|
653
654
|
}
|
|
654
655
|
else {
|
|
655
|
-
!this.objectsSubscribes[_id].cbs.includes(cb) &&
|
|
656
|
-
this.objectsSubscribes[_id].cbs.push(cb);
|
|
656
|
+
!this.objectsSubscribes[_id].cbs.includes(cb) && this.objectsSubscribes[_id].cbs.push(cb);
|
|
657
657
|
}
|
|
658
658
|
}
|
|
659
659
|
if (this.connected && toSubscribe.length) {
|
|
@@ -663,12 +663,11 @@ class Connection {
|
|
|
663
663
|
}
|
|
664
664
|
/**
|
|
665
665
|
* Unsubscribes all or the given callback from changes of the given object.
|
|
666
|
+
*
|
|
667
|
+
* @param id The ioBroker object ID or array of objects
|
|
668
|
+
* @param cb The callback
|
|
666
669
|
*/
|
|
667
|
-
unsubscribeObject(
|
|
668
|
-
/** The ioBroker object ID. */
|
|
669
|
-
id,
|
|
670
|
-
/** The callback. */
|
|
671
|
-
cb) {
|
|
670
|
+
unsubscribeObject(id, cb) {
|
|
672
671
|
let ids;
|
|
673
672
|
if (!Array.isArray(id)) {
|
|
674
673
|
ids = [id];
|
|
@@ -717,9 +716,10 @@ class Connection {
|
|
|
717
716
|
}
|
|
718
717
|
/**
|
|
719
718
|
* Subscribe to changes of the files.
|
|
720
|
-
*
|
|
721
|
-
* @param
|
|
722
|
-
* @param
|
|
719
|
+
*
|
|
720
|
+
* @param id The ioBroker state ID for meta-object. Could be a pattern
|
|
721
|
+
* @param filePattern Pattern or file name, like 'main/*' or 'main/visViews.json`
|
|
722
|
+
* @param cb The callback.
|
|
723
723
|
*/
|
|
724
724
|
async subscribeFiles(
|
|
725
725
|
/** The ioBroker state ID for meta-object. Could be a pattern */
|
|
@@ -751,19 +751,20 @@ class Connection {
|
|
|
751
751
|
toSubscribe.push(pattern);
|
|
752
752
|
}
|
|
753
753
|
else {
|
|
754
|
-
!this.filesSubscribes[key].cbs.includes(cb) &&
|
|
755
|
-
this.filesSubscribes[key].cbs.push(cb);
|
|
754
|
+
!this.filesSubscribes[key].cbs.includes(cb) && this.filesSubscribes[key].cbs.push(cb);
|
|
756
755
|
}
|
|
757
756
|
}
|
|
758
757
|
if (this.connected && toSubscribe.length) {
|
|
759
758
|
this._socket.emit('subscribeFiles', id, toSubscribe);
|
|
760
759
|
}
|
|
760
|
+
return Promise.resolve();
|
|
761
761
|
}
|
|
762
762
|
/**
|
|
763
763
|
* Unsubscribes the given callback from changes of files.
|
|
764
|
-
*
|
|
765
|
-
* @param
|
|
766
|
-
* @param
|
|
764
|
+
*
|
|
765
|
+
* @param id The ioBroker state ID.
|
|
766
|
+
* @param filePattern Pattern or file name, like 'main/*' or 'main/visViews.json`
|
|
767
|
+
* @param cb The callback.
|
|
767
768
|
*/
|
|
768
769
|
unsubscribeFiles(id, filePattern, cb) {
|
|
769
770
|
let filePatterns;
|
|
@@ -788,8 +789,7 @@ class Connection {
|
|
|
788
789
|
}
|
|
789
790
|
if (!sub.cbs || !sub.cbs.length) {
|
|
790
791
|
delete this.filesSubscribes[key];
|
|
791
|
-
this.connected &&
|
|
792
|
-
toUnsubscribe.push(pattern);
|
|
792
|
+
this.connected && toUnsubscribe.push(pattern);
|
|
793
793
|
}
|
|
794
794
|
}
|
|
795
795
|
}
|
|
@@ -836,7 +836,7 @@ class Connection {
|
|
|
836
836
|
}
|
|
837
837
|
});
|
|
838
838
|
if (changed && this.props.onObjectChange) {
|
|
839
|
-
this.props.onObjectChange(id, obj);
|
|
839
|
+
void this.props.onObjectChange(id, obj);
|
|
840
840
|
}
|
|
841
841
|
}
|
|
842
842
|
/**
|
|
@@ -844,13 +844,15 @@ class Connection {
|
|
|
844
844
|
*/
|
|
845
845
|
stateChange(id, state) {
|
|
846
846
|
for (const task in this.statesSubscribes) {
|
|
847
|
-
if (Object.prototype.hasOwnProperty.call(this.statesSubscribes, task) &&
|
|
847
|
+
if (Object.prototype.hasOwnProperty.call(this.statesSubscribes, task) &&
|
|
848
|
+
this.statesSubscribes[task].reg.test(id)) {
|
|
848
849
|
this.statesSubscribes[task].cbs.forEach(cb => {
|
|
849
850
|
try {
|
|
850
|
-
cb(id, state);
|
|
851
|
+
void cb(id, state);
|
|
851
852
|
}
|
|
852
853
|
catch (e) {
|
|
853
|
-
|
|
854
|
+
const knownError = e;
|
|
855
|
+
console.error(`Error by callback of stateChange: ${knownError === null || knownError === void 0 ? void 0 : knownError.message}`);
|
|
854
856
|
}
|
|
855
857
|
});
|
|
856
858
|
}
|
|
@@ -858,9 +860,10 @@ class Connection {
|
|
|
858
860
|
}
|
|
859
861
|
/**
|
|
860
862
|
* Called internally.
|
|
861
|
-
*
|
|
862
|
-
* @param
|
|
863
|
-
* @param
|
|
863
|
+
*
|
|
864
|
+
* @param messageType The message type
|
|
865
|
+
* @param sourceInstance The source instance
|
|
866
|
+
* @param data Payload
|
|
864
867
|
*/
|
|
865
868
|
instanceMessage(messageType, sourceInstance, data) {
|
|
866
869
|
if (this._instanceSubscriptions[sourceInstance]) {
|
|
@@ -873,14 +876,13 @@ class Connection {
|
|
|
873
876
|
}
|
|
874
877
|
/**
|
|
875
878
|
* Gets all states.
|
|
879
|
+
*
|
|
880
|
+
* @param pattern The pattern to filter states
|
|
881
|
+
* @param disableProgressUpdate Don't call onProgress() when done
|
|
876
882
|
*/
|
|
877
|
-
getStates(
|
|
878
|
-
/** The pattern to filter states. */
|
|
879
|
-
pattern,
|
|
880
|
-
/** don't call onProgress() when done */
|
|
881
|
-
disableProgressUpdate) {
|
|
883
|
+
getStates(pattern, disableProgressUpdate) {
|
|
882
884
|
if (!this.connected) {
|
|
883
|
-
return Promise.reject(NOT_CONNECTED);
|
|
885
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
884
886
|
}
|
|
885
887
|
if (typeof pattern === 'boolean') {
|
|
886
888
|
disableProgressUpdate = pattern;
|
|
@@ -890,70 +892,67 @@ class Connection {
|
|
|
890
892
|
this._socket.emit('getStates', pattern, (err, res) => {
|
|
891
893
|
this.states = res;
|
|
892
894
|
!disableProgressUpdate && this.onProgress(exports.PROGRESS.STATES_LOADED);
|
|
893
|
-
err ? reject(err) : resolve(this.states);
|
|
895
|
+
err ? reject(new Error(err)) : resolve(this.states);
|
|
894
896
|
});
|
|
895
897
|
});
|
|
896
898
|
}
|
|
897
899
|
/**
|
|
898
900
|
* Gets the given state.
|
|
901
|
+
*
|
|
902
|
+
* @param id The state ID
|
|
899
903
|
*/
|
|
900
|
-
getState(
|
|
901
|
-
/** The state ID. */
|
|
902
|
-
id) {
|
|
904
|
+
getState(id) {
|
|
903
905
|
if (!this.connected) {
|
|
904
|
-
return Promise.reject(NOT_CONNECTED);
|
|
906
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
905
907
|
}
|
|
906
908
|
if (id && id === this.ignoreState) {
|
|
907
909
|
return Promise.resolve(this.simStates[id] || { val: null, ack: true });
|
|
908
910
|
}
|
|
909
911
|
return new Promise((resolve, reject) => {
|
|
910
|
-
this._socket.emit('getState', id, (err, state) =>
|
|
912
|
+
this._socket.emit('getState', id, (err, state) => err ? reject(new Error(err)) : resolve(state));
|
|
911
913
|
});
|
|
912
914
|
}
|
|
913
915
|
/**
|
|
914
|
-
* @deprecated since js-controller 5.0. Use files instead.
|
|
915
916
|
* Get the given binary state.
|
|
917
|
+
*
|
|
918
|
+
* @deprecated since js-controller 5.0. Use files instead.
|
|
919
|
+
* @param id The state ID.
|
|
916
920
|
*/
|
|
917
|
-
getBinaryState(
|
|
918
|
-
/** The state ID. */
|
|
919
|
-
id) {
|
|
921
|
+
getBinaryState(id) {
|
|
920
922
|
if (!this.connected) {
|
|
921
|
-
return Promise.reject(NOT_CONNECTED);
|
|
923
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
922
924
|
}
|
|
923
925
|
// the data will come in base64
|
|
924
926
|
return new Promise((resolve, reject) => {
|
|
925
|
-
this._socket.emit('getBinaryState', id, (err, base64) =>
|
|
927
|
+
this._socket.emit('getBinaryState', id, (err, base64) => err ? reject(new Error(err)) : resolve(base64));
|
|
926
928
|
});
|
|
927
929
|
}
|
|
928
930
|
/**
|
|
929
|
-
* @deprecated since js-controller 5.0. Use files instead.
|
|
930
931
|
* Set the given binary state.
|
|
932
|
+
*
|
|
933
|
+
* @deprecated since js-controller 5.0. Use files instead.
|
|
934
|
+
* @param id The state ID.
|
|
935
|
+
* @param base64 The Base64 encoded binary data.
|
|
931
936
|
*/
|
|
932
|
-
setBinaryState(
|
|
933
|
-
/** The state ID. */
|
|
934
|
-
id,
|
|
935
|
-
/** The Base64 encoded binary data. */
|
|
936
|
-
base64) {
|
|
937
|
+
setBinaryState(id, base64) {
|
|
937
938
|
if (!this.connected) {
|
|
938
|
-
return Promise.reject(NOT_CONNECTED);
|
|
939
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
939
940
|
}
|
|
940
941
|
// the data will come in base64
|
|
941
942
|
return new Promise((resolve, reject) => {
|
|
942
|
-
this._socket.emit('setBinaryState', id, base64, (err) =>
|
|
943
|
+
this._socket.emit('setBinaryState', id, base64, (err) => err ? reject(new Error(err)) : resolve());
|
|
943
944
|
});
|
|
944
945
|
}
|
|
945
946
|
/**
|
|
946
947
|
* Sets the given state value.
|
|
948
|
+
*
|
|
949
|
+
* @param id The state ID
|
|
950
|
+
* @param val The state value
|
|
951
|
+
* @param ack The acknowledgment flag
|
|
947
952
|
*/
|
|
948
|
-
setState(
|
|
949
|
-
/** The state ID. */
|
|
950
|
-
id,
|
|
951
|
-
/** The state value. */
|
|
952
|
-
val,
|
|
953
|
-
/** The acknowledgment flag. */
|
|
954
|
-
ack) {
|
|
953
|
+
setState(id, val, ack) {
|
|
955
954
|
if (!this.connected) {
|
|
956
|
-
return Promise.reject(NOT_CONNECTED);
|
|
955
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
957
956
|
}
|
|
958
957
|
// extra handling for "nothing_selected" state for vis
|
|
959
958
|
if (id && id === this.ignoreState) {
|
|
@@ -978,7 +977,7 @@ class Connection {
|
|
|
978
977
|
if (this.statesSubscribes[id]) {
|
|
979
978
|
for (const cb of this.statesSubscribes[id].cbs) {
|
|
980
979
|
try {
|
|
981
|
-
cb(id, state);
|
|
980
|
+
void cb(id, state);
|
|
982
981
|
}
|
|
983
982
|
catch (e) {
|
|
984
983
|
console.error(`Error by callback of stateChanged: ${e}`);
|
|
@@ -988,19 +987,18 @@ class Connection {
|
|
|
988
987
|
return Promise.resolve();
|
|
989
988
|
}
|
|
990
989
|
return new Promise((resolve, reject) => {
|
|
991
|
-
this._socket.emit('setState', id, val, (err) => (err ? reject(err) : resolve()));
|
|
990
|
+
this._socket.emit('setState', id, val, (err) => (err ? reject(new Error(err)) : resolve()));
|
|
992
991
|
});
|
|
993
992
|
}
|
|
994
993
|
/**
|
|
995
994
|
* Gets all objects.
|
|
995
|
+
*
|
|
996
|
+
* @param update Set to true to retrieve all objects from the server (instead of using the local cache)
|
|
997
|
+
* @param disableProgressUpdate Don't call onProgress() when done
|
|
996
998
|
*/
|
|
997
|
-
getObjects(
|
|
998
|
-
/** Set to true to retrieve all objects from the server (instead of using the local cache). */
|
|
999
|
-
update,
|
|
1000
|
-
/** don't call onProgress() when done */
|
|
1001
|
-
disableProgressUpdate) {
|
|
999
|
+
getObjects(update, disableProgressUpdate) {
|
|
1002
1000
|
if (!this.connected) {
|
|
1003
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1001
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1004
1002
|
}
|
|
1005
1003
|
return new Promise((resolve, reject) => {
|
|
1006
1004
|
if (!update && this.objects) {
|
|
@@ -1010,22 +1008,22 @@ class Connection {
|
|
|
1010
1008
|
this._socket.emit(Connection.isWeb() ? 'getObjects' : 'getAllObjects', (err, res) => {
|
|
1011
1009
|
this.objects = res;
|
|
1012
1010
|
disableProgressUpdate && this.onProgress(exports.PROGRESS.OBJECTS_LOADED);
|
|
1013
|
-
err ? reject(err) : resolve(this.objects);
|
|
1011
|
+
err ? reject(new Error(err)) : resolve(this.objects);
|
|
1014
1012
|
});
|
|
1015
1013
|
}
|
|
1016
1014
|
});
|
|
1017
1015
|
}
|
|
1018
1016
|
/**
|
|
1019
1017
|
* Gets objects by list of IDs.
|
|
1018
|
+
*
|
|
1019
|
+
* @param list Array of object IDs to retrieve
|
|
1020
1020
|
*/
|
|
1021
|
-
getObjectsById(
|
|
1022
|
-
/** Array of object IDs to retrieve. */
|
|
1023
|
-
list) {
|
|
1021
|
+
getObjectsById(list) {
|
|
1024
1022
|
if (!this.connected) {
|
|
1025
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1023
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1026
1024
|
}
|
|
1027
1025
|
return new Promise((resolve, reject) => {
|
|
1028
|
-
this._socket.emit('getObjects', list, (err, res) =>
|
|
1026
|
+
this._socket.emit('getObjects', list, (err, res) => err ? reject(new Error(err)) : resolve(res));
|
|
1029
1027
|
});
|
|
1030
1028
|
}
|
|
1031
1029
|
/**
|
|
@@ -1042,11 +1040,12 @@ class Connection {
|
|
|
1042
1040
|
// re-subscribe states
|
|
1043
1041
|
const ids = Object.keys(this.statesSubscribes);
|
|
1044
1042
|
ids.forEach(id => this._socket.emit('subscribe', id));
|
|
1045
|
-
ids.length &&
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1043
|
+
ids.length &&
|
|
1044
|
+
this._socket.emit(Connection.isWeb() ? 'getStates' : 'getForeignStates', ids, (err, states) => {
|
|
1045
|
+
err && console.error(`Cannot getForeignStates: ${JSON.stringify(err)}`);
|
|
1046
|
+
// inform about states
|
|
1047
|
+
states && Object.keys(states).forEach(id => this.stateChange(id, states[id]));
|
|
1048
|
+
});
|
|
1050
1049
|
}
|
|
1051
1050
|
else if (!isEnable && this.subscribed) {
|
|
1052
1051
|
this.subscribed = false;
|
|
@@ -1061,45 +1060,43 @@ class Connection {
|
|
|
1061
1060
|
}
|
|
1062
1061
|
/**
|
|
1063
1062
|
* Requests log updates.
|
|
1063
|
+
*
|
|
1064
|
+
* @param isEnabled Set to true to get logs
|
|
1064
1065
|
*/
|
|
1065
|
-
requireLog(
|
|
1066
|
-
/** Set to true to get logs. */
|
|
1067
|
-
isEnabled) {
|
|
1066
|
+
requireLog(isEnabled) {
|
|
1068
1067
|
if (!this.connected) {
|
|
1069
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1068
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1070
1069
|
}
|
|
1071
1070
|
return new Promise((resolve, reject) => {
|
|
1072
|
-
this._socket.emit('requireLog', isEnabled, (err) =>
|
|
1071
|
+
this._socket.emit('requireLog', isEnabled, (err) => err ? reject(new Error(err)) : resolve());
|
|
1073
1072
|
});
|
|
1074
1073
|
}
|
|
1075
1074
|
/**
|
|
1076
1075
|
* Deletes the given object.
|
|
1076
|
+
*
|
|
1077
|
+
* @param id The object ID
|
|
1078
|
+
* @param maintenance Force deletion of non-conform IDs
|
|
1077
1079
|
*/
|
|
1078
|
-
delObject(
|
|
1079
|
-
/** The object ID. */
|
|
1080
|
-
id,
|
|
1081
|
-
/** Force deletion of non-conform IDs. */
|
|
1082
|
-
maintenance) {
|
|
1080
|
+
delObject(id, maintenance) {
|
|
1083
1081
|
if (!this.connected) {
|
|
1084
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1082
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1085
1083
|
}
|
|
1086
1084
|
return new Promise((resolve, reject) => {
|
|
1087
|
-
this._socket.emit('delObject', id, { maintenance: !!maintenance }, (err) =>
|
|
1085
|
+
this._socket.emit('delObject', id, { maintenance: !!maintenance }, (err) => err ? reject(new Error(err)) : resolve());
|
|
1088
1086
|
});
|
|
1089
1087
|
}
|
|
1090
1088
|
/**
|
|
1091
1089
|
* Deletes the given object and all its children.
|
|
1090
|
+
*
|
|
1091
|
+
* @param id The object ID
|
|
1092
|
+
* @param maintenance Force deletion of non-conform IDs
|
|
1092
1093
|
*/
|
|
1093
|
-
delObjects(
|
|
1094
|
-
/** The object ID. */
|
|
1095
|
-
id,
|
|
1096
|
-
/** Force deletion of non-conform IDs. */
|
|
1097
|
-
maintenance) {
|
|
1094
|
+
delObjects(id, maintenance) {
|
|
1098
1095
|
if (!this.connected) {
|
|
1099
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1096
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1100
1097
|
}
|
|
1101
1098
|
return new Promise((resolve, reject) => {
|
|
1102
|
-
this._socket.emit('delObjects', id, { maintenance: !!maintenance }, (err) =>
|
|
1099
|
+
this._socket.emit('delObjects', id, { maintenance: !!maintenance }, (err) => err ? reject(new Error(err)) : resolve());
|
|
1103
1100
|
});
|
|
1104
1101
|
}
|
|
1105
1102
|
/**
|
|
@@ -1107,10 +1104,10 @@ class Connection {
|
|
|
1107
1104
|
*/
|
|
1108
1105
|
setObject(id, obj) {
|
|
1109
1106
|
if (!this.connected) {
|
|
1110
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1107
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1111
1108
|
}
|
|
1112
1109
|
if (!obj) {
|
|
1113
|
-
return Promise.reject('Null object is not allowed');
|
|
1110
|
+
return Promise.reject(new Error('Null object is not allowed'));
|
|
1114
1111
|
}
|
|
1115
1112
|
obj = JSON.parse(JSON.stringify(obj));
|
|
1116
1113
|
if (Object.prototype.hasOwnProperty.call(obj, 'from')) {
|
|
@@ -1123,7 +1120,7 @@ class Connection {
|
|
|
1123
1120
|
delete obj.ts;
|
|
1124
1121
|
}
|
|
1125
1122
|
return new Promise((resolve, reject) => {
|
|
1126
|
-
this._socket.emit('setObject', id, obj, (err) => (err ? reject(err) : resolve()));
|
|
1123
|
+
this._socket.emit('setObject', id, obj, (err) => (err ? reject(new Error(err)) : resolve()));
|
|
1127
1124
|
});
|
|
1128
1125
|
}
|
|
1129
1126
|
/**
|
|
@@ -1131,7 +1128,7 @@ class Connection {
|
|
|
1131
1128
|
*/
|
|
1132
1129
|
getObject(id) {
|
|
1133
1130
|
if (!this.connected) {
|
|
1134
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1131
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1135
1132
|
}
|
|
1136
1133
|
if (id && id === this.ignoreState) {
|
|
1137
1134
|
return Promise.resolve({
|
|
@@ -1148,17 +1145,16 @@ class Connection {
|
|
|
1148
1145
|
});
|
|
1149
1146
|
}
|
|
1150
1147
|
return new Promise((resolve, reject) => {
|
|
1151
|
-
this._socket.emit('getObject', id, (err, obj) =>
|
|
1148
|
+
this._socket.emit('getObject', id, (err, obj) => err ? reject(new Error(err)) : resolve(obj));
|
|
1152
1149
|
});
|
|
1153
1150
|
}
|
|
1154
1151
|
/**
|
|
1155
1152
|
* Get all instances of the given adapter or all instances of all adapters.
|
|
1153
|
+
*
|
|
1154
|
+
* @param adapter The name of the adapter
|
|
1155
|
+
* @param update Force update
|
|
1156
1156
|
*/
|
|
1157
|
-
getAdapterInstances(
|
|
1158
|
-
/** The name of the adapter. */
|
|
1159
|
-
adapter,
|
|
1160
|
-
/** Force update. */
|
|
1161
|
-
update) {
|
|
1157
|
+
getAdapterInstances(adapter, update) {
|
|
1162
1158
|
if (typeof adapter === 'boolean') {
|
|
1163
1159
|
update = adapter;
|
|
1164
1160
|
adapter = '';
|
|
@@ -1168,20 +1164,20 @@ class Connection {
|
|
|
1168
1164
|
return this._promises[`instances_${adapter}`];
|
|
1169
1165
|
}
|
|
1170
1166
|
if (!this.connected) {
|
|
1171
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1167
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1172
1168
|
}
|
|
1173
1169
|
this._promises[`instances_${adapter}`] = new Promise((resolve, reject) => {
|
|
1174
1170
|
let timeout = setTimeout(() => {
|
|
1175
1171
|
timeout = null;
|
|
1176
1172
|
this.getObjectView(`system.adapter.${adapter ? `${adapter}.` : ''}`, `system.adapter.${adapter ? `${adapter}.` : ''}\u9999`, 'instance')
|
|
1177
1173
|
.then(items => resolve(Object.keys(items).map(id => fixAdminUI(items[id]))))
|
|
1178
|
-
.catch(e => reject(e));
|
|
1174
|
+
.catch(e => reject(new Error(e)));
|
|
1179
1175
|
}, TIMEOUT_FOR_ADMIN4);
|
|
1180
1176
|
this._socket.emit('getAdapterInstances', adapter, (err, instances) => {
|
|
1181
1177
|
if (timeout) {
|
|
1182
1178
|
clearTimeout(timeout);
|
|
1183
1179
|
timeout = null;
|
|
1184
|
-
err ? reject(err) : resolve(instances);
|
|
1180
|
+
err ? reject(new Error(err)) : resolve(instances);
|
|
1185
1181
|
}
|
|
1186
1182
|
});
|
|
1187
1183
|
});
|
|
@@ -1189,14 +1185,13 @@ class Connection {
|
|
|
1189
1185
|
}
|
|
1190
1186
|
/**
|
|
1191
1187
|
* Get adapters with the given name or all adapters.
|
|
1188
|
+
*
|
|
1189
|
+
* @param adapter The name of the adapter
|
|
1190
|
+
* @param update Force update
|
|
1192
1191
|
*/
|
|
1193
|
-
getAdapters(
|
|
1194
|
-
/** The name of the adapter. */
|
|
1195
|
-
adapter,
|
|
1196
|
-
/** Force update. */
|
|
1197
|
-
update) {
|
|
1192
|
+
getAdapters(adapter, update) {
|
|
1198
1193
|
if (Connection.isWeb()) {
|
|
1199
|
-
return Promise.reject('Allowed only in admin');
|
|
1194
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1200
1195
|
}
|
|
1201
1196
|
if (typeof adapter === 'boolean') {
|
|
1202
1197
|
update = adapter;
|
|
@@ -1207,7 +1202,7 @@ class Connection {
|
|
|
1207
1202
|
return this._promises[`adapter_${adapter}`];
|
|
1208
1203
|
}
|
|
1209
1204
|
if (!this.connected) {
|
|
1210
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1205
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1211
1206
|
}
|
|
1212
1207
|
this._promises[`adapter_${adapter}`] = new Promise((resolve, reject) => {
|
|
1213
1208
|
let timeout = setTimeout(() => {
|
|
@@ -1216,13 +1211,13 @@ class Connection {
|
|
|
1216
1211
|
.then(items => {
|
|
1217
1212
|
resolve(Object.keys(items).map(id => fixAdminUI(items[id])));
|
|
1218
1213
|
})
|
|
1219
|
-
.catch(e => reject(e));
|
|
1214
|
+
.catch(e => reject(new Error(e)));
|
|
1220
1215
|
}, TIMEOUT_FOR_ADMIN4);
|
|
1221
1216
|
this._socket.emit('getAdapters', adapter, (err, adapters) => {
|
|
1222
1217
|
if (timeout) {
|
|
1223
1218
|
clearTimeout(timeout);
|
|
1224
1219
|
timeout = null;
|
|
1225
|
-
err ? reject(err) : resolve(adapters);
|
|
1220
|
+
err ? reject(new Error(err)) : resolve(adapters);
|
|
1226
1221
|
}
|
|
1227
1222
|
});
|
|
1228
1223
|
});
|
|
@@ -1252,24 +1247,24 @@ class Connection {
|
|
|
1252
1247
|
}
|
|
1253
1248
|
/**
|
|
1254
1249
|
* Rename a group.
|
|
1250
|
+
*
|
|
1255
1251
|
* @param id The id.
|
|
1256
|
-
* @param
|
|
1257
|
-
* @param
|
|
1252
|
+
* @param newId The new id.
|
|
1253
|
+
* @param newName The new name.
|
|
1258
1254
|
*/
|
|
1259
1255
|
async renameGroup(id, newId, newName) {
|
|
1260
1256
|
if (Connection.isWeb()) {
|
|
1261
|
-
return Promise.reject('Allowed only in admin');
|
|
1257
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1262
1258
|
}
|
|
1263
1259
|
const groups = await this.getGroups(true);
|
|
1264
1260
|
if (groups.length) {
|
|
1265
1261
|
// find all elements
|
|
1266
|
-
const groupsToRename = groups
|
|
1267
|
-
.filter(group => group._id.startsWith(`${id}.`));
|
|
1262
|
+
const groupsToRename = groups.filter(group => group._id.startsWith(`${id}.`));
|
|
1268
1263
|
groupsToRename.forEach(group => {
|
|
1269
1264
|
group.newId = (newId + group._id.substring(id.length));
|
|
1270
1265
|
});
|
|
1271
1266
|
await new Promise((resolve, reject) => {
|
|
1272
|
-
this._renameGroups(groupsToRename, (err) =>
|
|
1267
|
+
this._renameGroups(groupsToRename, (err) => err ? reject(new Error(err)) : resolve(null));
|
|
1273
1268
|
});
|
|
1274
1269
|
const obj = groups.find(group => group._id === id);
|
|
1275
1270
|
if (obj) {
|
|
@@ -1279,25 +1274,21 @@ class Connection {
|
|
|
1279
1274
|
// @ts-expect-error will be corrected in the next js-controller release
|
|
1280
1275
|
obj.common.name = newName;
|
|
1281
1276
|
}
|
|
1282
|
-
return this.setObject(obj._id, obj)
|
|
1283
|
-
.then(() => this.delObject(id));
|
|
1277
|
+
return this.setObject(obj._id, obj).then(() => this.delObject(id));
|
|
1284
1278
|
}
|
|
1285
1279
|
}
|
|
1286
1280
|
return Promise.resolve();
|
|
1287
1281
|
}
|
|
1288
1282
|
/**
|
|
1289
1283
|
* Sends a message to a specific instance or all instances of some specific adapter.
|
|
1290
|
-
*
|
|
1284
|
+
*
|
|
1285
|
+
* @param instance The instance to send this message to.
|
|
1286
|
+
* @param command Command name of the target instance.
|
|
1287
|
+
* @param data The message data to send.
|
|
1291
1288
|
*/
|
|
1292
|
-
sendTo(
|
|
1293
|
-
/** The instance to send this message to. */
|
|
1294
|
-
instance,
|
|
1295
|
-
/** Command name of the target instance. */
|
|
1296
|
-
command,
|
|
1297
|
-
/** The message data to send. */
|
|
1298
|
-
data) {
|
|
1289
|
+
sendTo(instance, command, data) {
|
|
1299
1290
|
if (!this.connected) {
|
|
1300
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1291
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1301
1292
|
}
|
|
1302
1293
|
return new Promise(resolve => {
|
|
1303
1294
|
this._socket.emit('sendTo', instance, command, data, (result) => resolve(result));
|
|
@@ -1305,14 +1296,13 @@ class Connection {
|
|
|
1305
1296
|
}
|
|
1306
1297
|
/**
|
|
1307
1298
|
* Extend an object and create it if it might not exist.
|
|
1299
|
+
*
|
|
1300
|
+
* @param id The id.
|
|
1301
|
+
* @param obj The object.
|
|
1308
1302
|
*/
|
|
1309
|
-
extendObject(
|
|
1310
|
-
/** The id. */
|
|
1311
|
-
id,
|
|
1312
|
-
/** The object. */
|
|
1313
|
-
obj) {
|
|
1303
|
+
extendObject(id, obj) {
|
|
1314
1304
|
if (!this.connected) {
|
|
1315
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1305
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1316
1306
|
}
|
|
1317
1307
|
obj = JSON.parse(JSON.stringify(obj));
|
|
1318
1308
|
if (Object.prototype.hasOwnProperty.call(obj, 'from')) {
|
|
@@ -1325,7 +1315,7 @@ class Connection {
|
|
|
1325
1315
|
delete obj.ts;
|
|
1326
1316
|
}
|
|
1327
1317
|
return new Promise((resolve, reject) => {
|
|
1328
|
-
this._socket.emit('extendObject', id, obj, (err) =>
|
|
1318
|
+
this._socket.emit('extendObject', id, obj, (err) => err ? reject(new Error(err)) : resolve());
|
|
1329
1319
|
});
|
|
1330
1320
|
}
|
|
1331
1321
|
/**
|
|
@@ -1356,7 +1346,8 @@ class Connection {
|
|
|
1356
1346
|
}
|
|
1357
1347
|
/**
|
|
1358
1348
|
* Set the handler for standard output of a command.
|
|
1359
|
-
*
|
|
1349
|
+
*
|
|
1350
|
+
* @param handler The handler.
|
|
1360
1351
|
*/
|
|
1361
1352
|
registerCmdStdoutHandler(handler) {
|
|
1362
1353
|
this.onCmdStdoutHandler = handler;
|
|
@@ -1369,7 +1360,8 @@ class Connection {
|
|
|
1369
1360
|
}
|
|
1370
1361
|
/**
|
|
1371
1362
|
* Set the handler for standard error of a command.
|
|
1372
|
-
*
|
|
1363
|
+
*
|
|
1364
|
+
* @param handler The handler.
|
|
1373
1365
|
*/
|
|
1374
1366
|
registerCmdStderrHandler(handler) {
|
|
1375
1367
|
this.onCmdStderrHandler = handler;
|
|
@@ -1404,7 +1396,7 @@ class Connection {
|
|
|
1404
1396
|
return this._promises[`enums_${_enum || 'all'}`];
|
|
1405
1397
|
}
|
|
1406
1398
|
if (!this.connected) {
|
|
1407
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1399
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1408
1400
|
}
|
|
1409
1401
|
this._promises[`enums_${_enum || 'all'}`] = new Promise((resolve, reject) => {
|
|
1410
1402
|
this._socket.emit('getObjectView', 'system', 'enum', { startkey: `enum.${_enum || ''}`, endkey: `enum.${_enum ? `${_enum}.` : ''}\u9999` }, (err, res) => {
|
|
@@ -1418,8 +1410,11 @@ class Connection {
|
|
|
1418
1410
|
}
|
|
1419
1411
|
resolve(_res);
|
|
1420
1412
|
}
|
|
1413
|
+
else if (err) {
|
|
1414
|
+
reject(new Error(err));
|
|
1415
|
+
}
|
|
1421
1416
|
else {
|
|
1422
|
-
reject(
|
|
1417
|
+
reject(new Error('Invalid response while getting enums'));
|
|
1423
1418
|
}
|
|
1424
1419
|
});
|
|
1425
1420
|
});
|
|
@@ -1427,10 +1422,11 @@ class Connection {
|
|
|
1427
1422
|
}
|
|
1428
1423
|
/**
|
|
1429
1424
|
* Query a predefined object view.
|
|
1425
|
+
*
|
|
1430
1426
|
* @param design design - 'system' or other designs like `custom`.
|
|
1431
1427
|
* @param type The type of object.
|
|
1432
1428
|
* @param start The start ID.
|
|
1433
|
-
* @param
|
|
1429
|
+
* @param end The end ID.
|
|
1434
1430
|
*/
|
|
1435
1431
|
getObjectViewCustom(
|
|
1436
1432
|
/** The design: 'system' or other designs like `custom`. */
|
|
@@ -1453,37 +1449,32 @@ class Connection {
|
|
|
1453
1449
|
resolve(_res);
|
|
1454
1450
|
}
|
|
1455
1451
|
else {
|
|
1456
|
-
reject(err);
|
|
1452
|
+
reject(new Error(err));
|
|
1457
1453
|
}
|
|
1458
1454
|
});
|
|
1459
1455
|
});
|
|
1460
1456
|
}
|
|
1461
1457
|
/**
|
|
1462
1458
|
* Query a predefined object view.
|
|
1459
|
+
*
|
|
1463
1460
|
* @param type The type of object.
|
|
1464
1461
|
* @param start The start ID.
|
|
1465
|
-
* @param
|
|
1462
|
+
* @param end The end ID.
|
|
1466
1463
|
*/
|
|
1467
|
-
getObjectViewSystem(
|
|
1468
|
-
/** The type of object. */
|
|
1469
|
-
type,
|
|
1470
|
-
/** The start ID. */
|
|
1471
|
-
start,
|
|
1472
|
-
/** The end ID. */
|
|
1473
|
-
end) {
|
|
1464
|
+
getObjectViewSystem(type, start, end) {
|
|
1474
1465
|
return this.getObjectViewCustom('system', type, start, end);
|
|
1475
1466
|
}
|
|
1476
1467
|
/**
|
|
1477
1468
|
* @deprecated since version 1.1.15, cause parameter order does not match backend
|
|
1469
|
+
*
|
|
1478
1470
|
* Query a predefined object view.
|
|
1479
|
-
* @param
|
|
1480
|
-
* @param
|
|
1481
|
-
* @param
|
|
1482
|
-
* @returns {Promise<Record<string, ioBroker.Object>>}
|
|
1471
|
+
* @param start The start ID.
|
|
1472
|
+
* @param end The end ID.
|
|
1473
|
+
* @param type The type of object.
|
|
1483
1474
|
*/
|
|
1484
1475
|
getObjectView(start, end, type) {
|
|
1485
1476
|
if (!this.connected) {
|
|
1486
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1477
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1487
1478
|
}
|
|
1488
1479
|
start = start || '';
|
|
1489
1480
|
end = end || '\u9999';
|
|
@@ -1491,21 +1482,20 @@ class Connection {
|
|
|
1491
1482
|
}
|
|
1492
1483
|
/**
|
|
1493
1484
|
* Get the stored certificates.
|
|
1485
|
+
*
|
|
1486
|
+
* @param update Force update.
|
|
1494
1487
|
*/
|
|
1495
|
-
getCertificates(
|
|
1496
|
-
/** Force update. */
|
|
1497
|
-
update) {
|
|
1488
|
+
getCertificates(update) {
|
|
1498
1489
|
if (Connection.isWeb()) {
|
|
1499
|
-
return Promise.reject('Allowed only in admin');
|
|
1490
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1500
1491
|
}
|
|
1501
1492
|
if (this._promises.cert && !update) {
|
|
1502
1493
|
return this._promises.cert;
|
|
1503
1494
|
}
|
|
1504
1495
|
if (!this.connected) {
|
|
1505
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1496
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1506
1497
|
}
|
|
1507
|
-
this._promises.cert = this.getObject('system.certificates')
|
|
1508
|
-
.then(res => {
|
|
1498
|
+
this._promises.cert = this.getObject('system.certificates').then(res => {
|
|
1509
1499
|
const certs = [];
|
|
1510
1500
|
if (res && res.native && res.native.certificates) {
|
|
1511
1501
|
Object.keys(res.native.certificates).forEach(c => {
|
|
@@ -1534,7 +1524,11 @@ class Connection {
|
|
|
1534
1524
|
certs.push(_cert);
|
|
1535
1525
|
}
|
|
1536
1526
|
else {
|
|
1537
|
-
_cert.type =
|
|
1527
|
+
_cert.type =
|
|
1528
|
+
cert.substring(0, '-----BEGIN RSA PRIVATE KEY'.length) === '-----BEGIN RSA PRIVATE KEY' ||
|
|
1529
|
+
cert.substring(0, '-----BEGIN PRIVATE KEY'.length) === '-----BEGIN PRIVATE KEY'
|
|
1530
|
+
? 'private'
|
|
1531
|
+
: 'public';
|
|
1538
1532
|
if (_cert.type === 'public') {
|
|
1539
1533
|
const m = cert.split('-----END CERTIFICATE-----');
|
|
1540
1534
|
if (m.filter((t) => t.replace(/\r\n|\r|\n/, '').trim()).length > 1) {
|
|
@@ -1554,10 +1548,10 @@ class Connection {
|
|
|
1554
1548
|
*/
|
|
1555
1549
|
getLogs(host, linesNumber) {
|
|
1556
1550
|
if (Connection.isWeb()) {
|
|
1557
|
-
return Promise.reject('Allowed only in admin');
|
|
1551
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1558
1552
|
}
|
|
1559
1553
|
if (!this.connected) {
|
|
1560
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1554
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1561
1555
|
}
|
|
1562
1556
|
return new Promise(resolve => {
|
|
1563
1557
|
this._socket.emit('sendToHost', host, 'getLogs', linesNumber || 200, (lines) => resolve(lines));
|
|
@@ -1568,13 +1562,13 @@ class Connection {
|
|
|
1568
1562
|
*/
|
|
1569
1563
|
getLogsFiles(host) {
|
|
1570
1564
|
if (Connection.isWeb()) {
|
|
1571
|
-
return Promise.reject('Allowed only in admin');
|
|
1565
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1572
1566
|
}
|
|
1573
1567
|
if (!this.connected) {
|
|
1574
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1568
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1575
1569
|
}
|
|
1576
1570
|
return new Promise((resolve, reject) => {
|
|
1577
|
-
this._socket.emit('readLogs', host, (err, files) =>
|
|
1571
|
+
this._socket.emit('readLogs', host, (err, files) => err ? reject(new Error(err)) : resolve(files));
|
|
1578
1572
|
});
|
|
1579
1573
|
}
|
|
1580
1574
|
/**
|
|
@@ -1582,13 +1576,13 @@ class Connection {
|
|
|
1582
1576
|
*/
|
|
1583
1577
|
delLogs(host) {
|
|
1584
1578
|
if (Connection.isWeb()) {
|
|
1585
|
-
return Promise.reject('Allowed only in admin');
|
|
1579
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1586
1580
|
}
|
|
1587
1581
|
if (!this.connected) {
|
|
1588
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1582
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1589
1583
|
}
|
|
1590
1584
|
return new Promise((resolve, reject) => {
|
|
1591
|
-
this._socket.emit('sendToHost', host, 'delLogs', null, (error) =>
|
|
1585
|
+
this._socket.emit('sendToHost', host, 'delLogs', null, (error) => error ? reject(new Error(error)) : resolve());
|
|
1592
1586
|
});
|
|
1593
1587
|
}
|
|
1594
1588
|
/**
|
|
@@ -1596,124 +1590,120 @@ class Connection {
|
|
|
1596
1590
|
*/
|
|
1597
1591
|
readMetaItems() {
|
|
1598
1592
|
if (!this.connected) {
|
|
1599
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1593
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1600
1594
|
}
|
|
1601
1595
|
return new Promise((resolve, reject) => {
|
|
1602
|
-
this._socket.emit('getObjectView', 'system', 'meta', { startkey: '', endkey: '\u9999' }, (err, objs) =>
|
|
1596
|
+
this._socket.emit('getObjectView', 'system', 'meta', { startkey: '', endkey: '\u9999' }, (err, objs) => err
|
|
1597
|
+
? reject(new Error(err))
|
|
1598
|
+
: resolve(objs.rows &&
|
|
1599
|
+
objs.rows.map((obj) => obj.value)));
|
|
1603
1600
|
});
|
|
1604
1601
|
}
|
|
1605
1602
|
/**
|
|
1606
1603
|
* Read the directory of an adapter.
|
|
1604
|
+
*
|
|
1605
|
+
* @param adapter The adapter name.
|
|
1606
|
+
* @param fileName The directory name.
|
|
1607
1607
|
*/
|
|
1608
|
-
readDir(
|
|
1609
|
-
/** The adapter name. */
|
|
1610
|
-
adapter,
|
|
1611
|
-
/** The directory name. */
|
|
1612
|
-
fileName) {
|
|
1608
|
+
readDir(adapter, fileName) {
|
|
1613
1609
|
if (!this.connected) {
|
|
1614
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1610
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1615
1611
|
}
|
|
1616
1612
|
return new Promise((resolve, reject) => {
|
|
1617
|
-
this._socket.emit('readDir', adapter, fileName, (err, files) =>
|
|
1613
|
+
this._socket.emit('readDir', adapter, fileName, (err, files) => err ? reject(new Error(err)) : resolve(files));
|
|
1618
1614
|
});
|
|
1619
1615
|
}
|
|
1620
1616
|
/**
|
|
1621
1617
|
* Read a file of an adapter.
|
|
1618
|
+
*
|
|
1619
|
+
* @param adapter The adapter name.
|
|
1620
|
+
* @param fileName The file name.
|
|
1621
|
+
* @param base64 If it must be a base64 format.
|
|
1622
1622
|
*/
|
|
1623
|
-
readFile(
|
|
1624
|
-
/** The adapter name. */
|
|
1625
|
-
adapter,
|
|
1626
|
-
/** The file name. */
|
|
1627
|
-
fileName,
|
|
1628
|
-
/** If it must be a base64 format */
|
|
1629
|
-
base64) {
|
|
1623
|
+
readFile(adapter, fileName, base64) {
|
|
1630
1624
|
if (!this.connected) {
|
|
1631
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1625
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1632
1626
|
}
|
|
1633
1627
|
return new Promise((resolve, reject) => {
|
|
1634
1628
|
if (!base64) {
|
|
1635
1629
|
this._socket.emit('readFile', adapter, fileName, (err, data, type) => {
|
|
1636
|
-
err ? reject(err) : resolve({ data, type });
|
|
1630
|
+
err ? reject(new Error(err)) : resolve({ data, type });
|
|
1637
1631
|
});
|
|
1638
1632
|
}
|
|
1639
1633
|
else {
|
|
1640
|
-
this._socket.emit('readFile64', adapter, fileName, base64, (err, data) =>
|
|
1634
|
+
this._socket.emit('readFile64', adapter, fileName, base64, (err, data) => err ? reject(new Error(err)) : resolve(data));
|
|
1641
1635
|
}
|
|
1642
1636
|
});
|
|
1643
1637
|
}
|
|
1644
1638
|
/**
|
|
1645
1639
|
* Write a file of an adapter.
|
|
1640
|
+
*
|
|
1641
|
+
* @param adapter The adapter name.
|
|
1642
|
+
* @param fileName The file name.
|
|
1643
|
+
* @param data The data (if it's a Buffer, it will be converted to Base64)
|
|
1646
1644
|
*/
|
|
1647
|
-
writeFile64(
|
|
1648
|
-
/** The adapter name. */
|
|
1649
|
-
adapter,
|
|
1650
|
-
/** The file name. */
|
|
1651
|
-
fileName,
|
|
1652
|
-
/** The data (if it's a Buffer, it will be converted to Base64). */
|
|
1653
|
-
data) {
|
|
1645
|
+
writeFile64(adapter, fileName, data) {
|
|
1654
1646
|
if (!this.connected) {
|
|
1655
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1647
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1656
1648
|
}
|
|
1657
1649
|
return new Promise((resolve, reject) => {
|
|
1658
1650
|
if (typeof data === 'string') {
|
|
1659
|
-
this._socket.emit('writeFile', adapter, fileName, data, (err) =>
|
|
1651
|
+
this._socket.emit('writeFile', adapter, fileName, data, (err) => err ? reject(new Error(err)) : resolve());
|
|
1660
1652
|
}
|
|
1661
1653
|
else {
|
|
1662
|
-
const base64 = btoa(new Uint8Array(data)
|
|
1663
|
-
|
|
1664
|
-
this._socket.emit('writeFile64', adapter, fileName, base64, (err) => (err ? reject(err) : resolve()));
|
|
1654
|
+
const base64 = btoa(new Uint8Array(data).reduce((_data, byte) => _data + String.fromCharCode(byte), ''));
|
|
1655
|
+
this._socket.emit('writeFile64', adapter, fileName, base64, (err) => err ? reject(new Error(err)) : resolve());
|
|
1665
1656
|
}
|
|
1666
1657
|
});
|
|
1667
1658
|
}
|
|
1668
1659
|
/**
|
|
1669
1660
|
* Delete a file of an adapter.
|
|
1661
|
+
*
|
|
1662
|
+
* @param adapter The adapter name.
|
|
1663
|
+
* @param fileName The file name.
|
|
1670
1664
|
*/
|
|
1671
|
-
deleteFile(
|
|
1672
|
-
/** The adapter name. */
|
|
1673
|
-
adapter,
|
|
1674
|
-
/** The file name. */
|
|
1675
|
-
fileName) {
|
|
1665
|
+
deleteFile(adapter, fileName) {
|
|
1676
1666
|
if (!this.connected) {
|
|
1677
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1667
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1678
1668
|
}
|
|
1679
1669
|
return new Promise((resolve, reject) => {
|
|
1680
|
-
this._socket.emit('unlink', adapter, fileName, (err) =>
|
|
1670
|
+
this._socket.emit('unlink', adapter, fileName, (err) => err ? reject(new Error(err)) : resolve());
|
|
1681
1671
|
});
|
|
1682
1672
|
}
|
|
1683
1673
|
/**
|
|
1684
1674
|
* Delete a folder of an adapter.
|
|
1685
1675
|
* All files in folder will be deleted.
|
|
1676
|
+
*
|
|
1677
|
+
* @param adapter The adapter name.
|
|
1678
|
+
* @param folderName The folder name.
|
|
1686
1679
|
*/
|
|
1687
|
-
deleteFolder(
|
|
1688
|
-
/** The adapter name. */
|
|
1689
|
-
adapter,
|
|
1690
|
-
/** The file name. */
|
|
1691
|
-
folderName) {
|
|
1680
|
+
deleteFolder(adapter, folderName) {
|
|
1692
1681
|
if (!this.connected) {
|
|
1693
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1682
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1694
1683
|
}
|
|
1695
1684
|
return new Promise((resolve, reject) => {
|
|
1696
|
-
this._socket.emit('deleteFolder', adapter, folderName, (err) =>
|
|
1685
|
+
this._socket.emit('deleteFolder', adapter, folderName, (err) => err ? reject(new Error(err)) : resolve());
|
|
1697
1686
|
});
|
|
1698
1687
|
}
|
|
1699
1688
|
/**
|
|
1700
1689
|
* Get the list of all hosts.
|
|
1701
|
-
*
|
|
1690
|
+
*
|
|
1691
|
+
* @param update Force update.
|
|
1702
1692
|
*/
|
|
1703
1693
|
getHosts(update) {
|
|
1704
1694
|
if (Connection.isWeb()) {
|
|
1705
|
-
return Promise.reject('Allowed only in admin');
|
|
1695
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1706
1696
|
}
|
|
1707
1697
|
if (!update && this._promises.hosts) {
|
|
1708
1698
|
return this._promises.hosts;
|
|
1709
1699
|
}
|
|
1710
1700
|
if (!this.connected) {
|
|
1711
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1701
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1712
1702
|
}
|
|
1713
1703
|
this._promises.hosts = new Promise((resolve, reject) => {
|
|
1714
1704
|
this._socket.emit('getObjectView', 'system', 'host', { startkey: 'system.host.', endkey: 'system.host.\u9999' }, (err, doc) => {
|
|
1715
1705
|
if (err) {
|
|
1716
|
-
reject(err);
|
|
1706
|
+
reject(new Error(err));
|
|
1717
1707
|
}
|
|
1718
1708
|
else {
|
|
1719
1709
|
resolve(doc.rows.map(item => item.value));
|
|
@@ -1724,23 +1714,23 @@ class Connection {
|
|
|
1724
1714
|
}
|
|
1725
1715
|
/**
|
|
1726
1716
|
* Get the list of all users.
|
|
1717
|
+
*
|
|
1718
|
+
* @param update Force update.
|
|
1727
1719
|
*/
|
|
1728
|
-
getUsers(
|
|
1729
|
-
/** Force update. */
|
|
1730
|
-
update) {
|
|
1720
|
+
getUsers(update) {
|
|
1731
1721
|
if (Connection.isWeb()) {
|
|
1732
|
-
return Promise.reject('Allowed only in admin');
|
|
1722
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1733
1723
|
}
|
|
1734
1724
|
if (!update && this._promises.users) {
|
|
1735
1725
|
return this._promises.users;
|
|
1736
1726
|
}
|
|
1737
1727
|
if (!this.connected) {
|
|
1738
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1728
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1739
1729
|
}
|
|
1740
1730
|
this._promises.users = new Promise((resolve, reject) => {
|
|
1741
1731
|
this._socket.emit('getObjectView', 'system', 'user', { startkey: 'system.user.', endkey: 'system.user.\u9999' }, (err, doc) => {
|
|
1742
1732
|
if (err) {
|
|
1743
|
-
reject(err);
|
|
1733
|
+
reject(new Error(err));
|
|
1744
1734
|
}
|
|
1745
1735
|
else {
|
|
1746
1736
|
resolve(doc.rows.map(item => item.value));
|
|
@@ -1751,20 +1741,20 @@ class Connection {
|
|
|
1751
1741
|
}
|
|
1752
1742
|
/**
|
|
1753
1743
|
* Get the list of all groups.
|
|
1744
|
+
*
|
|
1745
|
+
* @param update Force update.
|
|
1754
1746
|
*/
|
|
1755
|
-
getGroups(
|
|
1756
|
-
/** Force update. */
|
|
1757
|
-
update) {
|
|
1747
|
+
getGroups(update) {
|
|
1758
1748
|
if (!update && this._promises.groups) {
|
|
1759
1749
|
return this._promises.groups;
|
|
1760
1750
|
}
|
|
1761
1751
|
if (!this.connected) {
|
|
1762
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1752
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1763
1753
|
}
|
|
1764
1754
|
this._promises.groups = new Promise((resolve, reject) => {
|
|
1765
1755
|
this._socket.emit('getObjectView', 'system', 'group', { startkey: 'system.group.', endkey: 'system.group.\u9999' }, (err, doc) => {
|
|
1766
1756
|
if (err) {
|
|
1767
|
-
reject(err);
|
|
1757
|
+
reject(new Error(err));
|
|
1768
1758
|
}
|
|
1769
1759
|
else {
|
|
1770
1760
|
resolve(doc.rows.map(item => item.value));
|
|
@@ -1775,14 +1765,14 @@ class Connection {
|
|
|
1775
1765
|
}
|
|
1776
1766
|
/**
|
|
1777
1767
|
* Get the host information.
|
|
1768
|
+
*
|
|
1769
|
+
* @param host The host name.
|
|
1770
|
+
* @param update Force update.
|
|
1771
|
+
* @param timeoutMs Optional read timeout.
|
|
1778
1772
|
*/
|
|
1779
|
-
getHostInfo(host,
|
|
1780
|
-
/** Force update. */
|
|
1781
|
-
update,
|
|
1782
|
-
/** optional read timeout. */
|
|
1783
|
-
timeoutMs) {
|
|
1773
|
+
getHostInfo(host, update, timeoutMs) {
|
|
1784
1774
|
if (Connection.isWeb()) {
|
|
1785
|
-
return Promise.reject('Allowed only in admin');
|
|
1775
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1786
1776
|
}
|
|
1787
1777
|
if (!host.startsWith('system.host.')) {
|
|
1788
1778
|
host += `system.host.${host}`;
|
|
@@ -1791,13 +1781,13 @@ class Connection {
|
|
|
1791
1781
|
return this._promises[`hostInfo_${host}`];
|
|
1792
1782
|
}
|
|
1793
1783
|
if (!this.connected) {
|
|
1794
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1784
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1795
1785
|
}
|
|
1796
1786
|
this._promises[`hostInfo_${host}`] = new Promise((resolve, reject) => {
|
|
1797
1787
|
let timeout = setTimeout(() => {
|
|
1798
1788
|
if (timeout) {
|
|
1799
1789
|
timeout = null;
|
|
1800
|
-
reject('getHostInfo timeout');
|
|
1790
|
+
reject(new Error('getHostInfo timeout'));
|
|
1801
1791
|
}
|
|
1802
1792
|
}, timeoutMs || this.props.cmdTimeout);
|
|
1803
1793
|
this._socket.emit('sendToHost', host, 'getHostInfo', null, (data) => {
|
|
@@ -1805,10 +1795,10 @@ class Connection {
|
|
|
1805
1795
|
clearTimeout(timeout);
|
|
1806
1796
|
timeout = null;
|
|
1807
1797
|
if (data === PERMISSION_ERROR) {
|
|
1808
|
-
reject('May not read "getHostInfo"');
|
|
1798
|
+
reject(new Error('May not read "getHostInfo"'));
|
|
1809
1799
|
}
|
|
1810
1800
|
else if (!data || typeof data !== 'object') {
|
|
1811
|
-
reject('Cannot read "getHostInfo"');
|
|
1801
|
+
reject(new Error('Cannot read "getHostInfo"'));
|
|
1812
1802
|
}
|
|
1813
1803
|
else {
|
|
1814
1804
|
resolve(data);
|
|
@@ -1820,14 +1810,14 @@ class Connection {
|
|
|
1820
1810
|
}
|
|
1821
1811
|
/**
|
|
1822
1812
|
* Get the host information (short version).
|
|
1813
|
+
*
|
|
1814
|
+
* @param host The host name.
|
|
1815
|
+
* @param update Force update.
|
|
1816
|
+
* @param timeoutMs Optional read timeout.
|
|
1823
1817
|
*/
|
|
1824
|
-
getHostInfoShort(host,
|
|
1825
|
-
/** Force update. */
|
|
1826
|
-
update,
|
|
1827
|
-
/** optional read timeout. */
|
|
1828
|
-
timeoutMs) {
|
|
1818
|
+
getHostInfoShort(host, update, timeoutMs) {
|
|
1829
1819
|
if (Connection.isWeb()) {
|
|
1830
|
-
return Promise.reject('Allowed only in admin');
|
|
1820
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1831
1821
|
}
|
|
1832
1822
|
if (!host.startsWith('system.host.')) {
|
|
1833
1823
|
host += `system.host.${host}`;
|
|
@@ -1836,13 +1826,13 @@ class Connection {
|
|
|
1836
1826
|
return this._promises[`hostInfoShort_${host}`];
|
|
1837
1827
|
}
|
|
1838
1828
|
if (!this.connected) {
|
|
1839
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1829
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1840
1830
|
}
|
|
1841
1831
|
this._promises[`hostInfoShort_${host}`] = new Promise((resolve, reject) => {
|
|
1842
1832
|
let timeout = setTimeout(() => {
|
|
1843
1833
|
if (timeout) {
|
|
1844
1834
|
timeout = null;
|
|
1845
|
-
reject('hostInfoShort timeout');
|
|
1835
|
+
reject(new Error('hostInfoShort timeout'));
|
|
1846
1836
|
}
|
|
1847
1837
|
}, timeoutMs || this.props.cmdTimeout);
|
|
1848
1838
|
this._socket.emit('sendToHost', host, 'getHostInfoShort', null, (data) => {
|
|
@@ -1850,10 +1840,10 @@ class Connection {
|
|
|
1850
1840
|
clearTimeout(timeout);
|
|
1851
1841
|
timeout = null;
|
|
1852
1842
|
if (data === PERMISSION_ERROR) {
|
|
1853
|
-
reject('May not read "getHostInfoShort"');
|
|
1843
|
+
reject(new Error('May not read "getHostInfoShort"'));
|
|
1854
1844
|
}
|
|
1855
1845
|
else if (!data || typeof data !== 'object') {
|
|
1856
|
-
reject('Cannot read "getHostInfoShort"');
|
|
1846
|
+
reject(new Error('Cannot read "getHostInfoShort"'));
|
|
1857
1847
|
}
|
|
1858
1848
|
else {
|
|
1859
1849
|
resolve(data);
|
|
@@ -1865,20 +1855,21 @@ class Connection {
|
|
|
1865
1855
|
}
|
|
1866
1856
|
/**
|
|
1867
1857
|
* Get the repository.
|
|
1858
|
+
*
|
|
1859
|
+
* @param host The host name.
|
|
1860
|
+
* @param options Options.
|
|
1861
|
+
* @param update Force update.
|
|
1862
|
+
* @param timeoutMs Timeout in ms.
|
|
1868
1863
|
*/
|
|
1869
|
-
getRepository(host, options,
|
|
1870
|
-
/** Force update. */
|
|
1871
|
-
update,
|
|
1872
|
-
/** timeout in ms. */
|
|
1873
|
-
timeoutMs) {
|
|
1864
|
+
getRepository(host, options, update, timeoutMs) {
|
|
1874
1865
|
if (Connection.isWeb()) {
|
|
1875
|
-
return Promise.reject('Allowed only in admin');
|
|
1866
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1876
1867
|
}
|
|
1877
1868
|
if (!update && this._promises.repo) {
|
|
1878
1869
|
return this._promises.repo;
|
|
1879
1870
|
}
|
|
1880
1871
|
if (!this.connected) {
|
|
1881
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1872
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1882
1873
|
}
|
|
1883
1874
|
if (!host.startsWith('system.host.')) {
|
|
1884
1875
|
host += `system.host.${host}`;
|
|
@@ -1887,7 +1878,7 @@ class Connection {
|
|
|
1887
1878
|
let timeout = setTimeout(() => {
|
|
1888
1879
|
if (timeout) {
|
|
1889
1880
|
timeout = null;
|
|
1890
|
-
reject('getRepository timeout');
|
|
1881
|
+
reject(new Error('getRepository timeout'));
|
|
1891
1882
|
}
|
|
1892
1883
|
}, timeoutMs || this.props.cmdTimeout);
|
|
1893
1884
|
this._socket.emit('sendToHost', host, 'getRepository', options, (data) => {
|
|
@@ -1895,10 +1886,10 @@ class Connection {
|
|
|
1895
1886
|
clearTimeout(timeout);
|
|
1896
1887
|
timeout = null;
|
|
1897
1888
|
if (data === PERMISSION_ERROR) {
|
|
1898
|
-
reject('May not read "getRepository"');
|
|
1889
|
+
reject(new Error('May not read "getRepository"'));
|
|
1899
1890
|
}
|
|
1900
1891
|
else if (!data || typeof data !== 'object') {
|
|
1901
|
-
reject('Cannot read "getRepository"');
|
|
1892
|
+
reject(new Error('Cannot read "getRepository"'));
|
|
1902
1893
|
}
|
|
1903
1894
|
else {
|
|
1904
1895
|
resolve(data);
|
|
@@ -1910,21 +1901,21 @@ class Connection {
|
|
|
1910
1901
|
}
|
|
1911
1902
|
/**
|
|
1912
1903
|
* Get the installed.
|
|
1904
|
+
*
|
|
1905
|
+
* @param host The host name.
|
|
1906
|
+
* @param update Force update.
|
|
1907
|
+
* @param cmdTimeout Timeout in ms.
|
|
1913
1908
|
*/
|
|
1914
|
-
getInstalled(host,
|
|
1915
|
-
/** Force update. */
|
|
1916
|
-
update,
|
|
1917
|
-
/** timeout in ms */
|
|
1918
|
-
cmdTimeout) {
|
|
1909
|
+
getInstalled(host, update, cmdTimeout) {
|
|
1919
1910
|
if (Connection.isWeb()) {
|
|
1920
|
-
return Promise.reject('Allowed only in admin');
|
|
1911
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
1921
1912
|
}
|
|
1922
1913
|
this._promises.installed = this._promises.installed || {};
|
|
1923
1914
|
if (!update && this._promises.installed[host]) {
|
|
1924
1915
|
return this._promises.installed[host];
|
|
1925
1916
|
}
|
|
1926
1917
|
if (!this.connected) {
|
|
1927
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1918
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1928
1919
|
}
|
|
1929
1920
|
if (!host.startsWith('system.host.')) {
|
|
1930
1921
|
host += `system.host.${host}`;
|
|
@@ -1933,7 +1924,7 @@ class Connection {
|
|
|
1933
1924
|
let timeout = setTimeout(() => {
|
|
1934
1925
|
if (timeout) {
|
|
1935
1926
|
timeout = null;
|
|
1936
|
-
reject('getInstalled timeout');
|
|
1927
|
+
reject(new Error('getInstalled timeout'));
|
|
1937
1928
|
}
|
|
1938
1929
|
}, cmdTimeout || this.props.cmdTimeout);
|
|
1939
1930
|
this._socket.emit('sendToHost', host, 'getInstalled', null, (data) => {
|
|
@@ -1941,10 +1932,10 @@ class Connection {
|
|
|
1941
1932
|
clearTimeout(timeout);
|
|
1942
1933
|
timeout = null;
|
|
1943
1934
|
if (data === PERMISSION_ERROR) {
|
|
1944
|
-
reject('May not read "getInstalled"');
|
|
1935
|
+
reject(new Error('May not read "getInstalled"'));
|
|
1945
1936
|
}
|
|
1946
1937
|
else if (!data || typeof data !== 'object') {
|
|
1947
|
-
reject('Cannot read "getInstalled"');
|
|
1938
|
+
reject(new Error('Cannot read "getInstalled"'));
|
|
1948
1939
|
}
|
|
1949
1940
|
else {
|
|
1950
1941
|
resolve(data);
|
|
@@ -1956,19 +1947,17 @@ class Connection {
|
|
|
1956
1947
|
}
|
|
1957
1948
|
/**
|
|
1958
1949
|
* Rename file or folder in ioBroker DB
|
|
1950
|
+
*
|
|
1951
|
+
* @param adapter Instance name, like `vis-2.0`.
|
|
1952
|
+
* @param oldName The current file name, e.g., main/vis-views.json
|
|
1953
|
+
* @param newName The new file name, e.g., main/vis-views-new.json
|
|
1959
1954
|
*/
|
|
1960
|
-
rename(
|
|
1961
|
-
/** instance name */
|
|
1962
|
-
adapter,
|
|
1963
|
-
/** current file name, e.g., main/vis-views.json */
|
|
1964
|
-
oldName,
|
|
1965
|
-
/** new file name, e.g., main/vis-views-new.json */
|
|
1966
|
-
newName) {
|
|
1955
|
+
rename(adapter, oldName, newName) {
|
|
1967
1956
|
if (!this.connected) {
|
|
1968
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1957
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1969
1958
|
}
|
|
1970
1959
|
return new Promise((resolve, reject) => {
|
|
1971
|
-
this._socket.emit('rename', adapter, oldName, newName, (err) =>
|
|
1960
|
+
this._socket.emit('rename', adapter, oldName, newName, (err) => err ? reject(new Error(err)) : resolve());
|
|
1972
1961
|
});
|
|
1973
1962
|
}
|
|
1974
1963
|
/**
|
|
@@ -1982,10 +1971,10 @@ class Connection {
|
|
|
1982
1971
|
/** new file name, e.g., main/vis-views-new.json */
|
|
1983
1972
|
newName) {
|
|
1984
1973
|
if (!this.connected) {
|
|
1985
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1974
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
1986
1975
|
}
|
|
1987
1976
|
return new Promise((resolve, reject) => {
|
|
1988
|
-
this._socket.emit('renameFile', adapter, oldName, newName, (err) =>
|
|
1977
|
+
this._socket.emit('renameFile', adapter, oldName, newName, (err) => err ? reject(new Error(err)) : resolve());
|
|
1989
1978
|
});
|
|
1990
1979
|
}
|
|
1991
1980
|
/**
|
|
@@ -2001,27 +1990,29 @@ class Connection {
|
|
|
2001
1990
|
/** Timeout of command in ms */
|
|
2002
1991
|
cmdTimeout) {
|
|
2003
1992
|
if (Connection.isWeb()) {
|
|
2004
|
-
return Promise.reject('Allowed only in admin');
|
|
1993
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2005
1994
|
}
|
|
2006
1995
|
if (!this.connected) {
|
|
2007
|
-
return Promise.reject(NOT_CONNECTED);
|
|
1996
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2008
1997
|
}
|
|
2009
1998
|
if (!host.startsWith(host)) {
|
|
2010
1999
|
host += `system.host.${host}`;
|
|
2011
2000
|
}
|
|
2012
2001
|
return new Promise((resolve, reject) => {
|
|
2013
|
-
let timeout = cmdTimeout
|
|
2014
|
-
|
|
2015
|
-
timeout
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2002
|
+
let timeout = cmdTimeout
|
|
2003
|
+
? setTimeout(() => {
|
|
2004
|
+
if (timeout) {
|
|
2005
|
+
timeout = null;
|
|
2006
|
+
reject(new Error('cmdExec timeout'));
|
|
2007
|
+
}
|
|
2008
|
+
}, cmdTimeout)
|
|
2009
|
+
: null;
|
|
2019
2010
|
this._socket.emit('cmdExec', host, cmdId, cmd, null, (err) => {
|
|
2020
2011
|
if (!cmdTimeout || timeout) {
|
|
2021
2012
|
timeout && clearTimeout(timeout);
|
|
2022
2013
|
timeout = null;
|
|
2023
2014
|
if (err) {
|
|
2024
|
-
reject(err);
|
|
2015
|
+
reject(new Error(err));
|
|
2025
2016
|
}
|
|
2026
2017
|
else {
|
|
2027
2018
|
resolve();
|
|
@@ -2042,10 +2033,10 @@ class Connection {
|
|
|
2042
2033
|
return this._promises[`supportedFeatures_${feature}`];
|
|
2043
2034
|
}
|
|
2044
2035
|
if (!this.connected) {
|
|
2045
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2036
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2046
2037
|
}
|
|
2047
2038
|
this._promises[`supportedFeatures_${feature}`] = new Promise((resolve, reject) => {
|
|
2048
|
-
this._socket.emit('checkFeatureSupported', feature, (err, supported) =>
|
|
2039
|
+
this._socket.emit('checkFeatureSupported', feature, (err, supported) => err ? reject(new Error(err)) : resolve(supported));
|
|
2049
2040
|
});
|
|
2050
2041
|
return this._promises[`supportedFeatures_${feature}`];
|
|
2051
2042
|
}
|
|
@@ -2054,18 +2045,18 @@ class Connection {
|
|
|
2054
2045
|
*/
|
|
2055
2046
|
async readBaseSettings(host) {
|
|
2056
2047
|
if (Connection.isWeb()) {
|
|
2057
|
-
return Promise.reject('Allowed only in admin');
|
|
2048
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2058
2049
|
}
|
|
2059
2050
|
const result = await this.checkFeatureSupported('CONTROLLER_READWRITE_BASE_SETTINGS');
|
|
2060
2051
|
if (result) {
|
|
2061
2052
|
if (!this.connected) {
|
|
2062
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2053
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2063
2054
|
}
|
|
2064
2055
|
return new Promise((resolve, reject) => {
|
|
2065
2056
|
let timeout = setTimeout(() => {
|
|
2066
2057
|
if (timeout) {
|
|
2067
2058
|
timeout = null;
|
|
2068
|
-
reject('readBaseSettings timeout');
|
|
2059
|
+
reject(new Error('readBaseSettings timeout'));
|
|
2069
2060
|
}
|
|
2070
2061
|
}, this.props.cmdTimeout);
|
|
2071
2062
|
if (host.startsWith('system.host.')) {
|
|
@@ -2076,10 +2067,10 @@ class Connection {
|
|
|
2076
2067
|
clearTimeout(timeout);
|
|
2077
2068
|
timeout = null;
|
|
2078
2069
|
if (data === PERMISSION_ERROR) {
|
|
2079
|
-
reject('May not read "BaseSettings"');
|
|
2070
|
+
reject(new Error('May not read "BaseSettings"'));
|
|
2080
2071
|
}
|
|
2081
2072
|
else if (!data || typeof data !== 'object') {
|
|
2082
|
-
reject('Cannot read "BaseSettings"');
|
|
2073
|
+
reject(new Error('Cannot read "BaseSettings"'));
|
|
2083
2074
|
}
|
|
2084
2075
|
else {
|
|
2085
2076
|
resolve(data);
|
|
@@ -2088,29 +2079,28 @@ class Connection {
|
|
|
2088
2079
|
});
|
|
2089
2080
|
});
|
|
2090
2081
|
}
|
|
2091
|
-
return Promise.reject('Not supported');
|
|
2082
|
+
return Promise.reject(new Error('Not supported'));
|
|
2092
2083
|
}
|
|
2093
2084
|
/**
|
|
2094
2085
|
* Write the base settings of a given host.
|
|
2095
|
-
*
|
|
2096
|
-
* @param
|
|
2097
|
-
* @
|
|
2086
|
+
*
|
|
2087
|
+
* @param host The host name.
|
|
2088
|
+
* @param config The new base settings.
|
|
2098
2089
|
*/
|
|
2099
2090
|
writeBaseSettings(host, config) {
|
|
2100
2091
|
if (Connection.isWeb()) {
|
|
2101
|
-
return Promise.reject('Allowed only in admin');
|
|
2092
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2102
2093
|
}
|
|
2103
|
-
return this.checkFeatureSupported('CONTROLLER_READWRITE_BASE_SETTINGS')
|
|
2104
|
-
.then(result => {
|
|
2094
|
+
return this.checkFeatureSupported('CONTROLLER_READWRITE_BASE_SETTINGS').then(result => {
|
|
2105
2095
|
if (result) {
|
|
2106
2096
|
if (!this.connected) {
|
|
2107
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2097
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2108
2098
|
}
|
|
2109
2099
|
return new Promise((resolve, reject) => {
|
|
2110
2100
|
let timeout = setTimeout(() => {
|
|
2111
2101
|
if (timeout) {
|
|
2112
2102
|
timeout = null;
|
|
2113
|
-
reject('writeBaseSettings timeout');
|
|
2103
|
+
reject(new Error('writeBaseSettings timeout'));
|
|
2114
2104
|
}
|
|
2115
2105
|
}, this.props.cmdTimeout);
|
|
2116
2106
|
this._socket.emit('sendToHost', host, 'writeBaseSettings', config, (data) => {
|
|
@@ -2138,23 +2128,23 @@ class Connection {
|
|
|
2138
2128
|
*/
|
|
2139
2129
|
restartController(host) {
|
|
2140
2130
|
if (Connection.isWeb()) {
|
|
2141
|
-
return Promise.reject('Allowed only in admin');
|
|
2131
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2142
2132
|
}
|
|
2143
2133
|
return new Promise((resolve, reject) => {
|
|
2144
2134
|
this._socket.emit('sendToHost', host, 'restartController', null, (error) => {
|
|
2145
|
-
error ? reject(error) : resolve(true);
|
|
2135
|
+
error ? reject(new Error(error)) : resolve(true);
|
|
2146
2136
|
});
|
|
2147
2137
|
});
|
|
2148
2138
|
}
|
|
2149
2139
|
/**
|
|
2150
2140
|
* Read statistics information from host
|
|
2151
|
-
*
|
|
2152
|
-
* @param
|
|
2153
|
-
* @
|
|
2141
|
+
*
|
|
2142
|
+
* @param host Host name
|
|
2143
|
+
* @param typeOfDiag one of none, normal, no-city, extended
|
|
2154
2144
|
*/
|
|
2155
2145
|
getDiagData(host, typeOfDiag) {
|
|
2156
2146
|
if (Connection.isWeb()) {
|
|
2157
|
-
return Promise.reject('Allowed only in admin');
|
|
2147
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2158
2148
|
}
|
|
2159
2149
|
return new Promise(resolve => {
|
|
2160
2150
|
this._socket.emit('sendToHost', host, 'getDiagData', typeOfDiag, (result) => resolve(result));
|
|
@@ -2165,46 +2155,44 @@ class Connection {
|
|
|
2165
2155
|
*/
|
|
2166
2156
|
getForeignStates(pattern) {
|
|
2167
2157
|
if (!this.connected) {
|
|
2168
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2158
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2169
2159
|
}
|
|
2170
2160
|
if (Connection.isWeb()) {
|
|
2171
2161
|
return new Promise((resolve, reject) => {
|
|
2172
|
-
this._socket.emit('getStates', pattern || '*', (err, states) =>
|
|
2162
|
+
this._socket.emit('getStates', pattern || '*', (err, states) => err ? reject(new Error(err)) : resolve(states));
|
|
2173
2163
|
});
|
|
2174
2164
|
}
|
|
2175
2165
|
return new Promise((resolve, reject) => {
|
|
2176
|
-
this._socket.emit('getForeignStates', pattern || '*', (err, states) =>
|
|
2166
|
+
this._socket.emit('getForeignStates', pattern || '*', (err, states) => err ? reject(new Error(err)) : resolve(states));
|
|
2177
2167
|
});
|
|
2178
2168
|
}
|
|
2179
2169
|
/**
|
|
2180
2170
|
* Get foreign objects by pattern, by specific type and resolve their enums. (Only admin)
|
|
2181
|
-
* @returns {ioBroker.GetObjectsPromise}
|
|
2182
2171
|
*/
|
|
2183
2172
|
getForeignObjects(pattern, type) {
|
|
2184
2173
|
if (Connection.isWeb()) {
|
|
2185
|
-
return Promise.reject('Allowed only in admin');
|
|
2174
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2186
2175
|
}
|
|
2187
2176
|
if (!this.connected) {
|
|
2188
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2177
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2189
2178
|
}
|
|
2190
2179
|
return new Promise((resolve, reject) => {
|
|
2191
|
-
this._socket.emit('getForeignObjects', pattern || '*', type, (err, states) =>
|
|
2180
|
+
this._socket.emit('getForeignObjects', pattern || '*', type, (err, states) => err ? reject(new Error(err)) : resolve(states));
|
|
2192
2181
|
});
|
|
2193
2182
|
}
|
|
2194
2183
|
/**
|
|
2195
2184
|
* Gets the system configuration.
|
|
2196
|
-
*
|
|
2197
|
-
* @
|
|
2185
|
+
*
|
|
2186
|
+
* @param update Force update.
|
|
2198
2187
|
*/
|
|
2199
2188
|
getSystemConfig(update) {
|
|
2200
2189
|
if (!update && this._promises.systemConfig) {
|
|
2201
2190
|
return this._promises.systemConfig;
|
|
2202
2191
|
}
|
|
2203
2192
|
if (!this.connected) {
|
|
2204
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2193
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2205
2194
|
}
|
|
2206
|
-
this._promises.systemConfig = this.getObject('system.config')
|
|
2207
|
-
.then(obj => {
|
|
2195
|
+
this._promises.systemConfig = this.getObject('system.config').then(obj => {
|
|
2208
2196
|
const systemConfig = (obj || {});
|
|
2209
2197
|
systemConfig.common = systemConfig.common || {};
|
|
2210
2198
|
systemConfig.native = systemConfig.native || {};
|
|
@@ -2216,8 +2204,7 @@ class Connection {
|
|
|
2216
2204
|
* Sets the system configuration.
|
|
2217
2205
|
*/
|
|
2218
2206
|
setSystemConfig(obj) {
|
|
2219
|
-
return this.setObject('system.config', obj)
|
|
2220
|
-
.then(() => this._promises.systemConfig = Promise.resolve(obj));
|
|
2207
|
+
return this.setObject('system.config', obj).then(() => (this._promises.systemConfig = Promise.resolve(obj)));
|
|
2221
2208
|
}
|
|
2222
2209
|
/**
|
|
2223
2210
|
* Get the raw socket.io socket.
|
|
@@ -2230,10 +2217,10 @@ class Connection {
|
|
|
2230
2217
|
*/
|
|
2231
2218
|
getHistory(id, options) {
|
|
2232
2219
|
if (!this.connected) {
|
|
2233
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2220
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2234
2221
|
}
|
|
2235
2222
|
return new Promise((resolve, reject) => {
|
|
2236
|
-
this._socket.emit('getHistory', id, options, (err, values) =>
|
|
2223
|
+
this._socket.emit('getHistory', id, options, (err, values) => err ? reject(new Error(err)) : resolve(values));
|
|
2237
2224
|
});
|
|
2238
2225
|
}
|
|
2239
2226
|
/**
|
|
@@ -2241,10 +2228,10 @@ class Connection {
|
|
|
2241
2228
|
*/
|
|
2242
2229
|
getHistoryEx(id, options) {
|
|
2243
2230
|
if (!this.connected) {
|
|
2244
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2231
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2245
2232
|
}
|
|
2246
2233
|
return new Promise((resolve, reject) => {
|
|
2247
|
-
this._socket.emit('getHistory', id, options, (err, values, stepIgnore, sessionId) =>
|
|
2234
|
+
this._socket.emit('getHistory', id, options, (err, values, stepIgnore, sessionId) => err ? reject(new Error(err)) : resolve({ values, sessionId, stepIgnore }));
|
|
2248
2235
|
});
|
|
2249
2236
|
}
|
|
2250
2237
|
/**
|
|
@@ -2252,10 +2239,10 @@ class Connection {
|
|
|
2252
2239
|
*/
|
|
2253
2240
|
changePassword(user, password) {
|
|
2254
2241
|
if (Connection.isWeb()) {
|
|
2255
|
-
return Promise.reject('Allowed only in admin');
|
|
2242
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2256
2243
|
}
|
|
2257
2244
|
return new Promise((resolve, reject) => {
|
|
2258
|
-
this._socket.emit('changePassword', user, password, (err) =>
|
|
2245
|
+
this._socket.emit('changePassword', user, password, (err) => err ? reject(new Error(err)) : resolve());
|
|
2259
2246
|
});
|
|
2260
2247
|
}
|
|
2261
2248
|
/**
|
|
@@ -2265,7 +2252,7 @@ class Connection {
|
|
|
2265
2252
|
/** Force update. */
|
|
2266
2253
|
update) {
|
|
2267
2254
|
if (Connection.isWeb()) {
|
|
2268
|
-
return Promise.reject('Allowed only in admin');
|
|
2255
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2269
2256
|
}
|
|
2270
2257
|
if (!host.startsWith('system.host.')) {
|
|
2271
2258
|
host = `system.host.${host}`;
|
|
@@ -2273,8 +2260,7 @@ class Connection {
|
|
|
2273
2260
|
if (!update && this._promises[`IPs_${host}`]) {
|
|
2274
2261
|
return this._promises[`IPs_${host}`];
|
|
2275
2262
|
}
|
|
2276
|
-
this._promises[`IPs_${host}`] = this.getObject(host)
|
|
2277
|
-
.then(obj => ((obj === null || obj === void 0 ? void 0 : obj.common) ? obj.common.address || [] : []));
|
|
2263
|
+
this._promises[`IPs_${host}`] = this.getObject(host).then(obj => ((obj === null || obj === void 0 ? void 0 : obj.common) ? obj.common.address || [] : []));
|
|
2278
2264
|
return this._promises[`IPs_${host}`];
|
|
2279
2265
|
}
|
|
2280
2266
|
/**
|
|
@@ -2284,7 +2270,7 @@ class Connection {
|
|
|
2284
2270
|
/** Force update. */
|
|
2285
2271
|
update) {
|
|
2286
2272
|
if (Connection.isWeb()) {
|
|
2287
|
-
return Promise.reject('Allowed only in admin');
|
|
2273
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2288
2274
|
}
|
|
2289
2275
|
if (ipOrHostName.startsWith('system.host.')) {
|
|
2290
2276
|
ipOrHostName = ipOrHostName.replace(/^system\.host\./, '');
|
|
@@ -2333,10 +2319,10 @@ class Connection {
|
|
|
2333
2319
|
*/
|
|
2334
2320
|
encrypt(text) {
|
|
2335
2321
|
if (Connection.isWeb()) {
|
|
2336
|
-
return Promise.reject('Allowed only in admin');
|
|
2322
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2337
2323
|
}
|
|
2338
2324
|
return new Promise((resolve, reject) => {
|
|
2339
|
-
this._socket.emit('encrypt', text, (err, _text) =>
|
|
2325
|
+
this._socket.emit('encrypt', text, (err, _text) => err ? reject(new Error(err)) : resolve(_text));
|
|
2340
2326
|
});
|
|
2341
2327
|
}
|
|
2342
2328
|
/**
|
|
@@ -2344,45 +2330,48 @@ class Connection {
|
|
|
2344
2330
|
*/
|
|
2345
2331
|
decrypt(encryptedText) {
|
|
2346
2332
|
if (Connection.isWeb()) {
|
|
2347
|
-
return Promise.reject('Allowed only in admin');
|
|
2333
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2348
2334
|
}
|
|
2349
2335
|
return new Promise((resolve, reject) => {
|
|
2350
|
-
this._socket.emit('decrypt', encryptedText, (err, text) =>
|
|
2336
|
+
this._socket.emit('decrypt', encryptedText, (err, text) => err ? reject(new Error(err)) : resolve(text));
|
|
2351
2337
|
});
|
|
2352
2338
|
}
|
|
2353
2339
|
/**
|
|
2354
2340
|
* Gets the version.
|
|
2355
|
-
* @returns {Promise<{version: string; serverName: string}>}
|
|
2356
2341
|
*/
|
|
2357
2342
|
getVersion(update) {
|
|
2358
2343
|
if (update && this._promises.version) {
|
|
2359
2344
|
delete this._promises.version;
|
|
2360
2345
|
}
|
|
2361
|
-
this._promises.version =
|
|
2362
|
-
this.
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2346
|
+
this._promises.version =
|
|
2347
|
+
this._promises.version ||
|
|
2348
|
+
new Promise((resolve, reject) => {
|
|
2349
|
+
this._socket.emit('getVersion', (err, version, serverName) => {
|
|
2350
|
+
// support of old socket.io
|
|
2351
|
+
if (err && !version && typeof err === 'string' && err.match(/\d+\.\d+\.\d+/)) {
|
|
2352
|
+
resolve({ version: err, serverName: 'socketio' });
|
|
2353
|
+
}
|
|
2354
|
+
else {
|
|
2355
|
+
err ? reject(new Error(err)) : resolve({ version, serverName });
|
|
2356
|
+
}
|
|
2357
|
+
});
|
|
2358
|
+
});
|
|
2372
2359
|
return this._promises.version;
|
|
2373
2360
|
}
|
|
2374
2361
|
/**
|
|
2375
2362
|
* Gets the web server name.
|
|
2376
|
-
* @returns {Promise<string>}
|
|
2377
2363
|
*/
|
|
2378
2364
|
getWebServerName() {
|
|
2379
|
-
this._promises.webName =
|
|
2380
|
-
this.
|
|
2381
|
-
|
|
2365
|
+
this._promises.webName =
|
|
2366
|
+
this._promises.webName ||
|
|
2367
|
+
new Promise((resolve, reject) => {
|
|
2368
|
+
this._socket.emit('getAdapterName', (err, name) => err ? reject(new Error(err)) : resolve(name));
|
|
2369
|
+
});
|
|
2382
2370
|
return this._promises.webName;
|
|
2383
2371
|
}
|
|
2384
2372
|
/**
|
|
2385
2373
|
* Gets the admin version.
|
|
2374
|
+
*
|
|
2386
2375
|
* @deprecated use getVersion()
|
|
2387
2376
|
*/
|
|
2388
2377
|
getAdminVersion() {
|
|
@@ -2390,68 +2379,67 @@ class Connection {
|
|
|
2390
2379
|
return this.getVersion();
|
|
2391
2380
|
}
|
|
2392
2381
|
/**
|
|
2393
|
-
* Change access rights for file
|
|
2382
|
+
* Change access rights for a file
|
|
2383
|
+
*
|
|
2384
|
+
* @param adapter The adapter name.
|
|
2385
|
+
* @param fileName file name with a full path. It could be like vis.0/*
|
|
2386
|
+
* @param options like {mode: 0x644}
|
|
2387
|
+
* @param options.mode Access rights. Default is 0x644
|
|
2394
2388
|
*/
|
|
2395
|
-
chmodFile(
|
|
2396
|
-
/** adapter name */
|
|
2397
|
-
adapter,
|
|
2398
|
-
/** file name with a full path. It could be like vis.0/* */
|
|
2399
|
-
filename,
|
|
2400
|
-
/** like {mode: 0x644} */
|
|
2401
|
-
options) {
|
|
2389
|
+
chmodFile(adapter, fileName, options) {
|
|
2402
2390
|
if (Connection.isWeb()) {
|
|
2403
|
-
return Promise.reject('Allowed only in admin');
|
|
2391
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2404
2392
|
}
|
|
2405
2393
|
if (!this.connected) {
|
|
2406
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2394
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2407
2395
|
}
|
|
2408
2396
|
return new Promise((resolve, reject) => {
|
|
2409
|
-
this._socket.emit('chmodFile', adapter,
|
|
2397
|
+
this._socket.emit('chmodFile', adapter, fileName, options, (err, entries, id) => err ? reject(new Error(err)) : resolve({ entries, id }));
|
|
2410
2398
|
});
|
|
2411
2399
|
}
|
|
2412
2400
|
/**
|
|
2413
|
-
* Change an owner or/and owner group for file
|
|
2401
|
+
* Change an owner or/and owner group for a file
|
|
2402
|
+
*
|
|
2403
|
+
* @param adapter The adapter name.
|
|
2404
|
+
* @param fileName file name with a full path. It could be like vis.0/*
|
|
2405
|
+
* @param options like {owner: 'user', ownerGroup: 'group'}
|
|
2406
|
+
* @param options.owner User name
|
|
2407
|
+
* @param options.ownerGroup Group name
|
|
2414
2408
|
*/
|
|
2415
|
-
chownFile(
|
|
2416
|
-
/** adapter name */
|
|
2417
|
-
adapter,
|
|
2418
|
-
/** file name with a full path. It could be like vis.0/* */
|
|
2419
|
-
fileName, options) {
|
|
2409
|
+
chownFile(adapter, fileName, options) {
|
|
2420
2410
|
if (Connection.isWeb()) {
|
|
2421
|
-
return Promise.reject('Allowed only in admin');
|
|
2411
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2422
2412
|
}
|
|
2423
2413
|
if (!this.connected) {
|
|
2424
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2414
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2425
2415
|
}
|
|
2426
2416
|
return new Promise((resolve, reject) => {
|
|
2427
|
-
this._socket.emit('chownFile', adapter, fileName, options, (err, entries, id) =>
|
|
2417
|
+
this._socket.emit('chownFile', adapter, fileName, options, (err, entries, id) => err ? reject(new Error(err)) : resolve({ entries, id }));
|
|
2428
2418
|
});
|
|
2429
2419
|
}
|
|
2430
2420
|
/**
|
|
2431
2421
|
* Check if the file exists
|
|
2422
|
+
*
|
|
2423
|
+
* @param adapter The adapter name.
|
|
2424
|
+
* @param fileName file name with a full path. It could be like vis.0/*
|
|
2432
2425
|
*/
|
|
2433
|
-
fileExists(
|
|
2434
|
-
/** adapter name */
|
|
2435
|
-
adapter,
|
|
2436
|
-
/** file name with a full path. It could be like vis.0/* */
|
|
2437
|
-
fileName) {
|
|
2426
|
+
fileExists(adapter, fileName) {
|
|
2438
2427
|
if (!this.connected) {
|
|
2439
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2428
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2440
2429
|
}
|
|
2441
2430
|
return new Promise((resolve, reject) => {
|
|
2442
|
-
this._socket.emit('fileExists', adapter, fileName, (err, exists) =>
|
|
2431
|
+
this._socket.emit('fileExists', adapter, fileName, (err, exists) => err ? reject(new Error(err)) : resolve(exists));
|
|
2443
2432
|
});
|
|
2444
2433
|
}
|
|
2445
2434
|
/**
|
|
2446
2435
|
* Get the alarm notifications from a host (only for admin connection).
|
|
2447
|
-
* @returns {Promise<any>}
|
|
2448
2436
|
*/
|
|
2449
2437
|
getNotifications(host, category) {
|
|
2450
2438
|
if (Connection.isWeb()) {
|
|
2451
|
-
return Promise.reject('Allowed only in admin');
|
|
2439
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2452
2440
|
}
|
|
2453
2441
|
if (!this.connected) {
|
|
2454
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2442
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2455
2443
|
}
|
|
2456
2444
|
return new Promise(resolve => {
|
|
2457
2445
|
this._socket.emit('sendToHost', host, 'getNotifications', { category }, (notifications) => resolve(notifications));
|
|
@@ -2459,16 +2447,16 @@ class Connection {
|
|
|
2459
2447
|
}
|
|
2460
2448
|
/**
|
|
2461
2449
|
* Clear the alarm notifications on a host (only for admin connection).
|
|
2462
|
-
*
|
|
2463
|
-
* @param
|
|
2464
|
-
* @
|
|
2450
|
+
*
|
|
2451
|
+
* @param host The host name.
|
|
2452
|
+
* @param category optional
|
|
2465
2453
|
*/
|
|
2466
2454
|
clearNotifications(host, category) {
|
|
2467
2455
|
if (Connection.isWeb()) {
|
|
2468
|
-
return Promise.reject('Allowed only in admin');
|
|
2456
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2469
2457
|
}
|
|
2470
2458
|
if (!this.connected) {
|
|
2471
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2459
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2472
2460
|
}
|
|
2473
2461
|
return new Promise(resolve => {
|
|
2474
2462
|
this._socket.emit('sendToHost', host, 'clearNotifications', { category }, (result) => resolve(result));
|
|
@@ -2479,37 +2467,35 @@ class Connection {
|
|
|
2479
2467
|
*/
|
|
2480
2468
|
getIsEasyModeStrict() {
|
|
2481
2469
|
if (Connection.isWeb()) {
|
|
2482
|
-
return Promise.reject('Allowed only in admin');
|
|
2470
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2483
2471
|
}
|
|
2484
2472
|
if (!this.connected) {
|
|
2485
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2473
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2486
2474
|
}
|
|
2487
2475
|
return new Promise((resolve, reject) => {
|
|
2488
|
-
this._socket.emit('getIsEasyModeStrict', (error, isStrict) =>
|
|
2476
|
+
this._socket.emit('getIsEasyModeStrict', (error, isStrict) => error ? reject(new Error(error)) : resolve(isStrict));
|
|
2489
2477
|
});
|
|
2490
2478
|
}
|
|
2491
2479
|
/**
|
|
2492
2480
|
* Read easy mode configuration (only for admin connection).
|
|
2493
|
-
* @returns {Promise<any>}
|
|
2494
2481
|
*/
|
|
2495
2482
|
getEasyMode() {
|
|
2496
2483
|
if (Connection.isWeb()) {
|
|
2497
|
-
return Promise.reject('Allowed only in admin');
|
|
2484
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2498
2485
|
}
|
|
2499
2486
|
if (!this.connected) {
|
|
2500
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2487
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2501
2488
|
}
|
|
2502
2489
|
return new Promise((resolve, reject) => {
|
|
2503
|
-
this._socket.emit('getEasyMode', (error, config) =>
|
|
2490
|
+
this._socket.emit('getEasyMode', (error, config) => error ? reject(new Error(error)) : resolve(config));
|
|
2504
2491
|
});
|
|
2505
2492
|
}
|
|
2506
2493
|
/**
|
|
2507
2494
|
* Read current user
|
|
2508
|
-
* @returns {Promise<string>}
|
|
2509
2495
|
*/
|
|
2510
2496
|
getCurrentUser() {
|
|
2511
2497
|
if (!this.connected) {
|
|
2512
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2498
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2513
2499
|
}
|
|
2514
2500
|
return new Promise(resolve => {
|
|
2515
2501
|
this._socket.emit('authEnabled', (isSecure, user) => resolve(user));
|
|
@@ -2517,7 +2503,7 @@ class Connection {
|
|
|
2517
2503
|
}
|
|
2518
2504
|
getCurrentSession(cmdTimeout) {
|
|
2519
2505
|
if (!this.connected) {
|
|
2520
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2506
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2521
2507
|
}
|
|
2522
2508
|
return new Promise((resolve, reject) => {
|
|
2523
2509
|
const controller = new AbortController();
|
|
@@ -2525,7 +2511,7 @@ class Connection {
|
|
|
2525
2511
|
if (timeout) {
|
|
2526
2512
|
timeout = null;
|
|
2527
2513
|
controller.abort();
|
|
2528
|
-
reject('getCurrentSession timeout');
|
|
2514
|
+
reject(new Error('getCurrentSession timeout'));
|
|
2529
2515
|
}
|
|
2530
2516
|
}, cmdTimeout || 5000);
|
|
2531
2517
|
fetch('./session', { signal: controller.signal })
|
|
@@ -2537,22 +2523,21 @@ class Connection {
|
|
|
2537
2523
|
resolve(json);
|
|
2538
2524
|
}
|
|
2539
2525
|
})
|
|
2540
|
-
.catch(e => reject(`getCurrentSession: ${e}`));
|
|
2526
|
+
.catch(e => reject(new Error(`getCurrentSession: ${e}`)));
|
|
2541
2527
|
});
|
|
2542
2528
|
}
|
|
2543
2529
|
/**
|
|
2544
2530
|
* Read adapter ratings
|
|
2545
|
-
* @returns {Promise<any>}
|
|
2546
2531
|
*/
|
|
2547
2532
|
getRatings(update) {
|
|
2548
2533
|
if (Connection.isWeb()) {
|
|
2549
|
-
return Promise.reject('Allowed only in admin');
|
|
2534
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2550
2535
|
}
|
|
2551
2536
|
if (!this.connected) {
|
|
2552
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2537
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2553
2538
|
}
|
|
2554
2539
|
return new Promise((resolve, reject) => {
|
|
2555
|
-
this._socket.emit('getRatings', update, (err, ratings) =>
|
|
2540
|
+
this._socket.emit('getRatings', update, (err, ratings) => err ? reject(new Error(err)) : resolve(ratings));
|
|
2556
2541
|
});
|
|
2557
2542
|
}
|
|
2558
2543
|
/**
|
|
@@ -2560,27 +2545,28 @@ class Connection {
|
|
|
2560
2545
|
*/
|
|
2561
2546
|
getCurrentInstance() {
|
|
2562
2547
|
if (!this.connected) {
|
|
2563
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2548
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2564
2549
|
}
|
|
2565
|
-
this._promises.currentInstance =
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2550
|
+
this._promises.currentInstance =
|
|
2551
|
+
this._promises.currentInstance ||
|
|
2552
|
+
new Promise((resolve, reject) => {
|
|
2553
|
+
this._socket.emit('getCurrentInstance', (err, namespace) => err ? reject(new Error(err)) : resolve(namespace));
|
|
2554
|
+
});
|
|
2569
2555
|
return this._promises.currentInstance;
|
|
2570
2556
|
}
|
|
2571
2557
|
// returns very optimized information for adapters to minimize a connection load
|
|
2572
2558
|
getCompactAdapters(update) {
|
|
2573
2559
|
if (Connection.isWeb()) {
|
|
2574
|
-
return Promise.reject('Allowed only in admin');
|
|
2560
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2575
2561
|
}
|
|
2576
2562
|
if (!update && this._promises.compactAdapters) {
|
|
2577
2563
|
return this._promises.compactAdapters;
|
|
2578
2564
|
}
|
|
2579
2565
|
if (!this.connected) {
|
|
2580
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2566
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2581
2567
|
}
|
|
2582
2568
|
this._promises.compactAdapters = new Promise((resolve, reject) => {
|
|
2583
|
-
this._socket.emit('getCompactAdapters', (err, adapters) =>
|
|
2569
|
+
this._socket.emit('getCompactAdapters', (err, adapters) => err ? reject(new Error(err)) : resolve(adapters));
|
|
2584
2570
|
});
|
|
2585
2571
|
return this._promises.compactAdapters;
|
|
2586
2572
|
}
|
|
@@ -2592,16 +2578,16 @@ class Connection {
|
|
|
2592
2578
|
// returns very optimized information for adapters to minimize a connection load
|
|
2593
2579
|
getCompactInstances(update) {
|
|
2594
2580
|
if (Connection.isWeb()) {
|
|
2595
|
-
return Promise.reject('Allowed only in admin');
|
|
2581
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2596
2582
|
}
|
|
2597
2583
|
if (!update && this._promises.compactInstances) {
|
|
2598
2584
|
return this._promises.compactInstances;
|
|
2599
2585
|
}
|
|
2600
2586
|
if (!this.connected) {
|
|
2601
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2587
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2602
2588
|
}
|
|
2603
2589
|
this._promises.compactInstances = new Promise((resolve, reject) => {
|
|
2604
|
-
this._socket.emit('getCompactInstances', (err, instances) =>
|
|
2590
|
+
this._socket.emit('getCompactInstances', (err, instances) => err ? reject(new Error(err)) : resolve(instances));
|
|
2605
2591
|
});
|
|
2606
2592
|
return this._promises.compactInstances;
|
|
2607
2593
|
}
|
|
@@ -2616,14 +2602,14 @@ class Connection {
|
|
|
2616
2602
|
*/
|
|
2617
2603
|
getCompactInstalled(host, update, cmdTimeout) {
|
|
2618
2604
|
if (Connection.isWeb()) {
|
|
2619
|
-
return Promise.reject('Allowed only in admin');
|
|
2605
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2620
2606
|
}
|
|
2621
2607
|
this._promises.installedCompact = this._promises.installedCompact || {};
|
|
2622
2608
|
if (!update && this._promises.installedCompact[host]) {
|
|
2623
2609
|
return this._promises.installedCompact[host];
|
|
2624
2610
|
}
|
|
2625
2611
|
if (!this.connected) {
|
|
2626
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2612
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2627
2613
|
}
|
|
2628
2614
|
if (!host.startsWith('system.host.')) {
|
|
2629
2615
|
host += `system.host.${host}`;
|
|
@@ -2632,7 +2618,7 @@ class Connection {
|
|
|
2632
2618
|
let timeout = setTimeout(() => {
|
|
2633
2619
|
if (timeout) {
|
|
2634
2620
|
timeout = null;
|
|
2635
|
-
reject('getCompactInstalled timeout');
|
|
2621
|
+
reject(new Error('getCompactInstalled timeout'));
|
|
2636
2622
|
}
|
|
2637
2623
|
}, cmdTimeout || this.props.cmdTimeout);
|
|
2638
2624
|
this._socket.emit('getCompactInstalled', host, (data) => {
|
|
@@ -2640,10 +2626,10 @@ class Connection {
|
|
|
2640
2626
|
clearTimeout(timeout);
|
|
2641
2627
|
timeout = null;
|
|
2642
2628
|
if (data === PERMISSION_ERROR) {
|
|
2643
|
-
reject('May not read "getCompactInstalled"');
|
|
2629
|
+
reject(new Error('May not read "getCompactInstalled"'));
|
|
2644
2630
|
}
|
|
2645
2631
|
else if (!data || typeof data !== 'object') {
|
|
2646
|
-
reject('Cannot read "getCompactInstalled"');
|
|
2632
|
+
reject(new Error('Cannot read "getCompactInstalled"'));
|
|
2647
2633
|
}
|
|
2648
2634
|
else {
|
|
2649
2635
|
resolve(data);
|
|
@@ -2657,19 +2643,19 @@ class Connection {
|
|
|
2657
2643
|
// reads only version of installed adapter
|
|
2658
2644
|
getCompactSystemRepositories(update, cmdTimeout) {
|
|
2659
2645
|
if (Connection.isWeb()) {
|
|
2660
|
-
return Promise.reject('Allowed only in admin');
|
|
2646
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2661
2647
|
}
|
|
2662
2648
|
if (!update && this._promises.getCompactSystemRepositories) {
|
|
2663
2649
|
return this._promises.getCompactSystemRepositories;
|
|
2664
2650
|
}
|
|
2665
2651
|
if (!this.connected) {
|
|
2666
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2652
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2667
2653
|
}
|
|
2668
2654
|
this._promises.getCompactSystemRepositories = new Promise((resolve, reject) => {
|
|
2669
2655
|
let timeout = setTimeout(() => {
|
|
2670
2656
|
if (timeout) {
|
|
2671
2657
|
timeout = null;
|
|
2672
|
-
reject('getCompactSystemRepositories timeout');
|
|
2658
|
+
reject(new Error('getCompactSystemRepositories timeout'));
|
|
2673
2659
|
}
|
|
2674
2660
|
}, cmdTimeout || this.props.cmdTimeout);
|
|
2675
2661
|
this._socket.emit('getCompactSystemRepositories', (data) => {
|
|
@@ -2677,10 +2663,10 @@ class Connection {
|
|
|
2677
2663
|
clearTimeout(timeout);
|
|
2678
2664
|
timeout = null;
|
|
2679
2665
|
if (data === PERMISSION_ERROR) {
|
|
2680
|
-
reject('May not read "getCompactSystemRepositories"');
|
|
2666
|
+
reject(new Error('May not read "getCompactSystemRepositories"'));
|
|
2681
2667
|
}
|
|
2682
2668
|
else if (!data || typeof data !== 'object') {
|
|
2683
|
-
reject('Cannot read "getCompactSystemRepositories"');
|
|
2669
|
+
reject(new Error('Cannot read "getCompactSystemRepositories"'));
|
|
2684
2670
|
}
|
|
2685
2671
|
else {
|
|
2686
2672
|
resolve(data);
|
|
@@ -2696,29 +2682,29 @@ class Connection {
|
|
|
2696
2682
|
return this._promises.systemConfigPromise;
|
|
2697
2683
|
}
|
|
2698
2684
|
if (!this.connected) {
|
|
2699
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2685
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2700
2686
|
}
|
|
2701
2687
|
this._promises.systemConfigPromise = new Promise((resolve, reject) => {
|
|
2702
|
-
this._socket.emit('getCompactSystemConfig', (err, systemConfig) =>
|
|
2688
|
+
this._socket.emit('getCompactSystemConfig', (err, systemConfig) => err ? reject(new Error(err)) : resolve(systemConfig));
|
|
2703
2689
|
});
|
|
2704
2690
|
return this._promises.systemConfigPromise;
|
|
2705
2691
|
}
|
|
2706
2692
|
/**
|
|
2707
2693
|
* Get the repository in compact form (only version and icon).
|
|
2708
|
-
*
|
|
2709
|
-
* @param
|
|
2710
|
-
* @param
|
|
2711
|
-
* @
|
|
2694
|
+
*
|
|
2695
|
+
* @param host The host name.
|
|
2696
|
+
* @param update Force update.
|
|
2697
|
+
* @param timeoutMs timeout in ms.
|
|
2712
2698
|
*/
|
|
2713
2699
|
getCompactRepository(host, update, timeoutMs) {
|
|
2714
2700
|
if (Connection.isWeb()) {
|
|
2715
|
-
return Promise.reject('Allowed only in admin');
|
|
2701
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2716
2702
|
}
|
|
2717
2703
|
if (!update && this._promises.repoCompact) {
|
|
2718
2704
|
return this._promises.repoCompact;
|
|
2719
2705
|
}
|
|
2720
2706
|
if (!this.connected) {
|
|
2721
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2707
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2722
2708
|
}
|
|
2723
2709
|
if (!host.startsWith('system.host.')) {
|
|
2724
2710
|
host += `system.host.${host}`;
|
|
@@ -2727,7 +2713,7 @@ class Connection {
|
|
|
2727
2713
|
let timeout = setTimeout(() => {
|
|
2728
2714
|
if (timeout) {
|
|
2729
2715
|
timeout = null;
|
|
2730
|
-
reject('getCompactRepository timeout');
|
|
2716
|
+
reject(new Error('getCompactRepository timeout'));
|
|
2731
2717
|
}
|
|
2732
2718
|
}, timeoutMs || this.props.cmdTimeout);
|
|
2733
2719
|
this._socket.emit('getCompactRepository', host, (data) => {
|
|
@@ -2735,10 +2721,10 @@ class Connection {
|
|
|
2735
2721
|
clearTimeout(timeout);
|
|
2736
2722
|
timeout = null;
|
|
2737
2723
|
if (data === PERMISSION_ERROR) {
|
|
2738
|
-
reject('May not read "getCompactRepository"');
|
|
2724
|
+
reject(new Error('May not read "getCompactRepository"'));
|
|
2739
2725
|
}
|
|
2740
2726
|
else if (!data) {
|
|
2741
|
-
reject('Cannot read "getCompactRepository"');
|
|
2727
|
+
reject(new Error('Cannot read "getCompactRepository"'));
|
|
2742
2728
|
}
|
|
2743
2729
|
else {
|
|
2744
2730
|
resolve(data);
|
|
@@ -2757,16 +2743,16 @@ class Connection {
|
|
|
2757
2743
|
*/
|
|
2758
2744
|
getCompactHosts(update) {
|
|
2759
2745
|
if (Connection.isWeb()) {
|
|
2760
|
-
return Promise.reject('Allowed only in admin');
|
|
2746
|
+
return Promise.reject(new Error('Allowed only in admin'));
|
|
2761
2747
|
}
|
|
2762
2748
|
if (!update && this._promises.hostsCompact) {
|
|
2763
2749
|
return this._promises.hostsCompact;
|
|
2764
2750
|
}
|
|
2765
2751
|
if (!this.connected) {
|
|
2766
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2752
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2767
2753
|
}
|
|
2768
2754
|
this._promises.hostsCompact = new Promise((resolve, reject) => {
|
|
2769
|
-
this._socket.emit('getCompactHosts', (err, hosts) =>
|
|
2755
|
+
this._socket.emit('getCompactHosts', (err, hosts) => err ? reject(new Error(err)) : resolve(hosts));
|
|
2770
2756
|
});
|
|
2771
2757
|
return this._promises.hostsCompact;
|
|
2772
2758
|
}
|
|
@@ -2778,37 +2764,30 @@ class Connection {
|
|
|
2778
2764
|
return this._promises.uuid;
|
|
2779
2765
|
}
|
|
2780
2766
|
if (!this.connected) {
|
|
2781
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2767
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2782
2768
|
}
|
|
2783
|
-
this._promises.uuid = this.getObject('system.meta.uuid')
|
|
2784
|
-
.then(obj => { var _a; return (_a = obj === null || obj === void 0 ? void 0 : obj.native) === null || _a === void 0 ? void 0 : _a.uuid; });
|
|
2769
|
+
this._promises.uuid = this.getObject('system.meta.uuid').then(obj => { var _a; return (_a = obj === null || obj === void 0 ? void 0 : obj.native) === null || _a === void 0 ? void 0 : _a.uuid; });
|
|
2785
2770
|
return this._promises.uuid;
|
|
2786
2771
|
}
|
|
2787
2772
|
/**
|
|
2788
2773
|
* Subscribe on instance message
|
|
2789
|
-
*
|
|
2790
|
-
* @param
|
|
2791
|
-
* @param
|
|
2792
|
-
* @param
|
|
2793
|
-
* @
|
|
2794
|
-
*/
|
|
2795
|
-
subscribeOnInstance(
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
/** message type like 'startCamera/cam3' */
|
|
2799
|
-
messageType, data,
|
|
2800
|
-
/** message handler. Could be null if all callbacks for this messageType should be unsubscribed */
|
|
2801
|
-
callback) {
|
|
2802
|
-
if (!this.connected) {
|
|
2803
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2774
|
+
*
|
|
2775
|
+
* @param targetInstance instance, like 'cameras.0'
|
|
2776
|
+
* @param messageType message type like 'startCamera/cam3'
|
|
2777
|
+
* @param data optional data object
|
|
2778
|
+
* @param callback message handler
|
|
2779
|
+
*/
|
|
2780
|
+
subscribeOnInstance(targetInstance, messageType, data, callback) {
|
|
2781
|
+
if (!this.connected) {
|
|
2782
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2804
2783
|
}
|
|
2805
2784
|
return new Promise((resolve, reject) => {
|
|
2806
2785
|
this._socket.emit('clientSubscribe', targetInstance, messageType, data, (err, result) => {
|
|
2807
2786
|
if (err) {
|
|
2808
|
-
reject(err);
|
|
2787
|
+
reject(new Error(err));
|
|
2809
2788
|
}
|
|
2810
|
-
else if (result
|
|
2811
|
-
reject(result.error);
|
|
2789
|
+
else if (result === null || result === void 0 ? void 0 : result.error) {
|
|
2790
|
+
reject(new Error(result.error));
|
|
2812
2791
|
}
|
|
2813
2792
|
else {
|
|
2814
2793
|
if (!targetInstance.startsWith('system.adapter.')) {
|
|
@@ -2816,8 +2795,7 @@ class Connection {
|
|
|
2816
2795
|
}
|
|
2817
2796
|
// save callback
|
|
2818
2797
|
this._instanceSubscriptions[targetInstance] = this._instanceSubscriptions[targetInstance] || [];
|
|
2819
|
-
if (!this._instanceSubscriptions[targetInstance].find(sub => sub.messageType === messageType &&
|
|
2820
|
-
sub.callback === callback)) {
|
|
2798
|
+
if (!this._instanceSubscriptions[targetInstance].find(sub => sub.messageType === messageType && sub.callback === callback)) {
|
|
2821
2799
|
this._instanceSubscriptions[targetInstance].push({
|
|
2822
2800
|
messageType,
|
|
2823
2801
|
callback,
|
|
@@ -2830,14 +2808,12 @@ class Connection {
|
|
|
2830
2808
|
}
|
|
2831
2809
|
/**
|
|
2832
2810
|
* Unsubscribe from instance message
|
|
2811
|
+
*
|
|
2812
|
+
* @param targetInstance instance, like 'cameras.0'
|
|
2813
|
+
* @param messageType message type like 'startCamera/cam3'
|
|
2814
|
+
* @param callback message handler. Could be null if all callbacks for this messageType should be unsubscribed
|
|
2833
2815
|
*/
|
|
2834
|
-
unsubscribeFromInstance(
|
|
2835
|
-
/** instance, like 'cameras.0' */
|
|
2836
|
-
targetInstance,
|
|
2837
|
-
/** message type like 'startCamera/cam3' */
|
|
2838
|
-
messageType,
|
|
2839
|
-
/** message handler. Could be null if all callbacks for this messageType should be unsubscribed */
|
|
2840
|
-
callback) {
|
|
2816
|
+
unsubscribeFromInstance(targetInstance, messageType, callback) {
|
|
2841
2817
|
var _a;
|
|
2842
2818
|
if (!targetInstance.startsWith('system.adapter.')) {
|
|
2843
2819
|
targetInstance = `system.adapter.${targetInstance}`;
|
|
@@ -2862,7 +2838,7 @@ class Connection {
|
|
|
2862
2838
|
promiseResults.push(new Promise((resolve, reject) => {
|
|
2863
2839
|
this._socket.emit('clientUnsubscribe', targetInstance, messageType, (err, wasSubscribed) => {
|
|
2864
2840
|
if (err) {
|
|
2865
|
-
reject(err);
|
|
2841
|
+
reject(new Error(err));
|
|
2866
2842
|
}
|
|
2867
2843
|
else {
|
|
2868
2844
|
resolve(wasSubscribed);
|
|
@@ -2873,8 +2849,7 @@ class Connection {
|
|
|
2873
2849
|
}
|
|
2874
2850
|
} while (deleted && (!callback || !messageType));
|
|
2875
2851
|
if (promiseResults.length) {
|
|
2876
|
-
return Promise.all(promiseResults)
|
|
2877
|
-
.then((results) => results.find(result => result) || false);
|
|
2852
|
+
return Promise.all(promiseResults).then((results) => results.find(result => result) || false);
|
|
2878
2853
|
}
|
|
2879
2854
|
return Promise.resolve(false);
|
|
2880
2855
|
}
|
|
@@ -2886,19 +2861,19 @@ class Connection {
|
|
|
2886
2861
|
}
|
|
2887
2862
|
/**
|
|
2888
2863
|
* Logout current user
|
|
2889
|
-
* @returns {Promise<null>}
|
|
2890
2864
|
*/
|
|
2891
2865
|
logout() {
|
|
2892
2866
|
if (!this.connected) {
|
|
2893
|
-
return Promise.reject(NOT_CONNECTED);
|
|
2867
|
+
return Promise.reject(new Error(NOT_CONNECTED));
|
|
2894
2868
|
}
|
|
2895
2869
|
return new Promise((resolve, reject) => {
|
|
2896
|
-
this._socket.emit('logout', (err) => (err ? reject(err) : resolve()));
|
|
2870
|
+
this._socket.emit('logout', (err) => (err ? reject(new Error(err)) : resolve()));
|
|
2897
2871
|
});
|
|
2898
2872
|
}
|
|
2899
2873
|
/**
|
|
2900
2874
|
* This is a special method for vis.
|
|
2901
2875
|
* It is used to not send to server the changes about "nothing_selected" state
|
|
2876
|
+
*
|
|
2902
2877
|
* @param id The state that has to be ignored by communication
|
|
2903
2878
|
*/
|
|
2904
2879
|
setStateToIgnore(id) {
|