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