iobroker.smart-watering 0.2.32 → 0.2.34
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 +21 -0
- package/admin/hilfe.html +6 -0
- package/admin/jsonConfig.json +7 -7
- package/admin/layout-src/01-konstanten.js +211 -0
- package/admin/layout-src/02-hinweise-css.js +967 -0
- package/admin/layout-src/03-aktionsschaltflaechen.js +353 -0
- package/admin/layout-src/04-tabellen-socket.js +830 -0
- package/admin/layout-src/05-objektauswahl.js +1086 -0
- package/admin/layout-src/06-schalter-schwelle.js +1752 -0
- package/admin/layout-src/07-zeiteinstellung.js +1783 -0
- package/admin/layout-src/08-ventilauswahl.js +1878 -0
- package/admin/layout-src/09-wetter-begruessung.js +597 -0
- package/admin/layout-src/10-ventilpanel-schaltzeit.js +5660 -0
- package/admin/layout-src/11-liveanzeige.js +1751 -0
- package/admin/layout-src/12-vis-tank-pumpe.js +2732 -0
- package/admin/layout-src/13-datenpunkte.js +2679 -0
- package/admin/layout-src/14-zeilen-steuerung.js +2358 -0
- package/admin/tab-layout-inject.html +629 -86
- package/admin/vis-bilder/Test_TankH.png +0 -0
- package/admin/vis-bilder/Test_TankL.png +0 -0
- package/admin/vis-bilder/Test_TankL2.png +0 -0
- package/admin/vis-bilder/Test_TankL3.png +0 -0
- package/admin/vis-bilder/Test_TankV.png +0 -0
- package/admin/vis-bilder/Test_TankV4.png +0 -0
- package/admin/vis-bilder/kies.png +0 -0
- package/admin/vis-bilder/seite-einstellung-pumpen.png +0 -0
- package/admin/vis-bilder/seite-einstellung-ventile.png +0 -0
- package/admin/vis-bilder/seite-sperren.png +0 -0
- package/admin/vis-bilder/tank.png +0 -0
- package/admin/vis-vorlage.json +589 -259
- package/io-package.json +27 -1
- package/lib/engine.js +26 -6
- package/lib/engineCore.js +280 -52
- package/lib/ensureAdapterStates.js +2 -12
- package/lib/ensureJavascript.js +7 -6
- package/lib/ensureVentil.test.js +5 -2
- package/lib/ensureVis2.js +7 -2
- package/lib/pumpSzenarien.js +13 -3
- package/lib/resolveVentilCount.js +49 -7
- package/lib/scriptShim.js +59 -1
- package/lib/smart-watering.js +6 -6
- package/lib/stateCommon.js +1 -1
- package/lib/stateDefinitions.js +81 -39
- package/lib/statesManifest.json +4 -4
- package/lib/ventilRegistry.js +6 -0
- package/main.js +41 -1
- package/package.json +1 -1
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
function isTab2VentilTable(table) {
|
|
2
|
+
return !!(table && table.getAttribute('data-bw-tab2-events-table') === '1');
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function nearestSectionTitle(table) {
|
|
6
|
+
var node = table;
|
|
7
|
+
var guard = 0;
|
|
8
|
+
while (node && node !== node.ownerDocument.body && guard < 10) {
|
|
9
|
+
var prev = node.previousElementSibling;
|
|
10
|
+
while (prev) {
|
|
11
|
+
var heading = null;
|
|
12
|
+
if (prev.matches && prev.matches('h1, h2, h3, h4, h5, h6, .MuiTypography-h4')) {
|
|
13
|
+
heading = prev;
|
|
14
|
+
} else if (prev.querySelector) {
|
|
15
|
+
heading = prev.querySelector('h1, h2, h3, h4, h5, h6, .MuiTypography-h4');
|
|
16
|
+
}
|
|
17
|
+
if (heading) {
|
|
18
|
+
return (heading.textContent || '').replace(/\s+/g, ' ').trim();
|
|
19
|
+
}
|
|
20
|
+
prev = prev.previousElementSibling;
|
|
21
|
+
}
|
|
22
|
+
node = node.parentElement;
|
|
23
|
+
guard += 1;
|
|
24
|
+
}
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isTankTable(table) {
|
|
29
|
+
if (!table) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (table.getAttribute('data-bw-tank-table') === '1') {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
var title = nearestSectionTitle(table);
|
|
36
|
+
return title === 'Wassertank' || title === 'Water tank';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isPumpTable(table) {
|
|
40
|
+
if (!table) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (table.getAttribute('data-bw-pump-table') === '1') {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
var title = nearestSectionTitle(table);
|
|
47
|
+
return title === 'Pumpensteuerung' || title === 'Pump control';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isPurePumpTable(table) {
|
|
51
|
+
return !!(table && isPumpTable(table) && !isTankTable(table));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isTab1VentilTable(table) {
|
|
55
|
+
return !!(table && table.getAttribute('data-bw-events-table') === '1' && !isTab2VentilTable(table) && !isPumpTable(table) && !isTankTable(table));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isVentilLikeTable(table) {
|
|
59
|
+
return isTab1VentilTable(table) || isTab2VentilTable(table);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function actionColsForTable(table) {
|
|
63
|
+
return isTab2VentilTable(table) ? TAB2_ACTION_COLS : ACTION_COLS;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function actionWidthForTable(table) {
|
|
67
|
+
return isTab2VentilTable(table) ? TAB2_ACTION_WIDTH : ACTION_WIDTH;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function actionColForTable(table, col) {
|
|
71
|
+
return isTab2VentilTable(table) ? col - 1 : col;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function tagAdminTable(table) {
|
|
75
|
+
if (!table) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
table.setAttribute('data-bw-admin-table', '1');
|
|
79
|
+
table.removeAttribute('data-bw-events-table');
|
|
80
|
+
table.removeAttribute('data-bw-tab2-events-table');
|
|
81
|
+
table.removeAttribute('data-bw-services-table');
|
|
82
|
+
table.removeAttribute('data-bw-pump-table');
|
|
83
|
+
table.removeAttribute('data-bw-tank-table');
|
|
84
|
+
if (isTankTable(table)) {
|
|
85
|
+
table.setAttribute('data-bw-tank-table', '1');
|
|
86
|
+
table.setAttribute('data-bw-pump-table', '1');
|
|
87
|
+
table.setAttribute('data-bw-events-table', '1');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (isPumpTable(table)) {
|
|
91
|
+
table.setAttribute('data-bw-pump-table', '1');
|
|
92
|
+
table.setAttribute('data-bw-events-table', '1');
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (isVentilTable(table)) {
|
|
96
|
+
if (tableTabPanelHasSchleifeAktiv(table)) {
|
|
97
|
+
table.setAttribute('data-bw-tab2-events-table', '1');
|
|
98
|
+
}
|
|
99
|
+
table.setAttribute('data-bw-events-table', '1');
|
|
100
|
+
} else if (isServicesTable(table)) {
|
|
101
|
+
table.setAttribute('data-bw-services-table', '1');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function applyAdapterPanelLayout(doc) {
|
|
106
|
+
var root = getAdapterRoot(doc);
|
|
107
|
+
if (!root) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
root.querySelectorAll('.MuiGrid-item').forEach(function (item) {
|
|
111
|
+
if (item.getAttribute('data-bw-info-banner') === '1' || item.getAttribute('data-bw-section-header') === '1') {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
var h = item.querySelector(':scope > .MuiTypography-h4, :scope > .MuiTypography-h5, :scope > .MuiTypography-h6');
|
|
115
|
+
if (h && !item.querySelector('.MuiTable-root, input, textarea, .MuiSwitch-root, .MuiCheckbox-root, select')) {
|
|
116
|
+
item.setAttribute('data-bw-section-header', '1');
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (item.querySelector('.MuiTable-root, input, textarea, .MuiSwitch-root, .MuiCheckbox-root, select, .MuiFormControl-root .MuiInputBase-root')) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
var typo = item.querySelector('.MuiTypography-root');
|
|
123
|
+
if (typo && (typo.textContent || '').trim().length >= 12) {
|
|
124
|
+
item.setAttribute('data-bw-info-banner', '1');
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function applyServicesTableRows(table) {
|
|
130
|
+
if (!table) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
var dataRows = [];
|
|
134
|
+
table.querySelectorAll('.MuiTableBody-root .MuiTableRow-root, .MuiTableBody-root tr').forEach(function (row) {
|
|
135
|
+
if (isDataRow(row)) {
|
|
136
|
+
dataRows.push(row);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
dataRows.forEach(function (row, idx) {
|
|
140
|
+
var pos = idx === 0 ? 'first' : idx === dataRows.length - 1 ? 'last' : 'mid';
|
|
141
|
+
row.setAttribute('data-bw-row', pos);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function findAllAdminTables(doc) {
|
|
146
|
+
var root = getAdapterRoot(doc);
|
|
147
|
+
if (!root) {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
return Array.prototype.slice.call(root.querySelectorAll('.MuiTable-root'));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function isVentilTable(table) {
|
|
154
|
+
if (!table || isPumpTable(table) || isTankTable(table)) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
var head = table.querySelector('.MuiTableHead-root');
|
|
158
|
+
var text = head ? head.textContent : '';
|
|
159
|
+
return text.indexOf('Nr') >= 0 && (text.indexOf('Name') >= 0 || text.indexOf('Zeit') >= 0);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
function disableAllAddButtons(doc) {
|
|
165
|
+
var addSelectors = [
|
|
166
|
+
'.MuiTableHead-root .MuiIconButton-colorPrimary',
|
|
167
|
+
'.MuiTableHead-root svg[data-testid="AddIcon"]',
|
|
168
|
+
'.MuiTableHead-root svg[data-testid="AddCircleOutlineIcon"]',
|
|
169
|
+
'.MuiTableHead-root svg[data-testid="AddCircleIcon"]'
|
|
170
|
+
];
|
|
171
|
+
addSelectors.forEach(function (sel) {
|
|
172
|
+
doc.querySelectorAll(sel).forEach(function (node) {
|
|
173
|
+
var btn = node.closest ? node.closest('.MuiIconButton-root, .MuiButton-root, button') : null;
|
|
174
|
+
if (!btn) {
|
|
175
|
+
btn = node;
|
|
176
|
+
}
|
|
177
|
+
if (!btn || btn.getAttribute('data-bw-add-removed') === '1') {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (btn.closest('[data-bw-floating-add="1"]') || btn.getAttribute('data-bw-role') === 'add') {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
var wrap = wrapNode(btn);
|
|
184
|
+
if (wrap && (wrap.getAttribute('data-bw-floating-add') === '1' || wrap.getAttribute('data-bw-role') === 'add')) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
btn.setAttribute('data-bw-add-removed', '1');
|
|
188
|
+
btn.setAttribute('disabled', 'disabled');
|
|
189
|
+
btn.setAttribute('aria-hidden', 'true');
|
|
190
|
+
btn.style.setProperty('display', 'none', 'important');
|
|
191
|
+
btn.style.setProperty('visibility', 'hidden', 'important');
|
|
192
|
+
btn.style.setProperty('pointer-events', 'none', 'important');
|
|
193
|
+
btn.style.setProperty('width', '0', 'important');
|
|
194
|
+
btn.style.setProperty('height', '0', 'important');
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function hideBottomAddRows(doc) {
|
|
200
|
+
doc.querySelectorAll('.MuiTableBody-root').forEach(function (tbody) {
|
|
201
|
+
tbody.querySelectorAll(':scope > .MuiTableRow-root, :scope > tr').forEach(function (row) {
|
|
202
|
+
if (isAddRow(row)) {
|
|
203
|
+
row.classList.add('bw-hide-bottom-add');
|
|
204
|
+
row.style.setProperty('display', 'none', 'important');
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
function hideTopLeftAddButton(table) {
|
|
212
|
+
if (!table) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
var head = table.querySelector('.MuiTableHead-root');
|
|
216
|
+
if (!head) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
var firstCell = head.querySelector('.MuiTableRow-root > .MuiTableCell-root:first-child, tr > th:first-child, tr > .MuiTableCell-root:first-child');
|
|
220
|
+
if (!firstCell) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
firstCell.querySelectorAll('.MuiIconButton-root, .MuiButton-root, button, span > .MuiIconButton-root').forEach(function (btn) {
|
|
224
|
+
var svg = btn.querySelector ? btn.querySelector('svg[data-testid]') : null;
|
|
225
|
+
var tid = svg ? svg.getAttribute('data-testid') : '';
|
|
226
|
+
var isAdd = tid === 'AddIcon' || tid === 'AddCircleOutlineIcon' || tid === 'AddCircleIcon' || btn.classList.contains('MuiIconButton-colorPrimary');
|
|
227
|
+
if (!isAdd && !btn.querySelector('svg') && (btn.textContent || '').trim() === '+') {
|
|
228
|
+
isAdd = true;
|
|
229
|
+
}
|
|
230
|
+
if (!isAdd) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
table._bwNativeAddBtn = btn;
|
|
234
|
+
btn.setAttribute('data-bw-top-add-removed', '1');
|
|
235
|
+
btn.setAttribute('disabled', 'disabled');
|
|
236
|
+
btn.style.setProperty('display', 'none', 'important');
|
|
237
|
+
btn.style.setProperty('visibility', 'hidden', 'important');
|
|
238
|
+
btn.style.setProperty('pointer-events', 'none', 'important');
|
|
239
|
+
var wrap = btn.closest('.MuiTooltip-root, span') || btn;
|
|
240
|
+
if (wrap && wrap !== btn && wrap.tagName === 'SPAN') {
|
|
241
|
+
wrap.style.setProperty('display', 'none', 'important');
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function hideHeaderTrash(table) {
|
|
247
|
+
var head = table.querySelector('.MuiTableHead-root');
|
|
248
|
+
if (!head) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
head.querySelectorAll('.MuiIconButton-root[disabled], button[disabled]').forEach(function (btn) {
|
|
252
|
+
var wrap = btn.closest('.MuiTooltip-root') || btn;
|
|
253
|
+
wrap.style.setProperty('display', 'none', 'important');
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function getTopWin(doc) {
|
|
258
|
+
var win = parentWin(doc);
|
|
259
|
+
try {
|
|
260
|
+
while (win.parent && win.parent !== win) {
|
|
261
|
+
win = win.parent;
|
|
262
|
+
}
|
|
263
|
+
} catch (e) {}
|
|
264
|
+
return win;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function findAdminSocket(doc) {
|
|
268
|
+
var seen = [];
|
|
269
|
+
var wins = [];
|
|
270
|
+
function addWin(win) {
|
|
271
|
+
if (!win || seen.indexOf(win) >= 0) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
seen.push(win);
|
|
275
|
+
wins.push(win);
|
|
276
|
+
}
|
|
277
|
+
function pickSocket(obj) {
|
|
278
|
+
if (!obj) {
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
if (typeof obj.sendTo === 'function' && typeof obj.setState === 'function') {
|
|
282
|
+
return obj;
|
|
283
|
+
}
|
|
284
|
+
if (typeof obj.getState === 'function' && typeof obj.setState === 'function') {
|
|
285
|
+
return obj;
|
|
286
|
+
}
|
|
287
|
+
if (typeof obj.emit === 'function' && typeof obj.getObjectViewSystem === 'function') {
|
|
288
|
+
return obj;
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
try {
|
|
293
|
+
addWin(getTopWin(doc));
|
|
294
|
+
addWin(parentWin(doc));
|
|
295
|
+
addWin(window);
|
|
296
|
+
if (doc && doc.defaultView) {
|
|
297
|
+
addWin(doc.defaultView);
|
|
298
|
+
}
|
|
299
|
+
var w = doc ? parentWin(doc) : window;
|
|
300
|
+
var i;
|
|
301
|
+
for (i = 0; i < 16 && w; i += 1) {
|
|
302
|
+
addWin(w);
|
|
303
|
+
if (!w.parent || w.parent === w) {
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
w = w.parent;
|
|
307
|
+
}
|
|
308
|
+
} catch (e) {}
|
|
309
|
+
var j;
|
|
310
|
+
var fallback = null;
|
|
311
|
+
for (j = 0; j < wins.length; j += 1) {
|
|
312
|
+
try {
|
|
313
|
+
var candidate = wins[j];
|
|
314
|
+
var found = pickSocket(candidate.socket) ||
|
|
315
|
+
(candidate.main && pickSocket(candidate.main.socket)) ||
|
|
316
|
+
(candidate.app && pickSocket(candidate.app.socket));
|
|
317
|
+
if (found) {
|
|
318
|
+
if (typeof found.writeFile64 === 'function' || typeof found.readFile === 'function') {
|
|
319
|
+
return found;
|
|
320
|
+
}
|
|
321
|
+
if (!fallback) {
|
|
322
|
+
fallback = found;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
} catch (e2) {}
|
|
326
|
+
}
|
|
327
|
+
var reactDocs = [];
|
|
328
|
+
function addDoc(reactDoc) {
|
|
329
|
+
if (reactDoc && reactDocs.indexOf(reactDoc) < 0) {
|
|
330
|
+
reactDocs.push(reactDoc);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
addDoc(doc);
|
|
334
|
+
for (j = 0; j < wins.length; j += 1) {
|
|
335
|
+
try {
|
|
336
|
+
addDoc(wins[j].document);
|
|
337
|
+
} catch (eDoc) {}
|
|
338
|
+
}
|
|
339
|
+
var di;
|
|
340
|
+
for (di = 0; di < reactDocs.length; di += 1) {
|
|
341
|
+
var reactSock = findSocketFromReact(reactDocs[di]);
|
|
342
|
+
if (reactSock) {
|
|
343
|
+
return reactSock;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return fallback;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function findSocketFromReact(doc) {
|
|
350
|
+
var rootEl = doc && doc.getElementById ? doc.getElementById('root') : null;
|
|
351
|
+
if (!rootEl) {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
var fiberKey = null;
|
|
355
|
+
var rootKeys = Object.keys(rootEl);
|
|
356
|
+
var ki;
|
|
357
|
+
for (ki = 0; ki < rootKeys.length; ki += 1) {
|
|
358
|
+
if (rootKeys[ki].indexOf('__reactContainer') === 0 || rootKeys[ki].indexOf('__reactFiber') === 0) {
|
|
359
|
+
fiberKey = rootKeys[ki];
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (!fiberKey || !rootEl[fiberKey]) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
var stack = [rootEl[fiberKey]];
|
|
367
|
+
var seen = typeof WeakSet === 'function' ? new WeakSet() : null;
|
|
368
|
+
var n = 0;
|
|
369
|
+
while (stack.length && n < 12000) {
|
|
370
|
+
var fiber = stack.pop();
|
|
371
|
+
n += 1;
|
|
372
|
+
if (!fiber || (seen && seen.has(fiber))) {
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (seen) {
|
|
376
|
+
seen.add(fiber);
|
|
377
|
+
}
|
|
378
|
+
var props = fiber.memoizedProps || fiber.pendingProps;
|
|
379
|
+
if (props && props.socket && typeof props.socket.getState === 'function' && typeof props.socket.setState === 'function') {
|
|
380
|
+
return props.socket;
|
|
381
|
+
}
|
|
382
|
+
if (fiber.child) {
|
|
383
|
+
stack.push(fiber.child);
|
|
384
|
+
}
|
|
385
|
+
if (fiber.sibling) {
|
|
386
|
+
stack.push(fiber.sibling);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return null;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
var bwOwnSocketPromise = null;
|
|
393
|
+
|
|
394
|
+
function readIoBrokerAccessToken() {
|
|
395
|
+
var wins = [];
|
|
396
|
+
try {
|
|
397
|
+
wins.push(window);
|
|
398
|
+
if (window.parent && window.parent !== window) {
|
|
399
|
+
wins.push(window.parent);
|
|
400
|
+
}
|
|
401
|
+
if (window.top && window.top !== window) {
|
|
402
|
+
wins.push(window.top);
|
|
403
|
+
}
|
|
404
|
+
} catch (e) {}
|
|
405
|
+
var wi;
|
|
406
|
+
var si;
|
|
407
|
+
for (wi = 0; wi < wins.length; wi += 1) {
|
|
408
|
+
if (!wins[wi]) {
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
for (si = 0; si < 2; si += 1) {
|
|
412
|
+
var storage = si === 0 ? wins[wi].sessionStorage : wins[wi].localStorage;
|
|
413
|
+
if (!storage) {
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
var raw;
|
|
417
|
+
try {
|
|
418
|
+
raw = storage.getItem('iob_tokens');
|
|
419
|
+
} catch (e2) {
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (!raw) {
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
var parts = raw.split(';');
|
|
426
|
+
if (parts.length < 3 || !parts[2]) {
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
var accessExp = new Date(parts[3] || parts[1]);
|
|
430
|
+
if (!isNaN(accessExp.getTime()) && accessExp.getTime() < Date.now()) {
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
return parts[2];
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return '';
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function resolveSocketPath() {
|
|
440
|
+
var wins = [window];
|
|
441
|
+
try {
|
|
442
|
+
if (window.parent && window.parent !== window) {
|
|
443
|
+
wins.push(window.parent);
|
|
444
|
+
}
|
|
445
|
+
if (window.top && window.top !== window) {
|
|
446
|
+
wins.push(window.top);
|
|
447
|
+
}
|
|
448
|
+
} catch (e) {}
|
|
449
|
+
var i;
|
|
450
|
+
for (i = 0; i < wins.length; i += 1) {
|
|
451
|
+
try {
|
|
452
|
+
var pathname = wins[i].location && wins[i].location.pathname;
|
|
453
|
+
if (!pathname || pathname.indexOf('/admin') !== 0) {
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
var segs = pathname.split('/').filter(Boolean);
|
|
457
|
+
var base = segs.length ? '/' + segs[0] : '/admin';
|
|
458
|
+
return base.charAt(base.length - 1) === '/' ? base + 'socket.io' : base + '/socket.io';
|
|
459
|
+
} catch (e2) {}
|
|
460
|
+
}
|
|
461
|
+
return '/socket.io';
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function buildSocketIoOptions() {
|
|
465
|
+
var opts = {
|
|
466
|
+
transports: ['polling', 'websocket'],
|
|
467
|
+
upgrade: true,
|
|
468
|
+
reconnection: false,
|
|
469
|
+
timeout: 20000,
|
|
470
|
+
path: resolveSocketPath(),
|
|
471
|
+
query: { ws: 'true' }
|
|
472
|
+
};
|
|
473
|
+
var token = readIoBrokerAccessToken();
|
|
474
|
+
if (token) {
|
|
475
|
+
opts.token = token;
|
|
476
|
+
opts.query.token = token;
|
|
477
|
+
}
|
|
478
|
+
return opts;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
function isConfigIframe() {
|
|
482
|
+
try {
|
|
483
|
+
return window.self !== window.top;
|
|
484
|
+
} catch (e) {
|
|
485
|
+
return true;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function resolveSocketUrl() {
|
|
490
|
+
var wins = [window];
|
|
491
|
+
try {
|
|
492
|
+
if (window.parent && window.parent !== window) {
|
|
493
|
+
wins.push(window.parent);
|
|
494
|
+
}
|
|
495
|
+
if (window.top && window.top !== window) {
|
|
496
|
+
wins.push(window.top);
|
|
497
|
+
}
|
|
498
|
+
} catch (e) {}
|
|
499
|
+
var i;
|
|
500
|
+
for (i = 0; i < wins.length; i += 1) {
|
|
501
|
+
try {
|
|
502
|
+
var url = wins[i].socketUrl;
|
|
503
|
+
if (url) {
|
|
504
|
+
if (url.indexOf(':') === 0) {
|
|
505
|
+
return window.location.protocol + '//' + window.location.hostname + url;
|
|
506
|
+
}
|
|
507
|
+
if (url.indexOf('http://') !== 0 && url.indexOf('https://') !== 0) {
|
|
508
|
+
return window.location.protocol + '//' + window.location.host + (url.indexOf('/') === 0 ? url : '/' + url);
|
|
509
|
+
}
|
|
510
|
+
return url;
|
|
511
|
+
}
|
|
512
|
+
} catch (e2) {}
|
|
513
|
+
}
|
|
514
|
+
return window.location.origin;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function wrapRawSocket(raw) {
|
|
518
|
+
return {
|
|
519
|
+
setState: function (stateId, val, ack) {
|
|
520
|
+
return new Promise(function (resolve, reject) {
|
|
521
|
+
raw.emit('setState', stateId, val, ack !== false, function (err) {
|
|
522
|
+
if (err) {
|
|
523
|
+
reject(new Error(String(err)));
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
resolve();
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
},
|
|
530
|
+
getState: function (stateId) {
|
|
531
|
+
return new Promise(function (resolve, reject) {
|
|
532
|
+
raw.emit('getState', stateId, function (err, state) {
|
|
533
|
+
if (err) {
|
|
534
|
+
reject(new Error(String(err)));
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
resolve(state);
|
|
538
|
+
});
|
|
539
|
+
});
|
|
540
|
+
},
|
|
541
|
+
getObject: function (objectId) {
|
|
542
|
+
return new Promise(function (resolve, reject) {
|
|
543
|
+
raw.emit('getObject', objectId, function (err, obj) {
|
|
544
|
+
if (typeof err === 'object' && err && err._id && obj === undefined) {
|
|
545
|
+
resolve(err);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (err) {
|
|
549
|
+
reject(new Error(String(err)));
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
resolve(obj);
|
|
553
|
+
});
|
|
554
|
+
});
|
|
555
|
+
},
|
|
556
|
+
setObject: function (objectId, obj) {
|
|
557
|
+
return new Promise(function (resolve, reject) {
|
|
558
|
+
raw.emit('setObject', objectId, obj, function (err) {
|
|
559
|
+
if (err) {
|
|
560
|
+
reject(new Error(String(err)));
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
resolve();
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
},
|
|
567
|
+
sendTo: function (instance, command, data) {
|
|
568
|
+
return new Promise(function (resolve, reject) {
|
|
569
|
+
raw.emit('sendTo', instance, command, data, function (result) {
|
|
570
|
+
resolve(result);
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
},
|
|
574
|
+
readFile: function (adapter, fileName) {
|
|
575
|
+
return new Promise(function (resolve, reject) {
|
|
576
|
+
raw.emit('readFile', adapter, fileName, function (err, file, mime) {
|
|
577
|
+
if (err) {
|
|
578
|
+
reject(new Error(String(err)));
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
resolve({ file: file, mimeType: mime });
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
},
|
|
585
|
+
writeFile64: function (adapter, fileName, data) {
|
|
586
|
+
return new Promise(function (resolve, reject) {
|
|
587
|
+
raw.emit('writeFile', adapter, fileName, data, function (err) {
|
|
588
|
+
if (err) {
|
|
589
|
+
reject(new Error(String(err)));
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
resolve();
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
},
|
|
596
|
+
_socket: raw,
|
|
597
|
+
delObject: function (objectId, options) {
|
|
598
|
+
var opts = options || { children: true };
|
|
599
|
+
return new Promise(function (resolve, reject) {
|
|
600
|
+
raw.emit('delObject', objectId, opts, function (err) {
|
|
601
|
+
if (err) {
|
|
602
|
+
reject(new Error(String(err)));
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
resolve();
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
},
|
|
609
|
+
getObjectViewSystem: function (type, start, end) {
|
|
610
|
+
return new Promise(function (resolve, reject) {
|
|
611
|
+
raw.emit('getObjectView', 'system', type, { startkey: start, endkey: end }, function (a, b) {
|
|
612
|
+
var result = b !== undefined && b !== null ? b : a;
|
|
613
|
+
if (typeof result === 'string') {
|
|
614
|
+
reject(new Error(result));
|
|
615
|
+
return;
|
|
616
|
+
}
|
|
617
|
+
resolve(result);
|
|
618
|
+
});
|
|
619
|
+
});
|
|
620
|
+
},
|
|
621
|
+
emit: function (event, a, b, c) {
|
|
622
|
+
raw.emit(event, a, b, c);
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function getIoConnectFn() {
|
|
628
|
+
var wins = [window];
|
|
629
|
+
try {
|
|
630
|
+
if (window.parent && window.parent !== window) {
|
|
631
|
+
wins.push(window.parent);
|
|
632
|
+
}
|
|
633
|
+
if (window.top && window.top !== window) {
|
|
634
|
+
wins.push(window.top);
|
|
635
|
+
}
|
|
636
|
+
} catch (e) {}
|
|
637
|
+
var i;
|
|
638
|
+
var lib;
|
|
639
|
+
for (i = 0; i < wins.length; i += 1) {
|
|
640
|
+
if (!wins[i]) {
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
try {
|
|
644
|
+
lib = wins[i].io || wins[i].iob;
|
|
645
|
+
} catch (e2) {
|
|
646
|
+
continue;
|
|
647
|
+
}
|
|
648
|
+
if (lib && typeof lib.connect === 'function') {
|
|
649
|
+
return lib.connect.bind(lib);
|
|
650
|
+
}
|
|
651
|
+
if (typeof lib === 'function') {
|
|
652
|
+
return lib;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return null;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function resolveSocketScriptUrls() {
|
|
659
|
+
var seen = {};
|
|
660
|
+
var urls = [];
|
|
661
|
+
function add(url) {
|
|
662
|
+
if (!url || seen[url]) {
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
seen[url] = true;
|
|
666
|
+
urls.push(url);
|
|
667
|
+
}
|
|
668
|
+
var basePath = resolveSocketPath();
|
|
669
|
+
if (basePath) {
|
|
670
|
+
add(basePath.replace(/\/$/, '') + '/socket.io.js');
|
|
671
|
+
}
|
|
672
|
+
add('/admin/socket.io/socket.io.js');
|
|
673
|
+
add('/socket.io/socket.io.js');
|
|
674
|
+
return urls;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
function pollIoConnect(done, fail) {
|
|
678
|
+
var attempts = 0;
|
|
679
|
+
(function tick() {
|
|
680
|
+
var connectFn = getIoConnectFn();
|
|
681
|
+
if (connectFn) {
|
|
682
|
+
done(connectFn);
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
attempts += 1;
|
|
686
|
+
if (attempts >= 50) {
|
|
687
|
+
fail('socket.io nicht geladen');
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
window.setTimeout(tick, 100);
|
|
691
|
+
})();
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function ensureSocketIoScript(done, fail) {
|
|
695
|
+
if (getIoConnectFn()) {
|
|
696
|
+
done(getIoConnectFn());
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
var urls = resolveSocketScriptUrls();
|
|
700
|
+
var idx = 0;
|
|
701
|
+
function tryNextUrl() {
|
|
702
|
+
if (getIoConnectFn()) {
|
|
703
|
+
done(getIoConnectFn());
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
if (idx >= urls.length) {
|
|
707
|
+
pollIoConnect(done, fail);
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
var url = urls[idx];
|
|
711
|
+
idx += 1;
|
|
712
|
+
var doc = document;
|
|
713
|
+
try {
|
|
714
|
+
if (window.top && window.top.document && window.top.document.head) {
|
|
715
|
+
doc = window.top.document;
|
|
716
|
+
}
|
|
717
|
+
} catch (e) {}
|
|
718
|
+
var script = doc.createElement('script');
|
|
719
|
+
script.setAttribute('data-bw-socket-io', '1');
|
|
720
|
+
script.src = url;
|
|
721
|
+
script.onload = function () {
|
|
722
|
+
pollIoConnect(done, fail);
|
|
723
|
+
};
|
|
724
|
+
script.onerror = function () {
|
|
725
|
+
tryNextUrl();
|
|
726
|
+
};
|
|
727
|
+
doc.head.appendChild(script);
|
|
728
|
+
}
|
|
729
|
+
tryNextUrl();
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
function loadSocketIoLibrary(done, fail) {
|
|
733
|
+
var connectFn = getIoConnectFn();
|
|
734
|
+
if (connectFn) {
|
|
735
|
+
done(connectFn);
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
var regWins = [];
|
|
739
|
+
try {
|
|
740
|
+
regWins.push(window.top);
|
|
741
|
+
regWins.push(window.parent);
|
|
742
|
+
regWins.push(window);
|
|
743
|
+
} catch (e) {}
|
|
744
|
+
var ri;
|
|
745
|
+
for (ri = 0; ri < regWins.length; ri += 1) {
|
|
746
|
+
if (regWins[ri] && typeof regWins[ri].registerSocketOnLoad === 'function') {
|
|
747
|
+
regWins[ri].registerSocketOnLoad(function () {
|
|
748
|
+
var fn = getIoConnectFn();
|
|
749
|
+
if (fn) {
|
|
750
|
+
done(fn);
|
|
751
|
+
} else {
|
|
752
|
+
pollIoConnect(done, fail);
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
ensureSocketIoScript(done, fail);
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
function ensureOwnAdminSocket() {
|
|
762
|
+
if (bwOwnSocketPromise) {
|
|
763
|
+
return bwOwnSocketPromise;
|
|
764
|
+
}
|
|
765
|
+
bwOwnSocketPromise = new Promise(function (resolve, reject) {
|
|
766
|
+
function failPromise(msg) {
|
|
767
|
+
bwOwnSocketPromise = null;
|
|
768
|
+
reject(msg);
|
|
769
|
+
}
|
|
770
|
+
loadSocketIoLibrary(function (connectFn) {
|
|
771
|
+
var raw = connectFn(resolveSocketUrl(), buildSocketIoOptions());
|
|
772
|
+
var failed = false;
|
|
773
|
+
var connectTimer = null;
|
|
774
|
+
function fail(msg) {
|
|
775
|
+
if (failed) {
|
|
776
|
+
return;
|
|
777
|
+
}
|
|
778
|
+
failed = true;
|
|
779
|
+
bwOwnSocketPromise = null;
|
|
780
|
+
if (connectTimer) {
|
|
781
|
+
window.clearTimeout(connectTimer);
|
|
782
|
+
connectTimer = null;
|
|
783
|
+
}
|
|
784
|
+
try {
|
|
785
|
+
raw.disconnect();
|
|
786
|
+
} catch (e) {}
|
|
787
|
+
reject(msg);
|
|
788
|
+
}
|
|
789
|
+
raw.on('connect_error', function (err) {
|
|
790
|
+
fail(adminErrMsg(err) || 'Socket-Verbindung fehlgeschlagen');
|
|
791
|
+
});
|
|
792
|
+
raw.on('connect', function () {
|
|
793
|
+
raw.emit('authenticate', function (ok) {
|
|
794
|
+
if (!ok) {
|
|
795
|
+
fail('Socket-Authentifizierung fehlgeschlagen');
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
if (connectTimer) {
|
|
799
|
+
window.clearTimeout(connectTimer);
|
|
800
|
+
connectTimer = null;
|
|
801
|
+
}
|
|
802
|
+
resolve(wrapRawSocket(raw));
|
|
803
|
+
});
|
|
804
|
+
});
|
|
805
|
+
connectTimer = window.setTimeout(function () {
|
|
806
|
+
fail('Socket-Verbindung Zeitüberschreitung');
|
|
807
|
+
}, 20000);
|
|
808
|
+
}, failPromise);
|
|
809
|
+
});
|
|
810
|
+
return bwOwnSocketPromise;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
function getAdminSocketAsync(doc, done) {
|
|
814
|
+
var sync = findAdminSocket(doc);
|
|
815
|
+
if (sync && (typeof sync.sendTo === 'function' || typeof sync.getState === 'function' ||
|
|
816
|
+
typeof sync.setState === 'function' || typeof sync.emit === 'function')) {
|
|
817
|
+
done(null, sync);
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
ensureOwnAdminSocket().then(function (own) {
|
|
821
|
+
done(null, own);
|
|
822
|
+
}).catch(function (err) {
|
|
823
|
+
if (sync) {
|
|
824
|
+
done(null, sync);
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
done(adminErrMsg(err) || String(err), null);
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
|