@iobroker/adapter-react-v5 4.7.15 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/Components/JsonConfigComponent/ConfigAccordion.d.ts +1 -1
  2. package/Components/JsonConfigComponent/ConfigAccordion.js +4 -6
  3. package/Components/JsonConfigComponent/ConfigAccordion.js.map +1 -1
  4. package/Components/JsonConfigComponent/ConfigAlive.d.ts +2 -2
  5. package/Components/JsonConfigComponent/ConfigAutocomplete.d.ts +36 -13
  6. package/Components/JsonConfigComponent/ConfigAutocomplete.js +66 -164
  7. package/Components/JsonConfigComponent/ConfigAutocompleteSendTo.d.ts +16 -13
  8. package/Components/JsonConfigComponent/ConfigAutocompleteSendTo.js +119 -251
  9. package/Components/JsonConfigComponent/ConfigCRON.d.ts +2 -2
  10. package/Components/JsonConfigComponent/ConfigCertCollection.d.ts +2 -2
  11. package/Components/JsonConfigComponent/ConfigCertificateSelect.d.ts +2 -2
  12. package/Components/JsonConfigComponent/ConfigCertificates.d.ts +2 -2
  13. package/Components/JsonConfigComponent/ConfigCheckbox.d.ts +14 -13
  14. package/Components/JsonConfigComponent/ConfigCheckbox.js +37 -79
  15. package/Components/JsonConfigComponent/ConfigChip.d.ts +2 -2
  16. package/Components/JsonConfigComponent/ConfigColor.d.ts +2 -2
  17. package/Components/JsonConfigComponent/ConfigCoordinates.d.ts +2 -2
  18. package/Components/JsonConfigComponent/ConfigDatePicker.d.ts +2 -2
  19. package/Components/JsonConfigComponent/ConfigDeviceManager.d.ts +6 -0
  20. package/Components/JsonConfigComponent/ConfigDeviceManager.js +18 -0
  21. package/Components/JsonConfigComponent/ConfigFile.d.ts +2 -2
  22. package/Components/JsonConfigComponent/ConfigFile.js +2 -2
  23. package/Components/JsonConfigComponent/ConfigFile.js.map +1 -1
  24. package/Components/JsonConfigComponent/ConfigFileSelector.js +8 -5
  25. package/Components/JsonConfigComponent/ConfigFileSelector.js.map +1 -1
  26. package/Components/JsonConfigComponent/ConfigFunc.d.ts +2 -2
  27. package/Components/JsonConfigComponent/ConfigGeneric.d.ts +12 -4
  28. package/Components/JsonConfigComponent/ConfigGeneric.js +11 -2
  29. package/Components/JsonConfigComponent/ConfigIP.d.ts +2 -2
  30. package/Components/JsonConfigComponent/ConfigImageSendTo.d.ts +2 -2
  31. package/Components/JsonConfigComponent/ConfigImageUpload.js +38 -44
  32. package/Components/JsonConfigComponent/ConfigImageUpload.js.map +1 -1
  33. package/Components/JsonConfigComponent/ConfigInstanceSelect.d.ts +2 -2
  34. package/Components/JsonConfigComponent/ConfigInterface.d.ts +2 -2
  35. package/Components/JsonConfigComponent/ConfigInterface.js +1 -1
  36. package/Components/JsonConfigComponent/ConfigInterface.js.map +1 -1
  37. package/Components/JsonConfigComponent/ConfigJsonEditor.d.ts +2 -2
  38. package/Components/JsonConfigComponent/ConfigJsonEditor.js +0 -1
  39. package/Components/JsonConfigComponent/ConfigJsonEditor.js.map +1 -1
  40. package/Components/JsonConfigComponent/ConfigLanguage.d.ts +6 -13
  41. package/Components/JsonConfigComponent/ConfigLanguage.js +105 -154
  42. package/Components/JsonConfigComponent/ConfigLicense.d.ts +1 -1
  43. package/Components/JsonConfigComponent/ConfigNumber.d.ts +1 -1
  44. package/Components/JsonConfigComponent/ConfigObjectId.d.ts +2 -2
  45. package/Components/JsonConfigComponent/ConfigPanel.js +8 -1
  46. package/Components/JsonConfigComponent/ConfigPanel.js.map +1 -1
  47. package/Components/JsonConfigComponent/ConfigPassword.d.ts +2 -2
  48. package/Components/JsonConfigComponent/ConfigPattern.d.ts +2 -2
  49. package/Components/JsonConfigComponent/ConfigRoom.d.ts +2 -2
  50. package/Components/JsonConfigComponent/ConfigSelect.d.ts +2 -2
  51. package/Components/JsonConfigComponent/ConfigSelectSendTo.d.ts +2 -2
  52. package/Components/JsonConfigComponent/ConfigSendto.d.ts +23 -17
  53. package/Components/JsonConfigComponent/ConfigSendto.js +259 -399
  54. package/Components/JsonConfigComponent/ConfigSetState.d.ts +2 -2
  55. package/Components/JsonConfigComponent/ConfigSlider.d.ts +2 -2
  56. package/Components/JsonConfigComponent/ConfigStaticDivider.d.ts +2 -2
  57. package/Components/JsonConfigComponent/ConfigStaticHeader.d.ts +2 -2
  58. package/Components/JsonConfigComponent/ConfigStaticImage.d.ts +2 -2
  59. package/Components/JsonConfigComponent/ConfigStaticText.d.ts +2 -2
  60. package/Components/JsonConfigComponent/ConfigText.d.ts +2 -2
  61. package/Components/JsonConfigComponent/ConfigText.js +18 -0
  62. package/Components/JsonConfigComponent/ConfigText.js.map +1 -1
  63. package/Components/JsonConfigComponent/ConfigTextSendTo.d.ts +2 -2
  64. package/Components/JsonConfigComponent/ConfigTimePicker.d.ts +2 -2
  65. package/Components/JsonConfigComponent/ConfigTopic.d.ts +2 -2
  66. package/Components/JsonConfigComponent/ConfigUUID.d.ts +2 -2
  67. package/Components/JsonConfigComponent/ConfigUser.d.ts +2 -2
  68. package/Components/JsonConfigComponent/DeviceManager/Communication.d.ts +63 -0
  69. package/Components/JsonConfigComponent/DeviceManager/Communication.js +268 -0
  70. package/Components/JsonConfigComponent/DeviceManager/DeviceActionButton.d.ts +11 -0
  71. package/Components/JsonConfigComponent/DeviceManager/DeviceActionButton.js +15 -0
  72. package/Components/JsonConfigComponent/DeviceManager/DeviceCard.d.ts +53 -0
  73. package/Components/JsonConfigComponent/DeviceManager/DeviceCard.js +340 -0
  74. package/Components/JsonConfigComponent/DeviceManager/DeviceControl.d.ts +45 -0
  75. package/Components/JsonConfigComponent/DeviceManager/DeviceControl.js +146 -0
  76. package/Components/JsonConfigComponent/DeviceManager/DeviceImageUpload.d.ts +12 -0
  77. package/Components/JsonConfigComponent/DeviceManager/DeviceImageUpload.js +69 -0
  78. package/Components/JsonConfigComponent/DeviceManager/DeviceList.d.ts +51 -0
  79. package/Components/JsonConfigComponent/DeviceManager/DeviceList.js +216 -0
  80. package/Components/JsonConfigComponent/DeviceManager/DeviceStatus.d.ts +13 -0
  81. package/Components/JsonConfigComponent/DeviceManager/DeviceStatus.js +111 -0
  82. package/Components/JsonConfigComponent/DeviceManager/InstanceActionButton.d.ts +7 -0
  83. package/Components/JsonConfigComponent/DeviceManager/InstanceActionButton.js +16 -0
  84. package/Components/JsonConfigComponent/DeviceManager/JsonConfig.d.ts +11 -0
  85. package/Components/JsonConfigComponent/DeviceManager/JsonConfig.js +94 -0
  86. package/Components/JsonConfigComponent/DeviceManager/TooltipButton.d.ts +10 -0
  87. package/Components/JsonConfigComponent/DeviceManager/TooltipButton.js +22 -0
  88. package/Components/JsonConfigComponent/DeviceManager/Utils.d.ts +12 -0
  89. package/Components/JsonConfigComponent/DeviceManager/Utils.js +158 -0
  90. package/Components/JsonConfigComponent/DeviceManager/i18n/de.json +21 -0
  91. package/Components/JsonConfigComponent/DeviceManager/i18n/en.json +21 -0
  92. package/Components/JsonConfigComponent/DeviceManager/i18n/es.json +21 -0
  93. package/Components/JsonConfigComponent/DeviceManager/i18n/fr.json +21 -0
  94. package/Components/JsonConfigComponent/DeviceManager/i18n/i18n.d.ts +26 -0
  95. package/Components/JsonConfigComponent/DeviceManager/i18n/it.json +21 -0
  96. package/Components/JsonConfigComponent/DeviceManager/i18n/nl.json +21 -0
  97. package/Components/JsonConfigComponent/DeviceManager/i18n/pl.json +21 -0
  98. package/Components/JsonConfigComponent/DeviceManager/i18n/pt.json +21 -0
  99. package/Components/JsonConfigComponent/DeviceManager/i18n/ru.json +21 -0
  100. package/Components/JsonConfigComponent/DeviceManager/i18n/uk.json +21 -0
  101. package/Components/JsonConfigComponent/DeviceManager/i18n/zh-cn.json +21 -0
  102. package/Components/JsonConfigComponent/DeviceManager/index.d.ts +2 -0
  103. package/Components/JsonConfigComponent/DeviceManager/index.js +10 -0
  104. package/Components/JsonConfigComponent/DeviceManager/index.js.map +1 -0
  105. package/Components/JsonConfigComponent/index.js +2 -7
  106. package/Components/JsonConfigComponent/index.js.map +1 -1
  107. package/Components/TextWithIcon.d.ts +1 -1
  108. package/Dialogs/ComplexCron.js +15 -17
  109. package/Dialogs/ComplexCron.js.map +1 -1
  110. package/Dialogs/Confirm.d.ts +20 -44
  111. package/Dialogs/Confirm.js +102 -158
  112. package/Dialogs/Error.d.ts +20 -39
  113. package/Dialogs/Error.js +50 -76
  114. package/Dialogs/Message.d.ts +22 -32
  115. package/Dialogs/Message.js +51 -83
  116. package/LegacyConnection.d.ts +3 -3
  117. package/README.md +7 -4
  118. package/i18n.d.ts +6 -6
  119. package/package.json +6 -5
  120. package/Components/JsonConfigComponent/ConfigAutocomplete.js.map +0 -1
  121. package/Components/JsonConfigComponent/ConfigAutocompleteSendTo.js.map +0 -1
  122. package/Components/JsonConfigComponent/ConfigCheckbox.js.map +0 -1
  123. package/Components/JsonConfigComponent/ConfigLanguage.js.map +0 -1
  124. package/Components/JsonConfigComponent/ConfigSendto.js.map +0 -1
  125. package/Dialogs/Confirm.js.map +0 -1
  126. package/Dialogs/Error.js.map +0 -1
  127. package/Dialogs/Message.js.map +0 -1
@@ -1,434 +1,294 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports["default"] = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
14
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
15
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
16
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
17
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
18
- var _react = _interopRequireDefault(require("react"));
19
- var _propTypes = _interopRequireDefault(require("prop-types"));
20
- var _styles = require("@mui/styles");
21
- var _material = require("@mui/material");
22
- var _iconsMaterial = require("@mui/icons-material");
23
- var _i18n = _interopRequireDefault(require("./wrapper/i18n"));
24
- var _Error = _interopRequireDefault(require("./wrapper/Dialogs/Error"));
25
- var _Message = _interopRequireDefault(require("./wrapper/Dialogs/Message"));
26
- var _Confirm = _interopRequireDefault(require("./wrapper/Dialogs/Confirm"));
27
- var _ConfigGeneric2 = _interopRequireDefault(require("./ConfigGeneric"));
28
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
29
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
30
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
31
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
32
- var styles = function styles() {
33
- return {
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 react_1 = __importDefault(require("react"));
7
+ const styles_1 = require("@mui/styles");
8
+ const material_1 = require("@mui/material");
9
+ const icons_material_1 = require("@mui/icons-material");
10
+ const i18n_1 = __importDefault(require("./wrapper/i18n"));
11
+ const Error_1 = __importDefault(require("./wrapper/Dialogs/Error"));
12
+ const Message_1 = __importDefault(require("./wrapper/Dialogs/Message"));
13
+ const Confirm_1 = __importDefault(require("./wrapper/Dialogs/Confirm"));
14
+ const ConfigGeneric_1 = __importDefault(require("./ConfigGeneric"));
15
+ const styles = () => ({
34
16
  fullWidth: {
35
- width: '100%'
17
+ width: '100%',
36
18
  },
37
19
  icon: {
38
- width: 24,
39
- height: 24,
40
- marginRight: 4
41
- }
42
- };
43
- };
20
+ width: 24,
21
+ height: 24,
22
+ marginRight: 4,
23
+ },
24
+ });
44
25
  function ip2int(ip) {
45
- // eslint-disable-next-line no-bitwise
46
- return ip.split('.').reduce(function (ipInt, octet) {
47
- return (ipInt << 8) + parseInt(octet, 10);
48
- }, 0) >>> 0;
26
+ // eslint-disable-next-line no-bitwise
27
+ return ip.split('.').reduce((ipInt, octet) => (ipInt << 8) + parseInt(octet, 10), 0) >>> 0;
49
28
  }
50
-
51
29
  // copied from iobroker.admin/src-rx/src/Utils.js
52
30
  function findNetworkAddressOfHost(obj, localIp) {
53
- var _obj$native;
54
- var networkInterfaces = obj === null || obj === void 0 || (_obj$native = obj["native"]) === null || _obj$native === void 0 || (_obj$native = _obj$native.hardware) === null || _obj$native === void 0 ? void 0 : _obj$native.networkInterfaces;
55
- if (!networkInterfaces) {
56
- return null;
57
- }
58
- var hostIp;
59
-
60
- // check ipv4 addresses
61
- Object.keys(networkInterfaces).forEach(function (inter) {
62
- return networkInterfaces[inter].forEach(function (ip) {
63
- if (ip.internal) {
64
- return;
65
- }
66
- if (localIp.includes(':') && ip.family !== 'IPv6') {
67
- return;
68
- }
69
- if (localIp.includes('.') && !localIp.match(/[^.\d]/) && ip.family !== 'IPv4') {
70
- return;
71
- }
72
- // if ip4 and not docker or wsl
73
- if (ip.family === 'IPv4' && !ip.address.startsWith('172') && (localIp === '127.0.0.0' || localIp === 'localhost' || localIp.match(/[^.\d]/))) {
74
- // if DNS name
75
- hostIp = ip.address;
76
- } else if (!hostIp) {
77
- if (ip.family === 'IPv4' && localIp.includes('.') &&
78
- // eslint-disable-next-line no-bitwise
79
- (ip2int(localIp) & ip2int(ip.netmask)) === (ip2int(ip.address) & ip2int(ip.netmask))) {
80
- hostIp = ip.address;
81
- } else {
82
- hostIp = ip.address;
83
- }
84
- }
85
- });
86
- });
87
-
88
- // check ipv6 addresses
89
- if (!hostIp) {
90
- Object.keys(networkInterfaces).forEach(function (inter) {
91
- return networkInterfaces[inter].forEach(function (ip) {
31
+ var _a, _b;
32
+ const networkInterfaces = (_b = (_a = obj === null || obj === void 0 ? void 0 : obj.native) === null || _a === void 0 ? void 0 : _a.hardware) === null || _b === void 0 ? void 0 : _b.networkInterfaces;
33
+ if (!networkInterfaces) {
34
+ return null;
35
+ }
36
+ let hostIp;
37
+ // check ipv4 addresses
38
+ Object.keys(networkInterfaces).forEach(inter => networkInterfaces[inter].forEach((ip) => {
92
39
  if (ip.internal) {
93
- return;
40
+ return;
94
41
  }
95
42
  if (localIp.includes(':') && ip.family !== 'IPv6') {
96
- return;
43
+ return;
97
44
  }
98
45
  if (localIp.includes('.') && !localIp.match(/[^.\d]/) && ip.family !== 'IPv4') {
99
- return;
46
+ return;
100
47
  }
101
- if (ip.family === 'IPv6' && (localIp === '127.0.0.0' || localIp === 'localhost' || localIp.match(/[^.\d]/))) {
102
- // if DNS name
103
- hostIp = ip.address;
104
- } else if (!hostIp) {
105
- if (ip.family === 'IPv4' && localIp.includes('.') &&
106
- // eslint-disable-next-line no-bitwise
107
- (ip2int(localIp) & ip2int(ip.netmask)) === (ip2int(ip.address) & ip2int(ip.netmask))) {
48
+ // if ip4 and not docker or wsl
49
+ if (ip.family === 'IPv4' && !ip.address.startsWith('172') && (localIp === '127.0.0.0' || localIp === 'localhost' || localIp.match(/[^.\d]/))) { // if DNS name
108
50
  hostIp = ip.address;
109
- } else {
110
- hostIp = ip.address;
111
- }
112
- }
113
- });
114
- });
115
- }
116
- if (!hostIp) {
117
- Object.keys(networkInterfaces).forEach(function (inter) {
118
- networkInterfaces[inter].forEach(function (ip) {
119
- if (ip.internal) {
120
- return;
121
- }
122
- if (localIp.includes(':') && ip.family !== 'IPv6') {
123
- return;
124
51
  }
125
- if (localIp.includes('.') && !localIp.match(/[^.\d]/) && ip.family !== 'IPv4') {
126
- return;
127
- }
128
- if (localIp === '127.0.0.0' || localIp === 'localhost' || localIp.match(/[^.\d]/)) {
129
- // if DNS name
130
- hostIp = ip.address;
131
- } else {
132
- hostIp = ip.address;
133
- }
134
- });
135
- });
136
- }
137
- if (!hostIp) {
138
- Object.keys(networkInterfaces).forEach(function (inter) {
139
- networkInterfaces[inter].forEach(function (ip) {
140
- if (ip.internal) {
141
- return;
52
+ else if (!hostIp) {
53
+ if (ip.family === 'IPv4' && localIp.includes('.') &&
54
+ // eslint-disable-next-line no-bitwise
55
+ (ip2int(localIp) & ip2int(ip.netmask)) === (ip2int(ip.address) & ip2int(ip.netmask))) {
56
+ hostIp = ip.address;
57
+ }
58
+ else {
59
+ hostIp = ip.address;
60
+ }
142
61
  }
143
- hostIp = ip.address;
144
- });
145
- });
146
- }
147
- return hostIp;
148
- }
149
- var ConfigSendto = /*#__PURE__*/function (_ConfigGeneric) {
150
- (0, _inherits2["default"])(ConfigSendto, _ConfigGeneric);
151
- var _super = _createSuper(ConfigSendto);
152
- function ConfigSendto() {
153
- (0, _classCallCheck2["default"])(this, ConfigSendto);
154
- return _super.apply(this, arguments);
155
- }
156
- (0, _createClass2["default"])(ConfigSendto, [{
157
- key: "componentDidMount",
158
- value: function () {
159
- var _componentDidMount = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
160
- var hostname, adminInstance, instanceObj, hostObj, ip;
161
- return _regenerator["default"].wrap(function _callee$(_context) {
162
- while (1) switch (_context.prev = _context.next) {
163
- case 0:
164
- (0, _get2["default"])((0, _getPrototypeOf2["default"])(ConfigSendto.prototype), "componentDidMount", this).call(this);
165
- hostname = window.location.hostname;
166
- if (!this.props.schema.openUrl) {
167
- _context.next = 19;
168
- break;
169
- }
170
- _context.next = 5;
171
- return this.props.socket.getCurrentInstance();
172
- case 5:
173
- adminInstance = _context.sent;
174
- _context.next = 8;
175
- return this.props.socket.getObject("system.adapter.".concat(adminInstance));
176
- case 8:
177
- instanceObj = _context.sent;
178
- _context.next = 11;
179
- return this.props.socket.getObject("system.host.".concat(instanceObj.common.host));
180
- case 11:
181
- hostObj = _context.sent;
182
- ip = findNetworkAddressOfHost(hostObj, window.location.hostname);
183
- if (!ip) {
184
- _context.next = 17;
185
- break;
186
- }
187
- hostname = "".concat(ip, ":").concat(window.location.port);
188
- _context.next = 19;
189
- break;
190
- case 17:
191
- console.warn("Cannot find suitable IP in host ".concat(instanceObj.common.host, " for ").concat(instanceObj._id));
192
- return _context.abrupt("return");
193
- case 19:
194
- this.setState({
195
- _error: '',
196
- _message: '',
197
- hostname: hostname
198
- });
199
- case 20:
200
- case "end":
201
- return _context.stop();
202
- }
203
- }, _callee, this);
204
- }));
205
- function componentDidMount() {
206
- return _componentDidMount.apply(this, arguments);
207
- }
208
- return componentDidMount;
209
- }()
210
- }, {
211
- key: "renderErrorDialog",
212
- value: function renderErrorDialog() {
213
- var _this = this;
214
- if (this.state._error) {
215
- return /*#__PURE__*/_react["default"].createElement(_Error["default"], {
216
- text: this.state._error,
217
- classes: undefined,
218
- onClose: function onClose() {
219
- return _this.setState({
220
- _error: ''
62
+ }));
63
+ // check ipv6 addresses
64
+ if (!hostIp) {
65
+ Object.keys(networkInterfaces).forEach(inter => networkInterfaces[inter].forEach((ip) => {
66
+ if (ip.internal) {
67
+ return;
68
+ }
69
+ if (localIp.includes(':') && ip.family !== 'IPv6') {
70
+ return;
71
+ }
72
+ if (localIp.includes('.') && !localIp.match(/[^.\d]/) && ip.family !== 'IPv4') {
73
+ return;
74
+ }
75
+ if (ip.family === 'IPv6' && (localIp === '127.0.0.0' || localIp === 'localhost' || localIp.match(/[^.\d]/))) { // if DNS name
76
+ hostIp = ip.address;
77
+ }
78
+ else if (!hostIp) {
79
+ if (ip.family === 'IPv4' && localIp.includes('.') &&
80
+ // eslint-disable-next-line no-bitwise
81
+ (ip2int(localIp) & ip2int(ip.netmask)) === (ip2int(ip.address) & ip2int(ip.netmask))) {
82
+ hostIp = ip.address;
83
+ }
84
+ else {
85
+ hostIp = ip.address;
86
+ }
87
+ }
88
+ }));
89
+ }
90
+ if (!hostIp) {
91
+ Object.keys(networkInterfaces).forEach(inter => {
92
+ networkInterfaces[inter].forEach((ip) => {
93
+ if (ip.internal) {
94
+ return;
95
+ }
96
+ if (localIp.includes(':') && ip.family !== 'IPv6') {
97
+ return;
98
+ }
99
+ if (localIp.includes('.') && !localIp.match(/[^.\d]/) && ip.family !== 'IPv4') {
100
+ return;
101
+ }
102
+ if (localIp === '127.0.0.0' || localIp === 'localhost' || localIp.match(/[^.\d]/)) { // if DNS name
103
+ hostIp = ip.address;
104
+ }
105
+ else {
106
+ hostIp = ip.address;
107
+ }
221
108
  });
222
- }
223
109
  });
224
- }
225
- return null;
226
110
  }
227
- }, {
228
- key: "renderMessageDialog",
229
- value: function renderMessageDialog() {
230
- var _this2 = this;
231
- if (this.state._message) {
232
- return /*#__PURE__*/_react["default"].createElement(_Message["default"], {
233
- text: this.state._message,
234
- classes: undefined,
235
- onClose: function onClose() {
236
- return _this2.setState({
237
- _message: ''
111
+ if (!hostIp) {
112
+ Object.keys(networkInterfaces).forEach(inter => {
113
+ networkInterfaces[inter].forEach((ip) => {
114
+ if (ip.internal) {
115
+ return;
116
+ }
117
+ hostIp = ip.address;
238
118
  });
239
- }
240
119
  });
241
- }
242
- return null;
243
120
  }
244
- }, {
245
- key: "_onClick",
246
- value: function _onClick() {
247
- var _this3 = this;
248
- this.props.onCommandRunning(true);
249
- this.setState({
250
- running: true
251
- });
252
- var _origin = "".concat(window.location.protocol, "//").concat(window.location.host).concat(window.location.pathname.replace(/\/index\.html$/, ''));
253
- var _originIp = "".concat(window.location.protocol, "//").concat(this.state.hostname.split(':').length > 3 ? "[".concat(this.state.hostname, "]") : this.state.hostname).concat(window.location.pathname.replace(/\/index\.html$/, ''));
254
- var data = this.props.schema.data;
255
- if (data === undefined && this.props.schema.jsonData) {
256
- data = this.getPattern(this.props.schema.jsonData, _objectSpread({
257
- _origin: _origin,
258
- _originIp: _originIp
259
- }, this.props.data));
260
- try {
261
- data = JSON.parse(data);
262
- } catch (e) {
263
- console.error("Cannot parse json data: ".concat(data));
121
+ return hostIp;
122
+ }
123
+ class ConfigSendto extends ConfigGeneric_1.default {
124
+ async componentDidMount() {
125
+ var _a;
126
+ super.componentDidMount();
127
+ let hostname = window.location.hostname;
128
+ if (this.props.schema.openUrl) {
129
+ // read admin host
130
+ const adminInstance = await this.props.socket.getCurrentInstance();
131
+ // @ts-expect-error
132
+ const instanceObj = await this.props.socket.getObject(`system.adapter.${adminInstance}`);
133
+ if (instanceObj) {
134
+ const hostObj = await this.props.socket.getObject(`system.host.${(_a = instanceObj === null || instanceObj === void 0 ? void 0 : instanceObj.common) === null || _a === void 0 ? void 0 : _a.host}`);
135
+ if (hostObj) {
136
+ const ip = findNetworkAddressOfHost(hostObj, window.location.hostname);
137
+ if (ip) {
138
+ hostname = `${ip}:${window.location.port}`;
139
+ }
140
+ else {
141
+ console.warn(`Cannot find suitable IP in host ${instanceObj.common.host} for ${instanceObj._id}`);
142
+ return;
143
+ }
144
+ }
145
+ }
264
146
  }
265
- }
266
- if (data === undefined) {
267
- data = null;
268
- }
269
- if (this.props.schema.openUrl && !data) {
270
- data = {
271
- _origin: _origin,
272
- _originIp: _originIp
273
- };
274
- }
275
- var timeout;
276
- if (this.props.schema.timeout) {
277
- timeout = setTimeout(function () {
278
- _this3.props.onCommandRunning(false);
279
- _this3.setState({
280
- _error: _i18n["default"].t('ra_Request timed out'),
281
- running: false
282
- });
283
- }, parseInt(this.props.schema.timeout, 10) || 10000);
284
- }
285
- this.props.socket.sendTo("".concat(this.props.adapterName, ".").concat(this.props.instance), this.props.schema.command || 'send', data).then(function (response) {
286
- if (timeout) {
287
- clearTimeout(timeout);
288
- timeout = null;
147
+ await new Promise(resolve => { this.setState({ _error: '', _message: '', hostname }, resolve); });
148
+ if (this.props.schema.onLoaded) {
149
+ this._onClick();
150
+ }
151
+ }
152
+ renderErrorDialog() {
153
+ if (this.state._error) {
154
+ return react_1.default.createElement(Error_1.default, { text: this.state._error, onClose: () => this.setState({ _error: '' }) });
155
+ }
156
+ return null;
157
+ }
158
+ renderMessageDialog() {
159
+ if (this.state._message) {
160
+ return react_1.default.createElement(Message_1.default, { text: this.state._message, onClose: () => this.setState({ _message: '' }) });
289
161
  }
290
- if (response !== null && response !== void 0 && response.error) {
291
- if (_this3.props.schema.error && _this3.props.schema.error[response.error]) {
292
- var error = _this3.getText(_this3.props.schema.error[response.error]);
293
- if (response.args) {
294
- response.args.forEach(function (arg) {
295
- return error = error.replace('%s', arg);
296
- });
162
+ return null;
163
+ }
164
+ _onClick() {
165
+ this.props.onCommandRunning(true);
166
+ this.setState({ running: true });
167
+ const _origin = `${window.location.protocol}//${window.location.host}${window.location.pathname.replace(/\/index\.html$/, '')}`;
168
+ const _originIp = `${window.location.protocol}//${this.state.hostname.split(':').length > 3 ? `[${this.state.hostname}]` : this.state.hostname}${window.location.pathname.replace(/\/index\.html$/, '')}`;
169
+ let data = this.props.schema.data;
170
+ if (data === undefined && this.props.schema.jsonData) {
171
+ data = this.getPattern(this.props.schema.jsonData, Object.assign({ _origin,
172
+ _originIp }, this.props.data));
173
+ console.log(this.props.schema.jsonData);
174
+ try {
175
+ data = JSON.parse(data);
297
176
  }
298
- _this3.setState({
299
- _error: error
300
- });
301
- } else {
302
- _this3.setState({
303
- _error: response.error ? _i18n["default"].t(response.error) : _i18n["default"].t('ra_Error')
304
- });
305
- }
306
- } else {
307
- if (response !== null && response !== void 0 && response.reloadBrowser && _this3.props.schema.reloadBrowser) {
308
- window.location.reload();
309
- } else if (response !== null && response !== void 0 && response.openUrl && _this3.props.schema.openUrl) {
310
- window.open(response.openUrl, response.window || _this3.props.schema.window || '_blank');
311
- } else if (response !== null && response !== void 0 && response.result && _this3.props.schema.result && _this3.props.schema.result[response.result]) {
312
- var text = _this3.getText(_this3.props.schema.result[response.result]);
313
- if (response.args) {
314
- response.args.forEach(function (arg) {
315
- return text = text.replace('%s', arg);
316
- });
177
+ catch (e) {
178
+ console.error(`Cannot parse json data: ${data}`);
317
179
  }
318
- window.alert(text);
319
- }
320
- if (response !== null && response !== void 0 && response["native"] && _this3.props.schema.useNative) {
321
- var attrs = Object.keys(response["native"]);
322
- attrs.forEach(function (attr) {
323
- return _this3.onChange(attr, response["native"][attr]);
324
- });
325
- setTimeout(function () {
326
- return _this3.props.forceUpdate(attrs, _this3.props.data);
327
- }, 300);
328
- } else if (response !== null && response !== void 0 && response.result) {
329
- window.alert((0, _typeof2["default"])(response.result) === 'object' ? JSON.stringify(response.result) : response.result);
330
- } else {
331
- window.alert(_i18n["default"].t('ra_Ok'));
332
- }
333
- if (response !== null && response !== void 0 && response.saveConfig) {
334
- _this3.props.onChange(null, null, null, true);
335
- }
336
180
  }
337
- })["catch"](function (e) {
338
- if (_this3.props.schema.error && _this3.props.schema.error[e.toString()]) {
339
- _this3.setState({
340
- _error: _this3.getText(_this3.props.schema.error[e.toString()])
341
- });
342
- } else {
343
- _this3.setState({
344
- _error: _i18n["default"].t(e.toString()) || _i18n["default"].t('ra_Error')
345
- });
181
+ if (data === undefined) {
182
+ data = null;
183
+ }
184
+ if (this.props.schema.openUrl && !data) {
185
+ data = {
186
+ _origin,
187
+ _originIp,
188
+ };
346
189
  }
347
- }).then(function () {
348
- _this3.props.onCommandRunning(false);
349
- _this3.setState({
350
- running: false
190
+ let timeout;
191
+ if (this.props.schema.timeout) {
192
+ timeout = setTimeout(() => {
193
+ this.props.onCommandRunning(false);
194
+ this.setState({ _error: i18n_1.default.t('ra_Request timed out'), running: false });
195
+ }, parseInt(this.props.schema.timeout, 10) || 10000);
196
+ }
197
+ this.props.socket.sendTo(`${this.props.adapterName}.${this.props.instance}`, this.props.schema.command || 'send', data)
198
+ .then(async (response) => {
199
+ if (timeout) {
200
+ clearTimeout(timeout);
201
+ timeout = undefined;
202
+ }
203
+ if (response === null || response === void 0 ? void 0 : response.error) {
204
+ if (this.props.schema.error && this.props.schema.error[response.error]) {
205
+ let error = this.getText(this.props.schema.error[response.error]);
206
+ if (response.args) {
207
+ response.args.forEach((arg) => error = error.replace('%s', arg));
208
+ }
209
+ this.setState({ _error: error });
210
+ }
211
+ else {
212
+ this.setState({ _error: response.error ? i18n_1.default.t(response.error) : i18n_1.default.t('ra_Error') });
213
+ }
214
+ }
215
+ else {
216
+ if ((response === null || response === void 0 ? void 0 : response.reloadBrowser) && this.props.schema.reloadBrowser) {
217
+ window.location.reload();
218
+ }
219
+ else if ((response === null || response === void 0 ? void 0 : response.openUrl) && this.props.schema.openUrl) {
220
+ window.open(response.openUrl, response.window || this.props.schema.window || '_blank');
221
+ }
222
+ else if ((response === null || response === void 0 ? void 0 : response.result) && this.props.schema.result && this.props.schema.result[response.result]) {
223
+ let text = this.getText(this.props.schema.result[response.result]);
224
+ if (response.args) {
225
+ response.args.forEach((arg) => text = text.replace('%s', arg));
226
+ }
227
+ window.alert(text);
228
+ }
229
+ if ((response === null || response === void 0 ? void 0 : response.native) && this.props.schema.useNative) {
230
+ for (const [attr, val] of Object.entries(response.native)) {
231
+ await this.onChangeAsync(attr, val);
232
+ }
233
+ setTimeout(() => this.props.forceUpdate(Object.keys(response.native), this.props.data), 300);
234
+ }
235
+ else if (response === null || response === void 0 ? void 0 : response.result) {
236
+ window.alert(typeof response.result === 'object' ? JSON.stringify(response.result) : response.result);
237
+ }
238
+ else {
239
+ window.alert(i18n_1.default.t('ra_Ok'));
240
+ }
241
+ if (response === null || response === void 0 ? void 0 : response.saveConfig) {
242
+ // @ts-expect-error 4 values intended?
243
+ this.props.onChange(null, null, null, true);
244
+ }
245
+ }
246
+ })
247
+ .catch((e) => {
248
+ if (this.props.schema.error && this.props.schema.error[e.toString()]) {
249
+ this.setState({ _error: this.getText(this.props.schema.error[e.toString()]) });
250
+ }
251
+ else {
252
+ this.setState({ _error: i18n_1.default.t(e.toString()) || i18n_1.default.t('ra_Error') });
253
+ }
254
+ })
255
+ .then(() => {
256
+ this.props.onCommandRunning(false);
257
+ this.setState({ running: false });
351
258
  });
352
- });
353
259
  }
354
- }, {
355
- key: "renderConfirmDialog",
356
- value: function renderConfirmDialog() {
357
- var _this4 = this;
358
- if (!this.state.confirmDialog) {
359
- return null;
360
- }
361
- var confirm = this.state.confirmData || this.props.schema.confirm;
362
- var icon = null;
363
- if (confirm.type === 'warning') {
364
- icon = /*#__PURE__*/_react["default"].createElement(_iconsMaterial.Warning, null);
365
- } else if (confirm.type === 'error') {
366
- icon = /*#__PURE__*/_react["default"].createElement(_iconsMaterial.Error, null);
367
- } else if (confirm.type === 'info') {
368
- icon = /*#__PURE__*/_react["default"].createElement(_iconsMaterial.Info, null);
369
- }
370
- return /*#__PURE__*/_react["default"].createElement(_Confirm["default"], {
371
- title: this.getText(confirm.title) || _i18n["default"].t('ra_Please confirm'),
372
- text: this.getText(confirm.text),
373
- ok: this.getText(confirm.ok) || _i18n["default"].t('ra_Ok'),
374
- cancel: this.getText(confirm.cancel) || _i18n["default"].t('ra_Cancel'),
375
- icon: icon,
376
- onClose: function onClose(isOk) {
377
- return _this4.setState({
378
- confirmDialog: false
379
- }, function () {
380
- return isOk && _this4._onClick();
381
- });
260
+ renderConfirmDialog() {
261
+ if (!this.state.confirmDialog) {
262
+ return null;
382
263
  }
383
- });
384
- }
385
- }, {
386
- key: "renderItem",
387
- value: function renderItem(error, disabled /* , defaultValue */) {
388
- var _this5 = this;
389
- var icon = this.getIcon();
390
- return /*#__PURE__*/_react["default"].createElement("div", {
391
- className: this.props.classes.fullWidth
392
- }, /*#__PURE__*/_react["default"].createElement(_material.Button, {
393
- variant: this.props.schema.variant || undefined,
394
- color: this.props.schema.color || 'grey',
395
- className: this.props.classes.fullWidth,
396
- disabled: disabled || !this.props.alive,
397
- startIcon: icon,
398
- title: this.props.alive ? this.getText(this.props.schema.title) || '' : _i18n["default"].t('ra_Instance is not alive'),
399
- onClick: function onClick() {
400
- if (_this5.props.schema.confirm) {
401
- _this5.setState({
402
- confirmDialog: true
403
- });
404
- } else {
405
- _this5._onClick();
406
- }
264
+ const confirm = this.state.confirmData || this.props.schema.confirm;
265
+ let icon = null;
266
+ if (confirm.type === 'warning') {
267
+ icon = react_1.default.createElement(icons_material_1.Warning, null);
268
+ }
269
+ else if (confirm.type === 'error') {
270
+ icon = react_1.default.createElement(icons_material_1.Error, null);
407
271
  }
408
- }, this.props.schema.showProcess && this.state.running ? /*#__PURE__*/_react["default"].createElement(_material.CircularProgress, {
409
- size: 20,
410
- style: {
411
- marginRight: 8
272
+ else if (confirm.type === 'info') {
273
+ icon = react_1.default.createElement(icons_material_1.Info, null);
412
274
  }
413
- }) : null, this.getText(this.props.schema.label, this.props.schema.noTranslation)), this.renderErrorDialog(), this.renderMessageDialog());
275
+ return react_1.default.createElement(Confirm_1.default, { title: this.getText(confirm.title) || i18n_1.default.t('ra_Please confirm'), text: this.getText(confirm.text), ok: this.getText(confirm.ok) || i18n_1.default.t('ra_Ok'), cancel: this.getText(confirm.cancel) || i18n_1.default.t('ra_Cancel'), icon: icon, onClose: isOk => this.setState({ confirmDialog: false }, () => isOk && this._onClick()) });
414
276
  }
415
- }]);
416
- return ConfigSendto;
417
- }(_ConfigGeneric2["default"]);
418
- ConfigSendto.propTypes = {
419
- socket: _propTypes["default"].object.isRequired,
420
- themeType: _propTypes["default"].string,
421
- themeName: _propTypes["default"].string,
422
- style: _propTypes["default"].object,
423
- className: _propTypes["default"].string,
424
- data: _propTypes["default"].object.isRequired,
425
- schema: _propTypes["default"].object,
426
- onError: _propTypes["default"].func,
427
- onChange: _propTypes["default"].func,
428
- adapterName: _propTypes["default"].string,
429
- instance: _propTypes["default"].number,
430
- commandRunning: _propTypes["default"].bool,
431
- onCommandRunning: _propTypes["default"].func
432
- };
433
- var _default = exports["default"] = (0, _styles.withStyles)(styles)(ConfigSendto);
434
- //# sourceMappingURL=ConfigSendto.js.map
277
+ renderItem(error, disabled) {
278
+ const icon = this.getIcon();
279
+ return react_1.default.createElement("div", { className: this.props.classes.fullWidth },
280
+ react_1.default.createElement(material_1.Button, { variant: this.props.schema.variant || undefined, color: this.props.schema.color || 'grey', className: this.props.classes.fullWidth, disabled: disabled || !this.props.alive, startIcon: icon, title: this.props.alive ? this.getText(this.props.schema.title) || '' : i18n_1.default.t('ra_Instance is not alive'), onClick: () => {
281
+ if (this.props.schema.confirm) {
282
+ this.setState({ confirmDialog: true });
283
+ }
284
+ else {
285
+ this._onClick();
286
+ }
287
+ } },
288
+ this.props.schema.showProcess && this.state.running ? react_1.default.createElement(material_1.CircularProgress, { size: 20, style: { marginRight: 8 } }) : null,
289
+ this.getText(this.props.schema.label, this.props.schema.noTranslation)),
290
+ this.renderErrorDialog(),
291
+ this.renderMessageDialog());
292
+ }
293
+ }
294
+ exports.default = (0, styles_1.withStyles)(styles)(ConfigSendto);