iobroker.iot 4.0.1 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/admin/assets/index-5zouxn2w.js +680 -0
- package/admin/index_m.html +1 -1
- package/admin/rules/assets/{ActionVisu-DE8dgNVF.js → ActionVisu-D9x2f6zu.js} +1 -1
- package/admin/rules/assets/{ActionVisu__loadShare__react__loadShare__-BKaC-p5K.js → ActionVisu__loadShare__react__loadShare__-Cg21Ef1U.js} +1 -1
- package/admin/rules/assets/{ActionVisu__loadShare__react_mf_2_dom__loadShare__-Bs1o8DtQ.js → ActionVisu__loadShare__react_mf_2_dom__loadShare__-B1zRWn0u.js} +2 -2
- package/admin/rules/assets/ActionVisu__mf_v__runtimeInit__mf_v__-Cz053nO7.js +10 -0
- package/admin/rules/assets/bootstrap-BCFKIiwZ.js +1 -0
- package/admin/rules/assets/hostInit-hos3Txsy.js +1 -1
- package/admin/rules/assets/{index-DjPMvPni.js → index-CAAeiKCc.js} +2 -2
- package/admin/rules/assets/{index-CbxmbJvB.js → index-Duo7mFlZ.js} +2 -2
- package/admin/rules/assets/index-DwYdaT5M.js +1151 -0
- package/admin/rules/assets/{virtualExposes-BNZJTatg.js → virtualExposes-BqVak7rX.js} +2 -2
- package/admin/rules/customRuleBlocks.js +2 -2
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/AlexaResponse.js +268 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/AlexaResponse.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/Base.js +110 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/Base.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/BrightnessController.js +19 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/BrightnessController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorController.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorTemperatureController.js +19 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorTemperatureController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ContactSensor.js +16 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ContactSensor.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/LockController.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/LockController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ModeController.js +68 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ModeController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/MotionSensor.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/MotionSensor.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/PercentageController.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/PercentageController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/PowerController.js +19 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/PowerController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/Speaker.js +25 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/Speaker.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/TemperatureSensor.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/TemperatureSensor.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ThermostatController.js +37 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ThermostatController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/index.js +32 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/index.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/Base.js +29 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/Base.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/ChangeReport.js +82 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/ChangeReport.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/Discovery.js +39 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/Discovery.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/ReportState.js +47 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/ReportState.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/index.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/index.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Base.js +36 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Base.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Closed.js +57 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Closed.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Open.js +57 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Open.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/index.js +12 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/index.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/AdjustableProperty.js +16 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/AdjustableProperty.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Base.js +127 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Base.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Brightness.js +18 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Brightness.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Color.js +38 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Color.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/ColorTemperatureInKelvin.js +53 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/ColorTemperatureInKelvin.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/DetectionState.js +23 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/DetectionState.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/LockState.js +37 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/LockState.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Mode.js +34 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Mode.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Muted.js +19 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Muted.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Percentage.js +18 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Percentage.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/PowerState.js +25 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/PowerState.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/TargetSetpoint.js +31 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/TargetSetpoint.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Temperature.js +22 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Temperature.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/ThermostatMode.js +49 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/ThermostatMode.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Volume.js +21 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Volume.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/index.js +38 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/index.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AdjustableControl.js +20 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AdjustableControl.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AdjustablePercentageControl.js +26 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AdjustablePercentageControl.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AirCondition.js +148 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AirCondition.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Blind.js +13 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Blind.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/ContactSensor.js +17 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/ContactSensor.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Control.js +321 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Control.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Ct.js +182 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Ct.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Dimmer.js +127 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Dimmer.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Door.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Door.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Gate.js +38 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Gate.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Hue.js +208 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Hue.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Light.js +47 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Light.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Lock.js +35 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Lock.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Motion.js +17 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Motion.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/ReadOnlyDetector.js +26 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/ReadOnlyDetector.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Slider.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Slider.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Socket.js +21 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Socket.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Temperature.js +21 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Temperature.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Thermostat.js +85 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Thermostat.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/VacuumCleaner.js +27 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/VacuumCleaner.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Volume.js +116 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Volume.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/VolumeGroup.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/VolumeGroup.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Window.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Window.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/index.js +121 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/index.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Device.js +83 -0
- package/build-backend/lib/AlexaSmartHomeV3/Device.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/DeviceManager.js +392 -0
- package/build-backend/lib/AlexaSmartHomeV3/DeviceManager.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/AlexaV3Exception.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/AlexaV3Exception.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/HourlyDeviceRateLimitExceeded.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/HourlyDeviceRateLimitExceeded.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/OverallDailyRateLimitExceeded.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/OverallDailyRateLimitExceeded.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/AdapterProvider.js +37 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/AdapterProvider.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/FileHelper.js +53 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/FileHelper.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/IotProxy.js +27 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/IotProxy.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/Logger.js +93 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/Logger.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/RateLimiter.js +112 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/RateLimiter.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/Utils.js +625 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/Utils.js.map +1 -0
- package/build-backend/lib/Utils.js +96 -0
- package/build-backend/lib/Utils.js.map +1 -0
- package/build-backend/lib/adminCommonSocket.js +715 -0
- package/build-backend/lib/adminCommonSocket.js.map +1 -0
- package/build-backend/lib/alexaCustom.js +542 -0
- package/build-backend/lib/alexaCustom.js.map +1 -0
- package/build-backend/lib/alexaSmartHomeV2.js +2788 -0
- package/build-backend/lib/alexaSmartHomeV3.js +97 -0
- package/build-backend/lib/alexaSmartHomeV3.js.map +1 -0
- package/build-backend/lib/alisa.js +2409 -0
- package/build-backend/lib/devices.js +23 -0
- package/build-backend/lib/devices.js.map +1 -0
- package/build-backend/lib/functions.js +24 -0
- package/build-backend/lib/functions.js.map +1 -0
- package/build-backend/lib/googleHome.js +3322 -0
- package/build-backend/lib/notifications.js +30 -0
- package/build-backend/lib/notifications.js.map +1 -0
- package/build-backend/lib/remote.js +1342 -0
- package/build-backend/lib/remote.js.map +1 -0
- package/build-backend/lib/rooms.js +48 -0
- package/build-backend/lib/rooms.js.map +1 -0
- package/build-backend/lib/texts.js +81 -0
- package/build-backend/lib/texts.js.map +1 -0
- package/build-backend/lib/translate.js +21 -0
- package/build-backend/lib/translate.js.map +1 -0
- package/build-backend/lib/visuApp.js +147 -0
- package/build-backend/lib/visuApp.js.map +1 -0
- package/build-backend/main.js +1361 -0
- package/build-backend/main.js.map +1 -0
- package/io-package.json +2 -2
- package/package.json +2 -2
- package/admin/assets/index-Y479CE6x.js +0 -681
- package/admin/rules/assets/ActionVisu__mf_v__runtimeInit__mf_v__-DtUoI3FU.js +0 -5
- package/admin/rules/assets/bootstrap-Ba57tu25.js +0 -1
- package/admin/rules/assets/index-_Y2FN5EZ.js +0 -1152
|
@@ -0,0 +1,1342 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
|
+
const node_zlib_1 = require("node:zlib");
|
|
8
|
+
const adminCommonSocket_1 = __importDefault(require("./adminCommonSocket"));
|
|
9
|
+
const MESSAGE_TYPES = {
|
|
10
|
+
MESSAGE: 0,
|
|
11
|
+
PING: 1,
|
|
12
|
+
PONG: 2,
|
|
13
|
+
CALLBACK: 3,
|
|
14
|
+
READY: 4,
|
|
15
|
+
WAIT: 5,
|
|
16
|
+
SENDING_DONE: 6,
|
|
17
|
+
MISSING: 7,
|
|
18
|
+
TIMEOUT: 8,
|
|
19
|
+
HTML: 9,
|
|
20
|
+
COMBINED_CALLBACK: 10,
|
|
21
|
+
COMBINED_MESSAGE: 11,
|
|
22
|
+
};
|
|
23
|
+
const MAX_IOT_MESSAGE_LENGTH = 127 * 1024;
|
|
24
|
+
const MAX_POST_MESSAGE_LENGTH = 127 * 1024;
|
|
25
|
+
const MAX_FILE_SIZE = 4 * 1024 * 1024;
|
|
26
|
+
const COLLECT_OBJS_MS = 400;
|
|
27
|
+
const COLLECT_STATES_MS = 400;
|
|
28
|
+
const COLLECT_LOGS_MS = 800;
|
|
29
|
+
const NONE = '___none___';
|
|
30
|
+
class RemoteAccess {
|
|
31
|
+
adapter;
|
|
32
|
+
device = null;
|
|
33
|
+
gcInterval = null;
|
|
34
|
+
name = {};
|
|
35
|
+
objects = {};
|
|
36
|
+
packets = {};
|
|
37
|
+
statesCache = {};
|
|
38
|
+
listOfLogs = [];
|
|
39
|
+
listOfStates = { ids: [], states: [] };
|
|
40
|
+
listOfObjects = { ids: [], objs: [] };
|
|
41
|
+
clientId;
|
|
42
|
+
config;
|
|
43
|
+
collectStatesMs;
|
|
44
|
+
collectObjectsMs;
|
|
45
|
+
collectLogsMs;
|
|
46
|
+
handlers;
|
|
47
|
+
subscribes = { stateChange: {}, objectChange: {}, log: {} };
|
|
48
|
+
sockets = {};
|
|
49
|
+
vendorPrefix = '';
|
|
50
|
+
localAdmin = null;
|
|
51
|
+
webObj = null;
|
|
52
|
+
webUrl = '';
|
|
53
|
+
adminObj = null;
|
|
54
|
+
adminUrl = '';
|
|
55
|
+
lang = 'en';
|
|
56
|
+
sendObjectsTimeout = null;
|
|
57
|
+
sendLogsTimeout = null;
|
|
58
|
+
sendStatesTimeout = null;
|
|
59
|
+
infoTimeout = null;
|
|
60
|
+
secret = '';
|
|
61
|
+
constructor(adapter, clientId) {
|
|
62
|
+
this.adapter = adapter;
|
|
63
|
+
this.config = adapter.config;
|
|
64
|
+
this.clientId = clientId;
|
|
65
|
+
this.collectStatesMs =
|
|
66
|
+
this.config.collectStatesMs === undefined
|
|
67
|
+
? COLLECT_STATES_MS
|
|
68
|
+
: parseInt(this.config.collectStatesMs, 10);
|
|
69
|
+
this.collectObjectsMs =
|
|
70
|
+
this.config.collectObjectsMs === undefined
|
|
71
|
+
? COLLECT_OBJS_MS
|
|
72
|
+
: parseInt(this.config.collectObjectsMs, 10);
|
|
73
|
+
this.collectLogsMs =
|
|
74
|
+
this.config.collectLogsMs === undefined
|
|
75
|
+
? COLLECT_LOGS_MS
|
|
76
|
+
: parseInt(this.config.collectLogsMs, 10);
|
|
77
|
+
this.handlers = {
|
|
78
|
+
getObject: { f: this.adapter.getForeignObjectAsync.bind(this.adapter), args: 1 },
|
|
79
|
+
setObject: { f: this.adapter.setForeignObjectAsync.bind(this.adapter), args: 2 },
|
|
80
|
+
getState: { f: this.adapter.getForeignStateAsync.bind(this.adapter), args: 1 },
|
|
81
|
+
setState: { f: this.adapter.setForeignStateAsync.bind(this.adapter), args: 2 },
|
|
82
|
+
delState: { f: this.adapter.delForeignStateAsync.bind(this.adapter), args: 2 },
|
|
83
|
+
getObjectView: { f: this.adapter.getObjectViewAsync.bind(this.adapter), args: 4 },
|
|
84
|
+
delObject: { f: this.adapter.delForeignObjectAsync.bind(this.adapter), args: 2 },
|
|
85
|
+
delObjects: { f: this.adapter.delForeignObjectAsync.bind(this.adapter), args: 2 },
|
|
86
|
+
extendObject: { f: this.adapter.extendForeignObjectAsync.bind(this.adapter), args: 2 },
|
|
87
|
+
getForeignStates: { f: this.adapter.getForeignStatesAsync.bind(this.adapter), args: 1 },
|
|
88
|
+
getForeignObjects: { f: this.adapter.getForeignObjectsAsync.bind(this.adapter), args: 2 },
|
|
89
|
+
fileExists: { f: this.adapter.fileExistsAsync.bind(this.adapter), args: 2 },
|
|
90
|
+
chownFile: { f: this.adapter.chownFileAsync.bind(this.adapter), args: 3 },
|
|
91
|
+
chmodFile: { f: this.adapter.chmodFileAsync.bind(this.adapter), args: 3 },
|
|
92
|
+
deleteFolder: { f: this.adapter.unlinkAsync.bind(this.adapter), args: 2 },
|
|
93
|
+
deleteFile: { f: this.adapter.unlinkAsync.bind(this.adapter), args: 2 },
|
|
94
|
+
mkdir: { f: this.adapter.mkdirAsync.bind(this.adapter), args: 2 },
|
|
95
|
+
renameFile: { f: this.adapter.renameAsync.bind(this.adapter), args: 3 },
|
|
96
|
+
readDir: { f: this.adapter.readDirAsync.bind(this.adapter), args: 2 },
|
|
97
|
+
changePassword: { f: this.adapter.setPasswordAsync.bind(this.adapter), args: 2 },
|
|
98
|
+
};
|
|
99
|
+
if (!this.config.remote) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (this.config.remoteAdminInstance) {
|
|
103
|
+
try {
|
|
104
|
+
this.localAdmin = require
|
|
105
|
+
.resolve('iobroker.admin')
|
|
106
|
+
.replace(/\\/g, '/')
|
|
107
|
+
.replace(/main\.js$/, 'www-react');
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
this.localAdmin = null;
|
|
111
|
+
this.adapter.log.warn('[REMOTE] Cannot read admin files while iobroker.admin was not found');
|
|
112
|
+
}
|
|
113
|
+
void this.adapter.getForeignObjectAsync(`system.adapter.${this.config.remoteAdminInstance}`).then(obj => {
|
|
114
|
+
this.adminObj = obj || null;
|
|
115
|
+
if (obj?.native && !obj.native.auth) {
|
|
116
|
+
this.adminUrl = `${obj.native.secure ? 'https:' : 'http:'}//localhost:${obj.native.port}`;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (this.config.remoteWebInstance) {
|
|
121
|
+
void this.adapter.getForeignObjectAsync(`system.adapter.${this.config.remoteWebInstance}`).then(obj => {
|
|
122
|
+
this.webObj = obj || null;
|
|
123
|
+
if (obj?.native && !obj.native.auth) {
|
|
124
|
+
this.webUrl = `${obj.native.secure ? 'https:' : 'http:'}//localhost:${obj.native.port}`;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
void this.adapter.getForeignObjectAsync('system.meta.uuid').then(obj => {
|
|
129
|
+
if (obj?.native) {
|
|
130
|
+
this.vendorPrefix = obj.native.uuid.length > 36 ? obj.native.uuid.substring(0, 2) : '';
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
setLanguage(_lang) {
|
|
135
|
+
this.lang = _lang || 'de';
|
|
136
|
+
}
|
|
137
|
+
registerDevice(device) {
|
|
138
|
+
this.device = device;
|
|
139
|
+
}
|
|
140
|
+
async _sendCachedStates() {
|
|
141
|
+
const sids = Object.keys(this.sockets);
|
|
142
|
+
const listOfStates = this.listOfStates;
|
|
143
|
+
// clear cache
|
|
144
|
+
this.listOfStates = { ids: [], states: [] };
|
|
145
|
+
if (sids.length) {
|
|
146
|
+
this.adapter.log.debug(`Send to ${sids.length} sockets: ${listOfStates.ids.map((id, i) => `${id}: ${listOfStates.states[i]?.val}`).join(', ')}`);
|
|
147
|
+
// pack the data
|
|
148
|
+
const data = JSON.stringify([listOfStates.ids, listOfStates.states]);
|
|
149
|
+
const args = (0, node_zlib_1.deflateSync)(data).toString('base64');
|
|
150
|
+
for (let s = 0; s < sids.length; s++) {
|
|
151
|
+
const error = await this._sendEvent({ name: 'stateChange', args, sid: sids[s], multi: true });
|
|
152
|
+
if (error) {
|
|
153
|
+
this.adapter.log.warn(`[REMOTE] cannot send "stateChange": ${JSON.stringify(error)}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
updateState(id, state) {
|
|
159
|
+
if (!this.config.remote) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const cache = JSON.stringify(state);
|
|
163
|
+
if (this.statesCache[id] && this.statesCache[id] !== cache) {
|
|
164
|
+
if (this.config.debug) {
|
|
165
|
+
this.adapter.log.debug(`[REMOTE] send stateChange "${id}": ${JSON.stringify(state)}`);
|
|
166
|
+
}
|
|
167
|
+
this.statesCache[id] = cache;
|
|
168
|
+
this.listOfStates.ids.push(id);
|
|
169
|
+
this.listOfStates.states.push(JSON.parse(JSON.stringify(state)));
|
|
170
|
+
// do not wait if the list will be too long
|
|
171
|
+
if (this.listOfStates.ids.length > 70) {
|
|
172
|
+
if (this.sendObjectsTimeout) {
|
|
173
|
+
clearTimeout(this.sendObjectsTimeout);
|
|
174
|
+
this.sendObjectsTimeout = null;
|
|
175
|
+
}
|
|
176
|
+
this._sendCachedStates().catch(e => this.adapter.log.error(`[REMOTE] Cannot send cached states: ${e}`));
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.sendObjectsTimeout ||= setTimeout(() => {
|
|
180
|
+
this.sendObjectsTimeout = null;
|
|
181
|
+
this._sendCachedStates().catch(e => this.adapter.log.error(`[REMOTE] Cannot send cached states: ${e}`));
|
|
182
|
+
}, this.collectStatesMs);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
// this.adapter.log.debug(`[REMOTE] ignore stateChange "${id}": ${JSON.stringify(state)}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
updateObject(id, obj) {
|
|
190
|
+
if (!this.config.remote) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
this.listOfObjects.ids.push(id);
|
|
194
|
+
this.listOfObjects.objs.push(JSON.parse(JSON.stringify(obj)));
|
|
195
|
+
if (this.sendObjectsTimeout) {
|
|
196
|
+
clearTimeout(this.sendObjectsTimeout);
|
|
197
|
+
}
|
|
198
|
+
this.sendObjectsTimeout = setTimeout(async () => {
|
|
199
|
+
this.sendObjectsTimeout = null;
|
|
200
|
+
const listOfObjects = this.listOfObjects;
|
|
201
|
+
this.listOfObjects = { ids: [], objs: [] };
|
|
202
|
+
const sids = Object.keys(this.sockets);
|
|
203
|
+
for (let s = 0; s < sids.length; s++) {
|
|
204
|
+
const error = await this._sendEvent({
|
|
205
|
+
name: 'objectChange',
|
|
206
|
+
args: [listOfObjects.ids, listOfObjects.objs],
|
|
207
|
+
sid: sids[s],
|
|
208
|
+
multi: true,
|
|
209
|
+
});
|
|
210
|
+
if (error) {
|
|
211
|
+
this.adapter.log.warn(`[REMOTE] cannot send "objectChange": ${JSON.stringify(error)}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}, COLLECT_OBJS_MS);
|
|
215
|
+
}
|
|
216
|
+
onLog(obj) {
|
|
217
|
+
if (!this.config.remote) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
this.listOfLogs.push(obj);
|
|
221
|
+
if (this.sendLogsTimeout) {
|
|
222
|
+
clearTimeout(this.sendLogsTimeout);
|
|
223
|
+
}
|
|
224
|
+
this.sendLogsTimeout = setTimeout(async () => {
|
|
225
|
+
this.sendLogsTimeout = null;
|
|
226
|
+
const listOfLogs = this.listOfLogs;
|
|
227
|
+
this.listOfLogs = [];
|
|
228
|
+
const sids = Object.keys(this.sockets);
|
|
229
|
+
for (let s = 0; s < sids.length; s++) {
|
|
230
|
+
const error = await this._sendEvent({
|
|
231
|
+
name: 'log',
|
|
232
|
+
args: [listOfLogs],
|
|
233
|
+
sid: sids[s],
|
|
234
|
+
multi: true,
|
|
235
|
+
});
|
|
236
|
+
if (error) {
|
|
237
|
+
this.adapter.log.error(`[REMOTE] cannot send "log": ${JSON.stringify(error)}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}, COLLECT_LOGS_MS);
|
|
241
|
+
}
|
|
242
|
+
destroy() {
|
|
243
|
+
if (this.gcInterval) {
|
|
244
|
+
clearInterval(this.gcInterval);
|
|
245
|
+
this.gcInterval = null;
|
|
246
|
+
}
|
|
247
|
+
if (this.sendLogsTimeout) {
|
|
248
|
+
clearTimeout(this.sendLogsTimeout);
|
|
249
|
+
this.sendLogsTimeout = null;
|
|
250
|
+
}
|
|
251
|
+
if (this.sendObjectsTimeout) {
|
|
252
|
+
clearTimeout(this.sendObjectsTimeout);
|
|
253
|
+
this.sendObjectsTimeout = null;
|
|
254
|
+
}
|
|
255
|
+
if (this.sendStatesTimeout) {
|
|
256
|
+
clearTimeout(this.sendStatesTimeout);
|
|
257
|
+
this.sendStatesTimeout = null;
|
|
258
|
+
}
|
|
259
|
+
adminCommonSocket_1.default.stopGB();
|
|
260
|
+
this._unsubscribeAll();
|
|
261
|
+
this.sockets = {};
|
|
262
|
+
}
|
|
263
|
+
_clearMemory() {
|
|
264
|
+
const now = Date.now();
|
|
265
|
+
const DAY = 36000000 * 3;
|
|
266
|
+
Object.keys(this.sockets).forEach(sid => {
|
|
267
|
+
if (now - this.sockets[sid].ts > DAY) {
|
|
268
|
+
this._unsubscribeSocket(sid, 'stateChange');
|
|
269
|
+
this._unsubscribeSocket(sid, 'objectChange');
|
|
270
|
+
this._unsubscribeSocket(sid, 'log');
|
|
271
|
+
delete this.sockets[sid];
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
Object.keys(this.packets).forEach(id => {
|
|
275
|
+
if (now - this.packets[id].ts > 120000) {
|
|
276
|
+
delete this.packets[id];
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
_readAllObjects() {
|
|
281
|
+
return this.adapter.getObjectListAsync({ include_docs: true }).then(res => {
|
|
282
|
+
const objects = {};
|
|
283
|
+
this.adapter.log.info('[REMOTE] received all objects');
|
|
284
|
+
if (res?.rows) {
|
|
285
|
+
for (let i = 0; i < res.rows.length; i++) {
|
|
286
|
+
objects[res.rows[i].doc._id] = res.rows[i].doc;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return objects;
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
pattern2RegEx(pattern) {
|
|
293
|
+
if (!pattern || typeof pattern !== 'string') {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
if (pattern !== '*') {
|
|
297
|
+
if (pattern[0] === '*' && pattern[pattern.length - 1] !== '*') {
|
|
298
|
+
pattern += '$';
|
|
299
|
+
}
|
|
300
|
+
if (pattern[0] !== '*' && pattern[pattern.length - 1] === '*') {
|
|
301
|
+
pattern = `^${pattern}`;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
pattern = pattern.replace(/\./g, '\\.');
|
|
305
|
+
pattern = pattern.replace(/\*/g, '.*');
|
|
306
|
+
pattern = pattern.replace(/\[/g, '\\[');
|
|
307
|
+
pattern = pattern.replace(/]/g, '\\]');
|
|
308
|
+
pattern = pattern.replace(/\(/g, '\\(');
|
|
309
|
+
pattern = pattern.replace(/\)/g, '\\)');
|
|
310
|
+
return pattern;
|
|
311
|
+
}
|
|
312
|
+
_subscribe(sid, type, pattern) {
|
|
313
|
+
//console.log((socket._name || socket.id) + ' subscribe ' + pattern);
|
|
314
|
+
const socket = this.sockets[sid];
|
|
315
|
+
this.subscribes[type] ||= {};
|
|
316
|
+
let s;
|
|
317
|
+
if (socket) {
|
|
318
|
+
socket._subscribe[type] ||= [];
|
|
319
|
+
s = socket._subscribe[type];
|
|
320
|
+
for (let i = 0; i < s.length; i++) {
|
|
321
|
+
if (s[i].pattern === pattern) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const p = this.pattern2RegEx(pattern);
|
|
327
|
+
if (p === null) {
|
|
328
|
+
return this.adapter.log.warn('[REMOTE] Empty or invalid pattern on subscribe!');
|
|
329
|
+
}
|
|
330
|
+
if (s) {
|
|
331
|
+
s.push({ pattern, regex: new RegExp(p) });
|
|
332
|
+
}
|
|
333
|
+
if (this.subscribes[type][pattern] === undefined) {
|
|
334
|
+
this.subscribes[type][pattern] = 1;
|
|
335
|
+
if (type === 'stateChange') {
|
|
336
|
+
this.adapter.log.debug(`[REMOTE] Subscribe STATES: ${pattern}`);
|
|
337
|
+
this.adapter.subscribeForeignStates(pattern);
|
|
338
|
+
}
|
|
339
|
+
else if (type === 'objectChange') {
|
|
340
|
+
this.adapter.log.debug(`[REMOTE] Subscribe OBJECTS: ${pattern}`);
|
|
341
|
+
this.adapter.subscribeForeignObjects?.(pattern);
|
|
342
|
+
}
|
|
343
|
+
else if (type === 'log') {
|
|
344
|
+
this.adapter.log.debug('[REMOTE] Subscribe LOGS');
|
|
345
|
+
void this.adapter.requireLog?.(true);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
this.subscribes[type][pattern]++;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
_showSubscribes(sid, type) {
|
|
353
|
+
const socket = this.sockets[sid];
|
|
354
|
+
if (socket?._subscribe) {
|
|
355
|
+
const s = socket._subscribe[type] || [];
|
|
356
|
+
const ids = [];
|
|
357
|
+
for (let i = 0; i < s.length; i++) {
|
|
358
|
+
ids.push(s[i].pattern);
|
|
359
|
+
}
|
|
360
|
+
this.adapter.log.debug(`[REMOTE] Subscribes: ${ids.join(', ')}`);
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
this.adapter.log.debug('[REMOTE] Subscribes: no subscribes');
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
_updateConnectedInfo() {
|
|
367
|
+
if (this.infoTimeout) {
|
|
368
|
+
clearTimeout(this.infoTimeout);
|
|
369
|
+
this.infoTimeout = null;
|
|
370
|
+
}
|
|
371
|
+
// TODO
|
|
372
|
+
// this.adapter.setState('info.connection', text, true);
|
|
373
|
+
}
|
|
374
|
+
_unsubscribe(sid, type, pattern) {
|
|
375
|
+
const socket = this.sockets[sid];
|
|
376
|
+
this.subscribes[type] ||= {};
|
|
377
|
+
if (socket && typeof socket === 'object') {
|
|
378
|
+
if (!socket._subscribe?.[type]) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
for (let i = socket._subscribe[type].length - 1; i >= 0; i--) {
|
|
382
|
+
if (socket._subscribe[type][i].pattern === pattern) {
|
|
383
|
+
// Remove pattern from global list
|
|
384
|
+
if (this.subscribes[type][pattern] !== undefined) {
|
|
385
|
+
this.subscribes[type][pattern]--;
|
|
386
|
+
if (this.subscribes[type][pattern] <= 0) {
|
|
387
|
+
if (type === 'stateChange') {
|
|
388
|
+
this.adapter.log.debug(`[REMOTE] Unsubscribe STATES: ${pattern}`);
|
|
389
|
+
//console.log((socket._name || socket.id) + ' unsubscribeForeignStates ' + pattern);
|
|
390
|
+
this.adapter.unsubscribeForeignStates(pattern);
|
|
391
|
+
}
|
|
392
|
+
else if (type === 'objectChange') {
|
|
393
|
+
this.adapter.log.debug(`[REMOTE] Unsubscribe OBJECTS: ${pattern}`);
|
|
394
|
+
//console.log((socket._name || socket.id) + ' unsubscribeForeignObjects ' + pattern);
|
|
395
|
+
this.adapter.unsubscribeForeignObjects &&
|
|
396
|
+
this.adapter.unsubscribeForeignObjects(pattern);
|
|
397
|
+
}
|
|
398
|
+
else if (type === 'log') {
|
|
399
|
+
//console.log((socket._name || socket.id) + ' requireLog false');
|
|
400
|
+
this.adapter.log.debug('[REMOTE] Unsubscribe LOGS');
|
|
401
|
+
void this.adapter.requireLog?.(false);
|
|
402
|
+
}
|
|
403
|
+
delete this.subscribes[type][pattern];
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
socket._subscribe[type].splice(i, 1);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
else if (pattern) {
|
|
412
|
+
// Remove pattern from global list
|
|
413
|
+
if (this.subscribes[type][pattern] !== undefined) {
|
|
414
|
+
this.subscribes[type][pattern]--;
|
|
415
|
+
if (this.subscribes[type][pattern] <= 0) {
|
|
416
|
+
if (type === 'stateChange') {
|
|
417
|
+
this.adapter.log.debug(`[REMOTE] Unsubscribe STATES: ${pattern}`);
|
|
418
|
+
this.adapter.unsubscribeForeignStates(pattern);
|
|
419
|
+
}
|
|
420
|
+
else if (type === 'objectChange') {
|
|
421
|
+
this.adapter.log.debug(`[REMOTE] Unsubscribe OBJECTS: ${pattern}`);
|
|
422
|
+
this.adapter.unsubscribeForeignObjects?.(pattern);
|
|
423
|
+
}
|
|
424
|
+
else if (type === 'log') {
|
|
425
|
+
this.adapter.log.debug('[REMOTE] Unsubscribe LOGS');
|
|
426
|
+
void this.adapter.requireLog?.(false);
|
|
427
|
+
}
|
|
428
|
+
delete this.subscribes[type][pattern];
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
_unsubscribeAll() {
|
|
434
|
+
Object.keys(this.sockets).forEach(sid => {
|
|
435
|
+
this._unsubscribe(sid, 'stateChange');
|
|
436
|
+
this._unsubscribe(sid, 'objectChange');
|
|
437
|
+
this._unsubscribe(sid, 'log');
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
_unsubscribeSocket(sid, type) {
|
|
441
|
+
const socket = this.sockets[sid];
|
|
442
|
+
if (!socket?._subscribe?.[type]) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
for (let i = 0; i < socket._subscribe[type].length; i++) {
|
|
446
|
+
const pattern = socket._subscribe[type][i].pattern;
|
|
447
|
+
if (this.subscribes[type][pattern] !== undefined) {
|
|
448
|
+
this.subscribes[type][pattern]--;
|
|
449
|
+
if (this.subscribes[type][pattern] <= 0) {
|
|
450
|
+
if (type === 'stateChange') {
|
|
451
|
+
this.adapter.log.debug(`[REMOTE] Unsubscribe STATES: ${pattern}`);
|
|
452
|
+
this.adapter.unsubscribeForeignStates(pattern);
|
|
453
|
+
}
|
|
454
|
+
else if (type === 'objectChange') {
|
|
455
|
+
this.adapter.log.debug(`[REMOTE] Unsubscribe OBJECTS: ${pattern}`);
|
|
456
|
+
this.adapter.unsubscribeForeignObjects?.(pattern);
|
|
457
|
+
}
|
|
458
|
+
else if (type === 'log') {
|
|
459
|
+
this.adapter.log.debug(`[REMOTE] Unsubscribe LOGS: ${pattern}`);
|
|
460
|
+
void this.adapter.requireLog?.(false);
|
|
461
|
+
}
|
|
462
|
+
delete this.subscribes[type][pattern];
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
_subscribeSocket(sid, type) {
|
|
468
|
+
const socket = this.sockets[sid];
|
|
469
|
+
if (!socket?._subscribe?.[type]) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
for (let i = 0; i < socket._subscribe[type].length; i++) {
|
|
473
|
+
const pattern = socket._subscribe[type][i].pattern;
|
|
474
|
+
if (this.subscribes[type][pattern] === undefined) {
|
|
475
|
+
this.subscribes[type][pattern] = 1;
|
|
476
|
+
if (type === 'stateChange') {
|
|
477
|
+
this.adapter.log.debug(`[REMOTE] Subscribe STATES: ${pattern}`);
|
|
478
|
+
this.adapter.subscribeForeignStates(pattern);
|
|
479
|
+
}
|
|
480
|
+
else if (type === 'objectChange') {
|
|
481
|
+
this.adapter.log.debug(`[REMOTE] Subscribe OBJECTS: ${pattern}`);
|
|
482
|
+
this.adapter.subscribeForeignObjects?.(pattern);
|
|
483
|
+
}
|
|
484
|
+
else if (type === 'log') {
|
|
485
|
+
this.adapter.log.debug('[REMOTE] Subscribe LOGS');
|
|
486
|
+
void this.adapter.requireLog?.(true);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
this.subscribes[type][pattern]++;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
_sendEvent(message, _originalMessage) {
|
|
495
|
+
return axios_1.default
|
|
496
|
+
.post('https://remote-events.iobroker.in/', message, {
|
|
497
|
+
validateStatus: status => status === 200,
|
|
498
|
+
timeout: 5000,
|
|
499
|
+
})
|
|
500
|
+
.then(() => undefined)
|
|
501
|
+
.catch(error => {
|
|
502
|
+
let errorMessage;
|
|
503
|
+
if (error.response) {
|
|
504
|
+
errorMessage = error.response.data || error.response.status;
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
errorMessage = error.message?.toString();
|
|
508
|
+
}
|
|
509
|
+
this.adapter.log.warn(`[REMOTE] Cannot send status update to ${message.sid} (${JSON.stringify(_originalMessage)}): ${JSON.stringify(errorMessage)}`);
|
|
510
|
+
if (errorMessage.error === 'invalid connectionId') {
|
|
511
|
+
if (this.sockets[message.sid]) {
|
|
512
|
+
this.adapter.log.debug(`[REMOTE] delete connection id ${message.sid}`);
|
|
513
|
+
delete this.sockets[message.sid];
|
|
514
|
+
}
|
|
515
|
+
errorMessage = false;
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
this.adapter.log.warn(`[REMOTE] Cannot send status update to "${message.sid}" (${JSON.stringify(_originalMessage)}): ${JSON.stringify(errorMessage)}`);
|
|
519
|
+
}
|
|
520
|
+
return JSON.stringify(errorMessage);
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
async _getStatesManyArgs(args) {
|
|
524
|
+
const response = [];
|
|
525
|
+
for (let a = 0; a < args.length; a++) {
|
|
526
|
+
const id = args[a][0];
|
|
527
|
+
try {
|
|
528
|
+
const result = await this.adapter.getForeignStatesAsync(id || '*');
|
|
529
|
+
response[a] = [null, result];
|
|
530
|
+
if (result) {
|
|
531
|
+
Object.keys(result).forEach(id => (this.statesCache[id] = JSON.stringify(result[id])));
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
catch (error) {
|
|
535
|
+
response[a] = [error];
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
return response;
|
|
539
|
+
}
|
|
540
|
+
async _getStateManyArgs(args) {
|
|
541
|
+
const response = [];
|
|
542
|
+
for (let a = 0; a < args.length; a++) {
|
|
543
|
+
const id = args[a][0];
|
|
544
|
+
try {
|
|
545
|
+
const result = await this.adapter.getForeignStateAsync(id || '*');
|
|
546
|
+
response[a] = [null, result];
|
|
547
|
+
this.statesCache[id] = JSON.stringify(result);
|
|
548
|
+
}
|
|
549
|
+
catch (error) {
|
|
550
|
+
response[a] = [error];
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return response;
|
|
554
|
+
}
|
|
555
|
+
async _getObjectManyArgs(args) {
|
|
556
|
+
const response = [];
|
|
557
|
+
for (let a = 0; a < args.length; a++) {
|
|
558
|
+
const id = args[a][0];
|
|
559
|
+
try {
|
|
560
|
+
const result = await this.adapter.getForeignObjectAsync(id || '*');
|
|
561
|
+
response[a] = [null, result];
|
|
562
|
+
}
|
|
563
|
+
catch (error) {
|
|
564
|
+
response[a] = [error];
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return response;
|
|
568
|
+
}
|
|
569
|
+
_subscribeManyArgs(sid, args) {
|
|
570
|
+
const result = [];
|
|
571
|
+
for (let a = 0; a < args.length; a++) {
|
|
572
|
+
const pattern = args[a][0];
|
|
573
|
+
if (Array.isArray(pattern)) {
|
|
574
|
+
for (let p = 0; p < pattern.length; p++) {
|
|
575
|
+
this._subscribe(sid, 'stateChange', pattern[p]);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
this._subscribe(sid, 'stateChange', pattern);
|
|
580
|
+
}
|
|
581
|
+
result.push([null]);
|
|
582
|
+
}
|
|
583
|
+
return Promise.resolve(result);
|
|
584
|
+
}
|
|
585
|
+
async _unsubscribeManyArgs(sid, args) {
|
|
586
|
+
const result = [];
|
|
587
|
+
for (let a = 0; a < args.length; a++) {
|
|
588
|
+
const pattern = args[a][0];
|
|
589
|
+
if (Array.isArray(pattern)) {
|
|
590
|
+
for (let p = 0; p < pattern.length; p++) {
|
|
591
|
+
this._unsubscribe(sid, 'stateChange', pattern[p]);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
this._unsubscribe(sid, 'stateChange', pattern);
|
|
596
|
+
}
|
|
597
|
+
result.push([null]);
|
|
598
|
+
}
|
|
599
|
+
return Promise.resolve(result);
|
|
600
|
+
}
|
|
601
|
+
uploadToServer(url, data, raw) {
|
|
602
|
+
return axios_1.default
|
|
603
|
+
.put(url, raw ? data.file : Buffer.from(data.file, 'base64'), {
|
|
604
|
+
headers: {
|
|
605
|
+
'Content-Type': data.mimeType,
|
|
606
|
+
},
|
|
607
|
+
})
|
|
608
|
+
.then(() => {
|
|
609
|
+
return true;
|
|
610
|
+
})
|
|
611
|
+
.catch(e => {
|
|
612
|
+
console.log(e);
|
|
613
|
+
return false;
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
readUrlFile(url, path, sid, type, id) {
|
|
617
|
+
return (0, axios_1.default)(url + path, {
|
|
618
|
+
responseType: 'arraybuffer',
|
|
619
|
+
validateStatus: status => status === 200,
|
|
620
|
+
timeout: 500,
|
|
621
|
+
})
|
|
622
|
+
.then(response => {
|
|
623
|
+
// replace port
|
|
624
|
+
if (path.endsWith('_socket/info.js')) {
|
|
625
|
+
response.data = response.data.toString();
|
|
626
|
+
// var socketUrl = ":8084"; var socketSession = ""; window.sysLang = "ru"; window.socketForceWebSockets = false;
|
|
627
|
+
// replace ":8084"; => "";
|
|
628
|
+
response.data = response.data.replace(/":\d+";/, '"";');
|
|
629
|
+
}
|
|
630
|
+
return {
|
|
631
|
+
file: Buffer.from(response.data).toString('base64'),
|
|
632
|
+
mimeType: response.headers['content-type'],
|
|
633
|
+
};
|
|
634
|
+
})
|
|
635
|
+
.catch(error => {
|
|
636
|
+
this.adapter.log.warn(`[REMOTE] File ${url}${path} not found`);
|
|
637
|
+
let errorMessage;
|
|
638
|
+
if (error.response && error.response.status === 404) {
|
|
639
|
+
errorMessage = 'Not exists';
|
|
640
|
+
}
|
|
641
|
+
else if (error.response && error.response.status === 401) {
|
|
642
|
+
errorMessage = 'Not authorised';
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
if (error.response) {
|
|
646
|
+
errorMessage = error.response.data || error.response.status;
|
|
647
|
+
}
|
|
648
|
+
else if (error.request) {
|
|
649
|
+
errorMessage = 'No answer';
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
errorMessage = error.message;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return { sid, d: [type, id, '', { error: errorMessage }] };
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
_sendResponse(sid, _type, id, name, args, writeUrl, readUrl) {
|
|
659
|
+
let packed = (0, node_zlib_1.deflateSync)(JSON.stringify(args)).toString('base64');
|
|
660
|
+
if (packed.length > MAX_IOT_MESSAGE_LENGTH) {
|
|
661
|
+
if (writeUrl) {
|
|
662
|
+
if (args.length === 3) {
|
|
663
|
+
const [error, file, mimeType] = args;
|
|
664
|
+
if (!error) {
|
|
665
|
+
return this.uploadToServer(writeUrl, { file, mimeType }, true).then(done => ({
|
|
666
|
+
sid,
|
|
667
|
+
d: [_type, id, name, done ? readUrl : ['Cannot upload']],
|
|
668
|
+
}));
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
else if (args.length === 2) {
|
|
672
|
+
const [error, result] = args;
|
|
673
|
+
if (!error) {
|
|
674
|
+
return this.uploadToServer(writeUrl, { file: JSON.stringify(result), mimeType: 'application/json' }, true).then(done => ({ sid, d: [_type, id, name, done ? readUrl : ['Cannot upload']] }));
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
else if (args.length === 1) {
|
|
678
|
+
const [result] = args;
|
|
679
|
+
return this.uploadToServer(writeUrl, { file: JSON.stringify(result), mimeType: 'application/json' }, true).then(done => ({ sid, d: [_type, id, name, done ? readUrl : ['Cannot upload']] }));
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
// too big message. Do not use iot for that and send directly to socket
|
|
683
|
+
/*const packets = []
|
|
684
|
+
while (packed.length > MAX_IOT_MESSAGE_LENGTH) {
|
|
685
|
+
const trunk = packed.substring(0, MAX_IOT_MESSAGE_LENGTH);
|
|
686
|
+
packed = packed.substring(MAX_IOT_MESSAGE_LENGTH);
|
|
687
|
+
packets.push(trunk);
|
|
688
|
+
}
|
|
689
|
+
if (packed.length) {
|
|
690
|
+
packets.push(packed);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
const trunks = packets.map((trunk, i) =>
|
|
694
|
+
sid: message.sid, i, l: packets.length, d: [_type, id, name, trunk]}));
|
|
695
|
+
|
|
696
|
+
this.packets[id] = {ts: Date.now(), trunks};
|
|
697
|
+
|
|
698
|
+
// start garbage collector
|
|
699
|
+
this.gcInterval = this.gcInterval || setInterval(() => this._clearMemory(), 60000);
|
|
700
|
+
|
|
701
|
+
return trunks;*/
|
|
702
|
+
setImmediate(async () => {
|
|
703
|
+
if (packed.length > MAX_POST_MESSAGE_LENGTH) {
|
|
704
|
+
// too big message. Do not use iot for that and send directly to socket
|
|
705
|
+
const packets = [];
|
|
706
|
+
while (packed.length > MAX_POST_MESSAGE_LENGTH) {
|
|
707
|
+
const trunk = packed.substring(0, MAX_POST_MESSAGE_LENGTH);
|
|
708
|
+
packed = packed.substring(MAX_POST_MESSAGE_LENGTH);
|
|
709
|
+
packets.push(trunk);
|
|
710
|
+
}
|
|
711
|
+
if (packed.length) {
|
|
712
|
+
packets.push(packed);
|
|
713
|
+
}
|
|
714
|
+
for (let i = 0; i < packets.length; i++) {
|
|
715
|
+
const error = await this._sendEvent({
|
|
716
|
+
sid,
|
|
717
|
+
d: [_type, id, name, packets[i], packets.length, i],
|
|
718
|
+
});
|
|
719
|
+
if (error) {
|
|
720
|
+
this.adapter.log.error(`[REMOTE] cannot send: ${JSON.stringify(error)}`);
|
|
721
|
+
break;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
else {
|
|
726
|
+
await this._sendEvent({ sid, d: [_type, id, name, packed] });
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
return Promise.resolve({ sid, d: [MESSAGE_TYPES.WAIT, id, name, [packed.length]] });
|
|
730
|
+
}
|
|
731
|
+
return Promise.resolve({ sid, d: [_type, id, name, packed] });
|
|
732
|
+
}
|
|
733
|
+
onCloudDisconnect() {
|
|
734
|
+
// delete all sockets
|
|
735
|
+
this.adapter.log.debug(`[REMOTE] Cloud disconnected`);
|
|
736
|
+
if (!this.sockets) {
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
const sids = Object.keys(this.sockets);
|
|
740
|
+
for (let s = 0; s < sids.length; s++) {
|
|
741
|
+
this._unsubscribeSocket(sids[s], 'stateChange');
|
|
742
|
+
this._unsubscribeSocket(sids[s], 'objectChange');
|
|
743
|
+
this._unsubscribeSocket(sids[s], 'log');
|
|
744
|
+
delete this.sockets[sids[s]];
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
process(request, serviceType) {
|
|
748
|
+
let message;
|
|
749
|
+
if (typeof request === 'string') {
|
|
750
|
+
try {
|
|
751
|
+
message = JSON.parse(request);
|
|
752
|
+
}
|
|
753
|
+
catch {
|
|
754
|
+
this.adapter.log.error(`[REMOTE] Cannot parse request: ${request}`);
|
|
755
|
+
message = null;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
else {
|
|
759
|
+
message = request;
|
|
760
|
+
}
|
|
761
|
+
if (message) {
|
|
762
|
+
const [_type, id, name, args, readUrl] = message.d;
|
|
763
|
+
let promiseOne; // answer will be created automatically (error, result)
|
|
764
|
+
let promiseResult; // answer will be created by promise
|
|
765
|
+
if (this.config.remote && _type === MESSAGE_TYPES.MISSING) {
|
|
766
|
+
if (this.packets[id]) {
|
|
767
|
+
const missing = args[0];
|
|
768
|
+
this.adapter.log.warn(`[REMOTE] Request for existing trunks: ${id}, "${name}": ${JSON.stringify(missing)}`);
|
|
769
|
+
if (this.device) {
|
|
770
|
+
setImmediate(async () => {
|
|
771
|
+
try {
|
|
772
|
+
for (let m = 0; m < missing.length; m++) {
|
|
773
|
+
await new Promise((resolve, reject) => this.device.publish(`response/${this.clientId}/${serviceType}`, JSON.stringify(this.packets[id].trunks[m]), { qos: 1 }, error => {
|
|
774
|
+
if (error) {
|
|
775
|
+
reject(error);
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
resolve();
|
|
779
|
+
}
|
|
780
|
+
}));
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
catch (err) {
|
|
784
|
+
this.adapter.log.error(`[REMOTE] Cannot send packet: ${err}`);
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
else {
|
|
790
|
+
this.adapter.log.warn(`[REMOTE] Request for non existing trunks: ${id}, "${name}"`);
|
|
791
|
+
}
|
|
792
|
+
promiseResult = Promise.resolve(NONE);
|
|
793
|
+
}
|
|
794
|
+
else if (this.config.remote && _type === MESSAGE_TYPES.SENDING_DONE) {
|
|
795
|
+
this.adapter.log.debug(`[REMOTE] Packet received: ${id}, "${name}"`);
|
|
796
|
+
delete this.packets[id];
|
|
797
|
+
promiseResult = Promise.resolve(NONE);
|
|
798
|
+
}
|
|
799
|
+
else if (_type === MESSAGE_TYPES.HTML) {
|
|
800
|
+
let promiseFile;
|
|
801
|
+
if (!this.config.remote) {
|
|
802
|
+
return Promise.resolve({ sid: message.sid, d: [_type, id, '', ['Not enabled']] });
|
|
803
|
+
}
|
|
804
|
+
else if (name === 'listOfPrograms' || name === '/listOfPrograms') {
|
|
805
|
+
promiseFile = adminCommonSocket_1.default.getListOfAllAdapters(this.adapter)
|
|
806
|
+
.then(result => {
|
|
807
|
+
const packed = (0, node_zlib_1.deflateSync)(JSON.stringify([null, result])).toString('base64');
|
|
808
|
+
return { sid: message.sid, d: [_type, id, '', packed] };
|
|
809
|
+
})
|
|
810
|
+
.catch(error => ({
|
|
811
|
+
sid: message.sid,
|
|
812
|
+
d: [_type, id, '', [error.toString()]],
|
|
813
|
+
}));
|
|
814
|
+
}
|
|
815
|
+
else if (name === 'vendorPrefix' || name === '/vendorPrefix') {
|
|
816
|
+
return Promise.resolve({ sid: message.sid, d: [_type, id, '', [null, this.vendorPrefix]] });
|
|
817
|
+
}
|
|
818
|
+
else if (name.startsWith('/adapter')) {
|
|
819
|
+
if (this.config.remoteAdminInstance) {
|
|
820
|
+
if (this.adminUrl) {
|
|
821
|
+
promiseFile = this.readUrlFile(this.adminUrl, name, message.sid, _type, id);
|
|
822
|
+
}
|
|
823
|
+
else {
|
|
824
|
+
promiseFile = Promise.resolve({
|
|
825
|
+
sid: message.sid,
|
|
826
|
+
d: [_type, id, '', { error: 'Not exists' }],
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
else {
|
|
831
|
+
promiseFile = Promise.resolve({
|
|
832
|
+
sid: message.sid,
|
|
833
|
+
d: [_type, id, '', { error: 'Not exists' }],
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
else {
|
|
838
|
+
const path = name.split('?')[0];
|
|
839
|
+
const parts = path.split('/');
|
|
840
|
+
parts.shift(); // remove leading /
|
|
841
|
+
const _adapter = parts.shift() || '';
|
|
842
|
+
this.adapter.log.debug(`[REMOTE] HTML: ${path}`);
|
|
843
|
+
// html must be returned only by iot channel, as lambda must process the answer
|
|
844
|
+
promiseFile = this.adapter
|
|
845
|
+
.readFileAsync(_adapter, parts.join('/'))
|
|
846
|
+
.then(data => {
|
|
847
|
+
data.file = Buffer.from(data.file).toString('base64');
|
|
848
|
+
return data;
|
|
849
|
+
})
|
|
850
|
+
.catch(() => {
|
|
851
|
+
if (this.webUrl) {
|
|
852
|
+
// try to read from server
|
|
853
|
+
return this.readUrlFile(this.webUrl, path, message.sid, _type, id);
|
|
854
|
+
}
|
|
855
|
+
return {
|
|
856
|
+
sid: message.sid,
|
|
857
|
+
d: [_type, id, '', { error: 'Not exists' }],
|
|
858
|
+
};
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
return promiseFile.then((data) => {
|
|
862
|
+
// if error
|
|
863
|
+
if (data.sid) {
|
|
864
|
+
return Promise.resolve(data);
|
|
865
|
+
}
|
|
866
|
+
const dataFile = data;
|
|
867
|
+
let packed = (0, node_zlib_1.deflateSync)(JSON.stringify(data)).toString('base64');
|
|
868
|
+
if (typeof args === 'string' &&
|
|
869
|
+
args?.startsWith('https:') &&
|
|
870
|
+
packed.length > MAX_IOT_MESSAGE_LENGTH) {
|
|
871
|
+
// upload file to temp server
|
|
872
|
+
return this.uploadToServer(args, dataFile).then(done => ({
|
|
873
|
+
sid: message.sid,
|
|
874
|
+
d: [_type, id, '', done ? '_$%URL' : 'Cannot upload'],
|
|
875
|
+
}));
|
|
876
|
+
}
|
|
877
|
+
if (dataFile.file.length > MAX_FILE_SIZE) {
|
|
878
|
+
// file too big
|
|
879
|
+
this.adapter.log.warn(`[REMOTE] Requested file ${name} is too big (${Math.round(dataFile.file.length / 1000)}Kb). Max length is ${MAX_FILE_SIZE / 1024}Kb`);
|
|
880
|
+
return Promise.resolve({
|
|
881
|
+
sid: message.sid,
|
|
882
|
+
d: [
|
|
883
|
+
_type,
|
|
884
|
+
id,
|
|
885
|
+
'',
|
|
886
|
+
{
|
|
887
|
+
error: `File is too big: ${Math.round(dataFile.file.length / 1000)}Kb, max ${MAX_FILE_SIZE / 1024}Kb`,
|
|
888
|
+
},
|
|
889
|
+
],
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
if (packed.length > MAX_IOT_MESSAGE_LENGTH) {
|
|
893
|
+
const packets = [];
|
|
894
|
+
while (packed.length > MAX_IOT_MESSAGE_LENGTH) {
|
|
895
|
+
const trunk = packed.substring(0, MAX_IOT_MESSAGE_LENGTH);
|
|
896
|
+
packed = packed.substring(MAX_IOT_MESSAGE_LENGTH);
|
|
897
|
+
packets.push(trunk);
|
|
898
|
+
}
|
|
899
|
+
if (packed.length) {
|
|
900
|
+
packets.push(packed);
|
|
901
|
+
}
|
|
902
|
+
const trunks = packets.map((trunk, i) => ({
|
|
903
|
+
sid: message.sid,
|
|
904
|
+
i,
|
|
905
|
+
l: packets.length,
|
|
906
|
+
d: [_type, id, '', trunk],
|
|
907
|
+
}));
|
|
908
|
+
this.packets[id] = { ts: Date.now(), trunks };
|
|
909
|
+
// start garbage collector
|
|
910
|
+
this.gcInterval = this.gcInterval || setInterval(() => this._clearMemory(), 60000);
|
|
911
|
+
return Promise.resolve(trunks);
|
|
912
|
+
}
|
|
913
|
+
return Promise.resolve({ sid: message.sid, d: [_type, id, '', packed] });
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
if (!this.config.remote) {
|
|
917
|
+
promiseResult = Promise.resolve({ sid: message.sid, d: [_type, id, name, ['Not enabled']] });
|
|
918
|
+
}
|
|
919
|
+
let isNew = false;
|
|
920
|
+
if (this.sockets) {
|
|
921
|
+
if (!this.sockets[message.sid]) {
|
|
922
|
+
this.adapter.log.debug(`[REMOTE] +++++ CONNECT ${message.sid}`);
|
|
923
|
+
this.sockets[message.sid] = {
|
|
924
|
+
_subscribe: {
|
|
925
|
+
stateChange: [],
|
|
926
|
+
objectChange: [],
|
|
927
|
+
log: [],
|
|
928
|
+
},
|
|
929
|
+
ts: Date.now(),
|
|
930
|
+
};
|
|
931
|
+
isNew = true;
|
|
932
|
+
}
|
|
933
|
+
else {
|
|
934
|
+
this.sockets[message.sid].ts = Date.now();
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
if (promiseResult) {
|
|
938
|
+
// this answer will be processed at the very end of the function
|
|
939
|
+
}
|
|
940
|
+
else if (_type === MESSAGE_TYPES.COMBINED_CALLBACK || _type === MESSAGE_TYPES.COMBINED_MESSAGE) {
|
|
941
|
+
let promiseMany;
|
|
942
|
+
if (name === 'getStates') {
|
|
943
|
+
promiseMany = this._getStatesManyArgs(args);
|
|
944
|
+
}
|
|
945
|
+
else if (name === 'getState') {
|
|
946
|
+
promiseMany = this._getStateManyArgs(args);
|
|
947
|
+
}
|
|
948
|
+
else if (name === 'getObject') {
|
|
949
|
+
promiseMany = this._getObjectManyArgs(args);
|
|
950
|
+
}
|
|
951
|
+
else if (name === 'subscribe' || name === 'subscribeStates') {
|
|
952
|
+
promiseMany = this._subscribeManyArgs(message.sid, args);
|
|
953
|
+
}
|
|
954
|
+
else if (name === 'unsubscribe' || name === 'unsubscribeStates') {
|
|
955
|
+
promiseMany = this._unsubscribeManyArgs(message.sid, args);
|
|
956
|
+
}
|
|
957
|
+
else if (name === 'ppng') {
|
|
958
|
+
// ping
|
|
959
|
+
promiseResult = Promise.resolve({ sid: message.sid, d: [_type, id, name, [0, isNew ? 0 : 1]] }); // 1 is OK, 0 is not OK
|
|
960
|
+
}
|
|
961
|
+
else {
|
|
962
|
+
// error
|
|
963
|
+
this.adapter.log.error(`[REMOTE] Received unknown multiple request: ${name}`);
|
|
964
|
+
promiseResult = Promise.resolve({ sid: message.sid, d: [_type, id, name, ['Unknown command']] });
|
|
965
|
+
}
|
|
966
|
+
if (promiseMany) {
|
|
967
|
+
promiseResult = promiseMany
|
|
968
|
+
.then(result => this._sendResponse(message.sid, _type, id, name, result))
|
|
969
|
+
/* let packed = zlib.deflateSync(JSON.stringify(result)).toString('base64');
|
|
970
|
+
|
|
971
|
+
if (packed.length > MAX_IOT_MESSAGE_LENGTH) {
|
|
972
|
+
setImmediate(async () => {
|
|
973
|
+
if (packed.length > MAX_POST_MESSAGE_LENGTH) {
|
|
974
|
+
// too big message. Do not use iot for that and send directly to socket
|
|
975
|
+
const packets = []
|
|
976
|
+
while (packed.length > MAX_POST_MESSAGE_LENGTH) {
|
|
977
|
+
const trunk = packed.substring(0, MAX_POST_MESSAGE_LENGTH);
|
|
978
|
+
packed = packed.substring(MAX_POST_MESSAGE_LENGTH);
|
|
979
|
+
packets.push(trunk);
|
|
980
|
+
}
|
|
981
|
+
if (packed.length) {
|
|
982
|
+
packets.push(packed);
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
for (let i = 0; i < packets.length; i++) {
|
|
986
|
+
const error = await this._sendEvent({sid: message.sid, d: [_type, id, name, packets[i], packets.length, i]});
|
|
987
|
+
if (error) {
|
|
988
|
+
this.adapter.log.error('[REMOTE] cannot send: ' + JSON.stringify(error));
|
|
989
|
+
break;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
} else {
|
|
993
|
+
await this._sendEvent({sid: message.sid, d: [_type, id, name, packed]});
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
return {sid: message.sid, d: [MESSAGE_TYPES.WAIT, id, name, [packed.length]]};
|
|
997
|
+
} else {
|
|
998
|
+
return {sid: message.sid, d: [_type, id, name, packed]};
|
|
999
|
+
}
|
|
1000
|
+
})*/
|
|
1001
|
+
.catch(error => ({ sid: message.sid, d: [_type, id, name, [error]] }));
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
else if (this.handlers[name]) {
|
|
1005
|
+
const argsArray = args;
|
|
1006
|
+
if (!this.handlers[name].args) {
|
|
1007
|
+
promiseOne = this.handlers[name].f();
|
|
1008
|
+
}
|
|
1009
|
+
else if (this.handlers[name].args === 1) {
|
|
1010
|
+
promiseOne = this.handlers[name].f(argsArray[0]);
|
|
1011
|
+
}
|
|
1012
|
+
else if (this.handlers[name].args === 2) {
|
|
1013
|
+
promiseOne = this.handlers[name].f(argsArray[0], argsArray[1]);
|
|
1014
|
+
}
|
|
1015
|
+
else if (this.handlers[name].args === 3) {
|
|
1016
|
+
promiseOne = this.handlers[name].f(argsArray[0], argsArray[1], argsArray[2]);
|
|
1017
|
+
}
|
|
1018
|
+
else if (this.handlers[name].args === 4) {
|
|
1019
|
+
promiseOne = this.handlers[name].f(argsArray[0], argsArray[1], argsArray[2], argsArray[3]);
|
|
1020
|
+
}
|
|
1021
|
+
else if (this.handlers[name].args === 5) {
|
|
1022
|
+
promiseOne = this.handlers[name].f(argsArray[0], argsArray[1], argsArray[2], argsArray[3], argsArray[4]);
|
|
1023
|
+
}
|
|
1024
|
+
else if (this.handlers[name].args === 6) {
|
|
1025
|
+
promiseOne = this.handlers[name].f(argsArray[0], argsArray[1], argsArray[2], argsArray[3], argsArray[4], argsArray[5]);
|
|
1026
|
+
}
|
|
1027
|
+
else {
|
|
1028
|
+
this.adapter.log.warn('[REMOTE] Unsupported number of arguments');
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
else if (name === 'ppng') {
|
|
1032
|
+
// ping
|
|
1033
|
+
promiseResult = Promise.resolve({ sid: message.sid, d: [_type, id, name, [null, !isNew]] });
|
|
1034
|
+
}
|
|
1035
|
+
else if (name === 'name') {
|
|
1036
|
+
const socket = this.sockets[message.sid];
|
|
1037
|
+
if (socket.name === undefined) {
|
|
1038
|
+
socket.name = name;
|
|
1039
|
+
this.adapter.log.info(`[REMOTE] socket ${message.sid} connected with name "${name}"`);
|
|
1040
|
+
}
|
|
1041
|
+
else if (socket.name !== name) {
|
|
1042
|
+
this.adapter.log.warn(`[REMOTE] socket ${message.sid} changed socket name from ${socket.name} to ${name}`);
|
|
1043
|
+
socket.name = name;
|
|
1044
|
+
}
|
|
1045
|
+
// start garbage collector
|
|
1046
|
+
this.gcInterval = this.gcInterval || setInterval(() => this._clearMemory(), 60000);
|
|
1047
|
+
promiseResult = Promise.resolve({ sid: message.sid, d: [_type, id, name, []] });
|
|
1048
|
+
}
|
|
1049
|
+
else if (name === 'authenticate') {
|
|
1050
|
+
promiseResult = Promise.resolve({ sid: message.sid, d: [_type, id, name, [true, false]] });
|
|
1051
|
+
}
|
|
1052
|
+
else if (name === 'getObjects') {
|
|
1053
|
+
promiseOne = this._readAllObjects();
|
|
1054
|
+
}
|
|
1055
|
+
else if (name === 'getHostByIp') {
|
|
1056
|
+
promiseResult = adminCommonSocket_1.default.getHostByIp(this.adapter, args[0]).then(result => ({
|
|
1057
|
+
sid: message.sid,
|
|
1058
|
+
d: [_type, id, name, [result.ip, result.obj]],
|
|
1059
|
+
}));
|
|
1060
|
+
}
|
|
1061
|
+
else if (name === 'getStates') {
|
|
1062
|
+
promiseOne = this.adapter.getForeignStatesAsync(args[0] || '*');
|
|
1063
|
+
}
|
|
1064
|
+
else if (name === 'requireLog') {
|
|
1065
|
+
const isEnabled = args[0];
|
|
1066
|
+
if (isEnabled) {
|
|
1067
|
+
this._subscribe(message.sid, 'log', 'dummy');
|
|
1068
|
+
}
|
|
1069
|
+
else {
|
|
1070
|
+
this._unsubscribe(message.sid, 'log', 'dummy');
|
|
1071
|
+
}
|
|
1072
|
+
if (this.adapter.log.level === 'debug') {
|
|
1073
|
+
this._showSubscribes(message.sid, 'log');
|
|
1074
|
+
}
|
|
1075
|
+
promiseOne = Promise.resolve({ sid: message.sid, d: [_type, id, name, [null]] });
|
|
1076
|
+
}
|
|
1077
|
+
else if (name === 'DCT') {
|
|
1078
|
+
// disconnect
|
|
1079
|
+
const socket = this.sockets[message.sid];
|
|
1080
|
+
this.adapter.log.debug(`[REMOTE] ---- DISCONNECT ${message.sid}`);
|
|
1081
|
+
if (socket) {
|
|
1082
|
+
this._unsubscribeSocket(message.sid, 'stateChange');
|
|
1083
|
+
this._unsubscribeSocket(message.sid, 'objectChange');
|
|
1084
|
+
this._unsubscribeSocket(message.sid, 'log');
|
|
1085
|
+
delete this.sockets[message.sid];
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
else if (name === 'getVersion') {
|
|
1089
|
+
promiseResult = Promise.resolve({
|
|
1090
|
+
sid: message.sid,
|
|
1091
|
+
d: [_type, id, name, [null, this.adminObj?.common.version, 'admin']],
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
else if (name === 'subscribe' || name === 'subscribeStates') {
|
|
1095
|
+
const pattern = args[0];
|
|
1096
|
+
if (Array.isArray(pattern)) {
|
|
1097
|
+
for (let p = 0; p < pattern.length; p++) {
|
|
1098
|
+
this._subscribe(message.sid, 'stateChange', pattern[p]);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
else {
|
|
1102
|
+
this._subscribe(message.sid, 'stateChange', pattern);
|
|
1103
|
+
}
|
|
1104
|
+
this.adapter.log.level === 'debug' && this._showSubscribes(message.sid, 'stateChange');
|
|
1105
|
+
promiseOne = Promise.resolve({ sid: message.sid, d: [_type, id, name, [null]] });
|
|
1106
|
+
}
|
|
1107
|
+
else if (name === 'unsubscribe' || name === 'unsubscribeStates') {
|
|
1108
|
+
const pattern = args[0];
|
|
1109
|
+
if (Array.isArray(pattern)) {
|
|
1110
|
+
for (let p = 0; p < pattern.length; p++) {
|
|
1111
|
+
this._unsubscribe(message.sid, 'stateChange', pattern[p]);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
else {
|
|
1115
|
+
this._unsubscribe(message.sid, 'stateChange', pattern);
|
|
1116
|
+
}
|
|
1117
|
+
this.adapter.log.level === 'debug' && this._showSubscribes(message.sid, 'stateChange');
|
|
1118
|
+
promiseOne = Promise.resolve({ sid: message.sid, d: [_type, id, name, [null]] });
|
|
1119
|
+
}
|
|
1120
|
+
else if (name === 'subscribeObjects') {
|
|
1121
|
+
const pattern = args?.[0] || '*';
|
|
1122
|
+
if (Array.isArray(pattern)) {
|
|
1123
|
+
for (let p = 0; p < pattern.length; p++) {
|
|
1124
|
+
this._subscribe(message.sid, 'objectChange', pattern[p]);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
else {
|
|
1128
|
+
this._subscribe(message.sid, 'objectChange', pattern);
|
|
1129
|
+
}
|
|
1130
|
+
this.adapter.log.level === 'debug' && this._showSubscribes(message.sid, 'objectChange');
|
|
1131
|
+
promiseOne = Promise.resolve({ sid: message.sid, d: [_type, id, name, [null]] });
|
|
1132
|
+
}
|
|
1133
|
+
else if (name === 'unsubscribeObjects') {
|
|
1134
|
+
const pattern = args[0];
|
|
1135
|
+
if (Array.isArray(pattern)) {
|
|
1136
|
+
for (let p = 0; p < pattern.length; p++) {
|
|
1137
|
+
this._unsubscribe(message.sid, 'objectChange', pattern[p]);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
else {
|
|
1141
|
+
this._unsubscribe(message.sid, 'objectChange', pattern);
|
|
1142
|
+
}
|
|
1143
|
+
this.adapter.log.level === 'debug' && this._showSubscribes(message.sid, 'objectChange');
|
|
1144
|
+
promiseOne = Promise.resolve({ sid: message.sid, d: [_type, id, name, [null]] });
|
|
1145
|
+
}
|
|
1146
|
+
else if (name === 'authEnabled') {
|
|
1147
|
+
promiseResult = Promise.resolve({ sid: message.sid, d: [_type, id, name, [false, 'admin']] });
|
|
1148
|
+
}
|
|
1149
|
+
else if (name === 'readFile') {
|
|
1150
|
+
const adapter = args[0];
|
|
1151
|
+
const fileName = args[1];
|
|
1152
|
+
promiseResult = this.adapter
|
|
1153
|
+
.readFileAsync(adapter, fileName)
|
|
1154
|
+
.then(data => this._sendResponse(message.sid, _type, id, name, [null, data.file, data.mimeType], message.wu, message.ru))
|
|
1155
|
+
.catch(error => ({ sid: message.sid, d: [_type, id, name, [error]] }));
|
|
1156
|
+
}
|
|
1157
|
+
else if (name === 'readFile64') {
|
|
1158
|
+
const adapter = args[0];
|
|
1159
|
+
const fileName = args[1];
|
|
1160
|
+
promiseResult = this.adapter
|
|
1161
|
+
.readFileAsync(adapter, fileName)
|
|
1162
|
+
.then(data => {
|
|
1163
|
+
let data64;
|
|
1164
|
+
if (data.mimeType) {
|
|
1165
|
+
try {
|
|
1166
|
+
if (data.mimeType === 'application/json' ||
|
|
1167
|
+
data.mimeType === 'application/json5' ||
|
|
1168
|
+
fileName.toLowerCase().endsWith('.json5')) {
|
|
1169
|
+
data64 = Buffer.from(encodeURIComponent(data.mimeType)).toString('base64');
|
|
1170
|
+
}
|
|
1171
|
+
else if (data.mimeType) {
|
|
1172
|
+
data64 = Buffer.from(data.mimeType).toString('base64');
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
catch (error) {
|
|
1176
|
+
this.adapter.log.error(`[readFile64] Cannot convert data: ${error.toString()}`);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
return this._sendResponse(message.sid, _type, id, name, [null, data64, data.mimeType], message.wu, message.ru);
|
|
1180
|
+
})
|
|
1181
|
+
.catch(error => ({ sid: message.sid, d: [_type, id, name, [error]] }));
|
|
1182
|
+
}
|
|
1183
|
+
else if (name === 'writeFile' || name === 'writeFile64') {
|
|
1184
|
+
const [adr, fileName, data64, options] = args;
|
|
1185
|
+
if (readUrl) {
|
|
1186
|
+
promiseOne = (0, axios_1.default)(readUrl, {
|
|
1187
|
+
responseType: 'arraybuffer',
|
|
1188
|
+
validateStatus: status => status === 200,
|
|
1189
|
+
timeout: 15000,
|
|
1190
|
+
}).then(response => this.adapter.writeFileAsync(adr, fileName, Buffer.from(response.data), options));
|
|
1191
|
+
}
|
|
1192
|
+
else if (name === 'writeFile') {
|
|
1193
|
+
this.adapter.log.debug('writeFile deprecated. Please use writeFile64');
|
|
1194
|
+
promiseOne = this.adapter.writeFileAsync(adr, fileName, data64, options);
|
|
1195
|
+
}
|
|
1196
|
+
else if (name === 'writeFile64') {
|
|
1197
|
+
const buffer = Buffer.from(data64, 'base64');
|
|
1198
|
+
promiseOne = this.adapter.writeFileAsync(adr, fileName, buffer, options);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
else if (name === 'getHistory') {
|
|
1202
|
+
const _id = args[0];
|
|
1203
|
+
const options = args[1];
|
|
1204
|
+
promiseResult = this.adapter
|
|
1205
|
+
.getHistoryAsync(_id, options)
|
|
1206
|
+
.then(data => this._sendResponse(message.sid, _type, id, name, [null, data.result, data.step, data.sessionId], message.wu, message.ru))
|
|
1207
|
+
.catch(error => ({ sid: message.sid, d: [_type, id, name, [error]] }));
|
|
1208
|
+
}
|
|
1209
|
+
else if (name === 'getEasyMode') {
|
|
1210
|
+
promiseOne = adminCommonSocket_1.default.getEasyMode(this.adapter, this.adminObj);
|
|
1211
|
+
}
|
|
1212
|
+
else if (name === 'getAdapterInstances') {
|
|
1213
|
+
promiseOne = adminCommonSocket_1.default.getAdapterInstances(this.adapter, args[0]);
|
|
1214
|
+
}
|
|
1215
|
+
else if (name === 'getCurrentInstance') {
|
|
1216
|
+
promiseOne = Promise.resolve(this.config.remoteAdminInstance);
|
|
1217
|
+
}
|
|
1218
|
+
else if (name === 'checkFeatureSupported') {
|
|
1219
|
+
promiseOne = Promise.resolve(this.adapter.supportsFeature?.(args[0]));
|
|
1220
|
+
}
|
|
1221
|
+
else if (name === 'getAdapterName') {
|
|
1222
|
+
promiseOne = Promise.resolve('admin');
|
|
1223
|
+
}
|
|
1224
|
+
else if (name === 'decrypt') {
|
|
1225
|
+
if (this.secret) {
|
|
1226
|
+
promiseOne = Promise.resolve(this.adapter.decrypt(this.secret, args[0]));
|
|
1227
|
+
}
|
|
1228
|
+
else {
|
|
1229
|
+
promiseOne = this.adapter.getForeignObjectAsync('system.config', (err, obj) => {
|
|
1230
|
+
if (obj?.native?.secret) {
|
|
1231
|
+
this.secret = obj.native.secret;
|
|
1232
|
+
return this.adapter.decrypt(this.secret, args[0]);
|
|
1233
|
+
}
|
|
1234
|
+
this.adapter.log.error(`No system.config found: ${err}`);
|
|
1235
|
+
throw new Error('No system.config found');
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
else if (name === 'encrypt') {
|
|
1240
|
+
if (this.secret) {
|
|
1241
|
+
promiseOne = Promise.resolve(this.adapter.encrypt(this.secret, args[0]));
|
|
1242
|
+
}
|
|
1243
|
+
else {
|
|
1244
|
+
promiseOne = this.adapter.getForeignObjectAsync('system.config', (err, obj) => {
|
|
1245
|
+
if (obj?.native?.secret) {
|
|
1246
|
+
this.secret = obj.native.secret;
|
|
1247
|
+
return this.adapter.encrypt(this.secret, args[0]);
|
|
1248
|
+
}
|
|
1249
|
+
this.adapter.log.error(`No system.config found: ${err}`);
|
|
1250
|
+
throw new Error('No system.config found');
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
else if (name === 'getIsEasyModeStrict') {
|
|
1255
|
+
promiseOne = adminCommonSocket_1.default.getIsEasyModeStrict(this.adapter, this.adminObj);
|
|
1256
|
+
}
|
|
1257
|
+
else if (name === 'getAdapters') {
|
|
1258
|
+
promiseOne = adminCommonSocket_1.default.getAdapters(this.adapter, args[0]);
|
|
1259
|
+
}
|
|
1260
|
+
else if (name === 'updateLicenses') {
|
|
1261
|
+
promiseOne = adminCommonSocket_1.default.updateLicenses(this.adapter, args[0], args[1], this.adminObj);
|
|
1262
|
+
}
|
|
1263
|
+
else if (name === 'getCompactInstances') {
|
|
1264
|
+
promiseOne = adminCommonSocket_1.default.getCompactInstances(this.adapter);
|
|
1265
|
+
}
|
|
1266
|
+
else if (name === 'getCompactSystemRepositories') {
|
|
1267
|
+
promiseOne = adminCommonSocket_1.default.getCompactSystemRepositories(this.adapter);
|
|
1268
|
+
}
|
|
1269
|
+
else if (name === 'getCompactAdapters') {
|
|
1270
|
+
promiseOne = adminCommonSocket_1.default.getCompactAdapters(this.adapter);
|
|
1271
|
+
}
|
|
1272
|
+
else if (name === 'getCompactInstalled') {
|
|
1273
|
+
promiseResult = adminCommonSocket_1.default.getCompactInstalled(this.adapter, args[0] || this.adminObj?.common.host || this.adapter.common.host).then(data => ({ sid: message.sid, d: [_type, id, name, [data]] }));
|
|
1274
|
+
}
|
|
1275
|
+
else if (name === 'getCompactSystemConfig') {
|
|
1276
|
+
promiseOne = adminCommonSocket_1.default.getCompactSystemConfig(this.adapter);
|
|
1277
|
+
}
|
|
1278
|
+
else if (name === 'getCompactRepository') {
|
|
1279
|
+
promiseResult = adminCommonSocket_1.default.getCompactRepository(this.adapter, args[0] || this.adminObj?.common.host || this.adapter.common.host).then(data => ({ sid: message.sid, d: [_type, id, name, [data]] }));
|
|
1280
|
+
}
|
|
1281
|
+
else if (name === 'getCompactHosts') {
|
|
1282
|
+
promiseOne = adminCommonSocket_1.default.getCompactHosts(this.adapter);
|
|
1283
|
+
}
|
|
1284
|
+
else if (name === 'readLogs') {
|
|
1285
|
+
promiseOne = adminCommonSocket_1.default.readLogs(this.adapter, args[0] || this.adminObj?.common.host || this.adapter.common.host);
|
|
1286
|
+
}
|
|
1287
|
+
else if (name === 'eventsThreshold') {
|
|
1288
|
+
promiseOne = Promise.resolve(NONE);
|
|
1289
|
+
}
|
|
1290
|
+
else if (name === 'getRatings') {
|
|
1291
|
+
promiseOne = adminCommonSocket_1.default.getRatings(this.adapter, args[0], args[1]);
|
|
1292
|
+
}
|
|
1293
|
+
else if (name === 'getUserPermissions') {
|
|
1294
|
+
this.adapter.log.error(`[REMOTE] getUserPermissions not implemented!!!!!!!!!!!!!!!!!!!!!`);
|
|
1295
|
+
}
|
|
1296
|
+
else if (name === 'listPermissions') {
|
|
1297
|
+
promiseResult = adminCommonSocket_1.default.listPermissions(this.adapter)
|
|
1298
|
+
.then(commandsPermissions => this._sendResponse(message.sid, _type, id, name, [commandsPermissions]))
|
|
1299
|
+
.catch(error => ({ sid: message.sid, d: [_type, id, name, [error]] }));
|
|
1300
|
+
}
|
|
1301
|
+
else if (name === 'sendToHost') {
|
|
1302
|
+
const [host, command, msg] = args;
|
|
1303
|
+
this.adapter.log.debug(`[REMOTE] SEND_TO_HOST: ${command}`);
|
|
1304
|
+
// check if the host is alive
|
|
1305
|
+
promiseResult = adminCommonSocket_1.default.sendToHost(this.adapter, host, command, msg)
|
|
1306
|
+
.then(data => this._sendResponse(message.sid, _type, id, name, [data], message.wu, message.ru))
|
|
1307
|
+
.catch(error => ({ sid: message.sid, d: [_type, id, name, [error]] }));
|
|
1308
|
+
}
|
|
1309
|
+
else if (name === 'sendTo') {
|
|
1310
|
+
const [adapterInstance, command, message] = args;
|
|
1311
|
+
promiseResult = adminCommonSocket_1.default.sendTo(this.adapter, adapterInstance, command, message)
|
|
1312
|
+
.then(data => this._sendResponse(message.sid, _type, id, name, [data], message.wu, message.ru))
|
|
1313
|
+
.catch(error => ({ sid: message.sid, d: [_type, id, name, [error]] }));
|
|
1314
|
+
}
|
|
1315
|
+
else if (name === 'getAllObjects') {
|
|
1316
|
+
promiseOne = adminCommonSocket_1.default.getAllObjects(this.adapter);
|
|
1317
|
+
}
|
|
1318
|
+
// MESSAGE is the only one-way message and no answer is expected
|
|
1319
|
+
if (_type === MESSAGE_TYPES.MESSAGE || _type === MESSAGE_TYPES.COMBINED_MESSAGE) {
|
|
1320
|
+
promiseResult = promiseOne ? promiseOne.then(() => NONE) : Promise.resolve(NONE);
|
|
1321
|
+
}
|
|
1322
|
+
else if (!promiseResult && promiseOne) {
|
|
1323
|
+
promiseResult = promiseOne
|
|
1324
|
+
.then(result => this._sendResponse(message.sid, _type, id, name, [null, result], message.wu, message.ru))
|
|
1325
|
+
.catch(error => ({ sid: message.sid, d: [_type, id, name, [error]] }));
|
|
1326
|
+
}
|
|
1327
|
+
if (!promiseResult) {
|
|
1328
|
+
this.adapter.log.warn(`[REMOTE] Received unknown command: ${name}`);
|
|
1329
|
+
promiseResult = Promise.resolve({ sid: message.sid, d: [_type, id, name, ['Unknown command']] });
|
|
1330
|
+
}
|
|
1331
|
+
return promiseResult.then(result => {
|
|
1332
|
+
if (result !== NONE && result.d && result.d[0] !== MESSAGE_TYPES.WAIT) {
|
|
1333
|
+
setImmediate(async (_result, _message) => await this._sendEvent(_result, _message), result, message);
|
|
1334
|
+
}
|
|
1335
|
+
return NONE;
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
return Promise.reject(new Error('Null message'));
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
exports.default = RemoteAccess;
|
|
1342
|
+
//# sourceMappingURL=remote.js.map
|