@meta2d/core 1.0.60 → 1.0.62
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/package.json +1 -1
- package/src/canvas/canvas.d.ts +0 -1
- package/src/canvas/canvas.js +37 -21
- package/src/canvas/canvas.js.map +1 -1
- package/src/canvas/magnifierCanvas.d.ts +2 -0
- package/src/canvas/magnifierCanvas.js +21 -0
- package/src/canvas/magnifierCanvas.js.map +1 -1
- package/src/core.d.ts +7 -2
- package/src/core.js +259 -64
- package/src/core.js.map +1 -1
- package/src/dialog/dialog.js +2 -2
- package/src/dialog/dialog.js.map +1 -1
- package/src/event/event.d.ts +5 -0
- package/src/event/event.js.map +1 -1
- package/src/pen/model.d.ts +12 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.d.ts +1 -0
- package/src/pen/render.js +98 -13
- package/src/pen/render.js.map +1 -1
- package/src/store/store.d.ts +4 -1
- package/src/store/store.js.map +1 -1
|
@@ -7,6 +7,7 @@ export declare class MagnifierCanvas {
|
|
|
7
7
|
canvas: HTMLCanvasElement;
|
|
8
8
|
magnifierScreen: any;
|
|
9
9
|
offscreen: any;
|
|
10
|
+
domOffscreen: any;
|
|
10
11
|
private magnifierSize;
|
|
11
12
|
magnifier: boolean;
|
|
12
13
|
constructor(parentCanvas: Canvas, parentElement: HTMLElement, store: Meta2dStore);
|
|
@@ -15,5 +16,6 @@ export declare class MagnifierCanvas {
|
|
|
15
16
|
* 绘制到 该画布的 离屏层
|
|
16
17
|
*/
|
|
17
18
|
private renderMagnifier;
|
|
19
|
+
updateDomOffscreen(): void;
|
|
18
20
|
render(): void;
|
|
19
21
|
}
|
|
@@ -6,6 +6,7 @@ export class MagnifierCanvas {
|
|
|
6
6
|
canvas = document.createElement('canvas');
|
|
7
7
|
magnifierScreen = createOffscreen();
|
|
8
8
|
offscreen = createOffscreen();
|
|
9
|
+
domOffscreen = createOffscreen();
|
|
9
10
|
magnifierSize = 300;
|
|
10
11
|
magnifier;
|
|
11
12
|
constructor(parentCanvas, parentElement, store) {
|
|
@@ -32,6 +33,10 @@ export class MagnifierCanvas {
|
|
|
32
33
|
.getContext('2d')
|
|
33
34
|
.scale(this.store.dpiRatio, this.store.dpiRatio);
|
|
34
35
|
this.offscreen.getContext('2d').textBaseline = 'middle';
|
|
36
|
+
this.domOffscreen.width = w;
|
|
37
|
+
this.domOffscreen.height = h;
|
|
38
|
+
this.domOffscreen.getContext('2d').scale(this.store.dpiRatio, this.store.dpiRatio);
|
|
39
|
+
this.domOffscreen.getContext('2d').textBaseline = 'middle';
|
|
35
40
|
this.magnifierScreen.width = this.magnifierSize + 5;
|
|
36
41
|
this.magnifierScreen.height = this.magnifierSize + 5;
|
|
37
42
|
}
|
|
@@ -71,6 +76,7 @@ export class MagnifierCanvas {
|
|
|
71
76
|
this.parentCanvas.offscreen,
|
|
72
77
|
this.parentCanvas.canvasImage.offscreen,
|
|
73
78
|
this.parentCanvas.canvasImage.animateOffsScreen,
|
|
79
|
+
this.domOffscreen //dom元素的绘制层
|
|
74
80
|
];
|
|
75
81
|
drawOffscreens.forEach((offscreen) => {
|
|
76
82
|
ctx.drawImage(offscreen, pt.x - r, pt.y - r, this.magnifierSize, this.magnifierSize, 0, 0, this.magnifierSize, this.magnifierSize);
|
|
@@ -89,6 +95,21 @@ export class MagnifierCanvas {
|
|
|
89
95
|
const offscreenCtx = this.offscreen.getContext('2d');
|
|
90
96
|
offscreenCtx.drawImage(this.magnifierScreen, 0, 0, this.magnifierSize + 5, this.magnifierSize + 5, (pt.x - r - 2.5) / this.store.dpiRatio, (pt.y - r - 2.5) / this.store.dpiRatio, (this.magnifierSize + 5) / this.store.dpiRatio, (this.magnifierSize + 5) / this.store.dpiRatio);
|
|
91
97
|
}
|
|
98
|
+
updateDomOffscreen() {
|
|
99
|
+
const domCtx = this.domOffscreen.getContext('2d');
|
|
100
|
+
domCtx.clearRect(0, 0, this.domOffscreen.width, this.domOffscreen.height);
|
|
101
|
+
for (const pen of this.store.data.pens) {
|
|
102
|
+
if (pen.externElement || pen.name === 'gif') {
|
|
103
|
+
if (pen.calculative.img) {
|
|
104
|
+
domCtx.save();
|
|
105
|
+
domCtx.translate(this.store.data.x, this.store.data.y);
|
|
106
|
+
const { x, y, width, height } = pen.calculative.worldRect;
|
|
107
|
+
domCtx.drawImage(pen.calculative.img, x, y, width, height);
|
|
108
|
+
domCtx.restore();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
92
113
|
render() {
|
|
93
114
|
this.offscreen
|
|
94
115
|
.getContext('2d')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"magnifierCanvas.js","sourceRoot":"","sources":["../../../../packages/core/src/canvas/magnifierCanvas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,OAAO,eAAe;
|
|
1
|
+
{"version":3,"file":"magnifierCanvas.js","sourceRoot":"","sources":["../../../../packages/core/src/canvas/magnifierCanvas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,OAAO,eAAe;IASjB;IACA;IACA;IAVT,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC1C,eAAe,GAAG,eAAe,EAAE,CAAC;IACpC,SAAS,GAAG,eAAe,EAAE,CAAC;IAC9B,YAAY,GAAG,eAAe,EAAE,CAAC;IACzB,aAAa,GAAW,GAAG,CAAC;IACpC,SAAS,CAAU;IAEnB,YACS,YAAoB,EACpB,aAA0B,EAC1B,KAAkB;QAFlB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,kBAAa,GAAb,aAAa,CAAa;QAC1B,UAAK,GAAL,KAAK,CAAa;QAEzB,aAAa,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gB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AAU,CAAC,IAAI,CAAC,CAAC;QACzC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3D,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7E,CAAC;CACF"}
|
package/src/core.d.ts
CHANGED
|
@@ -27,8 +27,9 @@ export declare class Meta2d {
|
|
|
27
27
|
type?: string;
|
|
28
28
|
topic?: string;
|
|
29
29
|
url?: string;
|
|
30
|
+
method?: string;
|
|
30
31
|
}) => boolean | string;
|
|
31
|
-
events: Record<number, (pen: Pen, e: Event) => void>;
|
|
32
|
+
events: Record<number, (pen: Pen, e: Event, params?: any) => void>;
|
|
32
33
|
map: ViewMap;
|
|
33
34
|
mapTimer: any;
|
|
34
35
|
constructor(parent: string | HTMLElement, opts?: Options);
|
|
@@ -216,8 +217,11 @@ export declare class Meta2d {
|
|
|
216
217
|
closeHttp(): void;
|
|
217
218
|
updateTimer: any;
|
|
218
219
|
updateTimerList: any[];
|
|
220
|
+
sqlTimerList: any[];
|
|
219
221
|
connectNetwork(): void;
|
|
220
222
|
connectNetWebSocket(net: Network): void;
|
|
223
|
+
getIotToken(devices: any): Promise<any>;
|
|
224
|
+
doSqlCode(type: string, dbid: string, sql: string): Promise<void>;
|
|
221
225
|
randomString(e: number): string;
|
|
222
226
|
mockValue(data: any): any;
|
|
223
227
|
dataMock(): void;
|
|
@@ -234,6 +238,7 @@ export declare class Meta2d {
|
|
|
234
238
|
type?: string;
|
|
235
239
|
topic?: string;
|
|
236
240
|
url?: string;
|
|
241
|
+
method?: string;
|
|
237
242
|
}): void;
|
|
238
243
|
setDatas(datas: {
|
|
239
244
|
dataId?: string;
|
|
@@ -260,7 +265,7 @@ export declare class Meta2d {
|
|
|
260
265
|
clearRuleLines(): void;
|
|
261
266
|
private onEvent;
|
|
262
267
|
private doEvent;
|
|
263
|
-
doMessageEvent(eventName: string): void;
|
|
268
|
+
doMessageEvent(eventName: string, data?: any): void;
|
|
264
269
|
doDataEvent: (datas: {
|
|
265
270
|
dataId?: string;
|
|
266
271
|
id?: string;
|
package/src/core.js
CHANGED
|
@@ -203,7 +203,7 @@ export class Meta2d {
|
|
|
203
203
|
if (e.value) {
|
|
204
204
|
_pen = this.findOne(e.value);
|
|
205
205
|
}
|
|
206
|
-
if (this.store.animates.has(_pen) && !_pen.calculative.pause) {
|
|
206
|
+
if (this.store.animates.has(_pen) && !_pen.calculative.pause && _pen.animateName === e.params) {
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
209
|
if (e.targetType && e.params) {
|
|
@@ -262,7 +262,7 @@ export class Meta2d {
|
|
|
262
262
|
}
|
|
263
263
|
console.warn('[meta2d] StopVideo event value is not a string');
|
|
264
264
|
};
|
|
265
|
-
this.events[EventAction.JS] = (pen, e) => {
|
|
265
|
+
this.events[EventAction.JS] = (pen, e, params) => {
|
|
266
266
|
if (e.value && !e.fn) {
|
|
267
267
|
try {
|
|
268
268
|
if (typeof e.value !== 'string') {
|
|
@@ -275,7 +275,7 @@ export class Meta2d {
|
|
|
275
275
|
console.error('[meta2d]: Error on make a function:', err);
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
|
-
e.fn?.(pen, e.params, { meta2d: this, eventName: e.name });
|
|
278
|
+
e.fn?.(pen, params || e.params, { meta2d: this, eventName: e.name });
|
|
279
279
|
};
|
|
280
280
|
this.events[EventAction.GlobalFn] = (pen, e) => {
|
|
281
281
|
if (typeof e.value !== 'string') {
|
|
@@ -357,6 +357,33 @@ export class Meta2d {
|
|
|
357
357
|
}
|
|
358
358
|
};
|
|
359
359
|
this.events[EventAction.SendData] = (pen, e) => {
|
|
360
|
+
if (e.list?.length) {
|
|
361
|
+
// if (e.targetType === 'id') {
|
|
362
|
+
const value = {};
|
|
363
|
+
e.list.forEach((item) => {
|
|
364
|
+
const _pen = item.params ? this.findOne(item.params) : pen;
|
|
365
|
+
for (let key in item.value) {
|
|
366
|
+
if (item.value[key] === undefined || item.value[key] === '') {
|
|
367
|
+
value[key] = _pen[key];
|
|
368
|
+
}
|
|
369
|
+
else if (typeof item.value[key] === 'string' && item.value[key]?.indexOf('${') > -1) {
|
|
370
|
+
let keys = item.value[key].match(/(?<=\$\{).*?(?=\})/g);
|
|
371
|
+
if (keys?.length) {
|
|
372
|
+
value[key] = _pen[keys[0]];
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
value[key] = item.value[key];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
if (pen.deviceId) {
|
|
381
|
+
value.deviceId = pen.deviceId;
|
|
382
|
+
}
|
|
383
|
+
this.sendDataToNetWork(value, pen, e);
|
|
384
|
+
return;
|
|
385
|
+
// }
|
|
386
|
+
}
|
|
360
387
|
const value = deepClone(e.value);
|
|
361
388
|
if (value && typeof value === 'object') {
|
|
362
389
|
if (e.targetType === 'id') {
|
|
@@ -392,9 +419,30 @@ export class Meta2d {
|
|
|
392
419
|
return;
|
|
393
420
|
}
|
|
394
421
|
let params = queryURLParams(_pen.iframe.split('?')[1]);
|
|
422
|
+
const value = {};
|
|
423
|
+
if (e.list?.length) {
|
|
424
|
+
e.list.forEach((item) => {
|
|
425
|
+
const _pen = item.params ? this.findOne(item.params) : pen;
|
|
426
|
+
for (let key in item.value) {
|
|
427
|
+
if (item.value[key] === undefined || item.value[key] === '') {
|
|
428
|
+
value[key] = _pen[key];
|
|
429
|
+
}
|
|
430
|
+
else if (typeof item.value[key] === 'string' && item.value[key]?.indexOf('${') > -1) {
|
|
431
|
+
let keys = item.value[key].match(/(?<=\$\{).*?(?=\})/g);
|
|
432
|
+
if (keys?.length) {
|
|
433
|
+
value[key] = _pen[keys[0]];
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
value[key] = item.value[key];
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}
|
|
395
442
|
_pen.calculative.singleton.div.children[0].contentWindow.postMessage(JSON.stringify({
|
|
396
443
|
name: e.value,
|
|
397
444
|
id: params.id,
|
|
445
|
+
value
|
|
398
446
|
}), '*');
|
|
399
447
|
return;
|
|
400
448
|
};
|
|
@@ -403,7 +451,27 @@ export class Meta2d {
|
|
|
403
451
|
console.warn('[meta2d] Emit value must be a string');
|
|
404
452
|
return;
|
|
405
453
|
}
|
|
406
|
-
|
|
454
|
+
const value = {};
|
|
455
|
+
if (e.list?.length) {
|
|
456
|
+
e.list.forEach((item) => {
|
|
457
|
+
const _pen = item.params ? this.findOne(item.params) : pen;
|
|
458
|
+
for (let key in item.value) {
|
|
459
|
+
if (item.value[key] === undefined || item.value[key] === '') {
|
|
460
|
+
value[key] = _pen[key];
|
|
461
|
+
}
|
|
462
|
+
else if (typeof item.value[key] === 'string' && item.value[key]?.indexOf('${') > -1) {
|
|
463
|
+
let keys = item.value[key].match(/(?<=\$\{).*?(?=\})/g);
|
|
464
|
+
if (keys?.length) {
|
|
465
|
+
value[key] = _pen[keys[0]];
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
value[key] = item.value[key];
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
window.parent.postMessage(JSON.stringify({ name: e.value, value }), '*');
|
|
407
475
|
return;
|
|
408
476
|
};
|
|
409
477
|
}
|
|
@@ -1074,6 +1142,7 @@ export class Meta2d {
|
|
|
1074
1142
|
}
|
|
1075
1143
|
if (index !== -1 && index !== undefined) {
|
|
1076
1144
|
const animate = deepClone(pen.animations[index]);
|
|
1145
|
+
animate.animateName = animate.name;
|
|
1077
1146
|
delete animate.name;
|
|
1078
1147
|
animate.currentAnimation = index;
|
|
1079
1148
|
if (!pen.type && animate.frames) {
|
|
@@ -1730,6 +1799,7 @@ export class Meta2d {
|
|
|
1730
1799
|
}
|
|
1731
1800
|
updateTimer;
|
|
1732
1801
|
updateTimerList = [];
|
|
1802
|
+
sqlTimerList = [];
|
|
1733
1803
|
connectNetwork() {
|
|
1734
1804
|
this.closeNetwork();
|
|
1735
1805
|
const { networks } = this.store.data;
|
|
@@ -1738,76 +1808,119 @@ export class Meta2d {
|
|
|
1738
1808
|
let mqttIndex = 0;
|
|
1739
1809
|
this.mqttClients = [];
|
|
1740
1810
|
let websocketIndex = 0;
|
|
1811
|
+
let sqlIndex = 0;
|
|
1741
1812
|
this.websockets = [];
|
|
1742
|
-
networks.forEach((net) => {
|
|
1743
|
-
if (net.type === 'subscribe') {
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1813
|
+
networks.forEach(async (net) => {
|
|
1814
|
+
// if (net.type === 'subscribe') {
|
|
1815
|
+
if (net.protocol === 'mqtt') {
|
|
1816
|
+
net.index = mqttIndex;
|
|
1817
|
+
if (net.options.clientId && !net.options.customClientId) {
|
|
1818
|
+
net.options.clientId = s8();
|
|
1819
|
+
}
|
|
1820
|
+
net.times = 0;
|
|
1821
|
+
this.mqttClients[mqttIndex] = mqtt.connect(net.url, net.options);
|
|
1822
|
+
this.mqttClients[mqttIndex].on('message', (topic, message) => {
|
|
1823
|
+
this.socketCallback(message.toString(), {
|
|
1824
|
+
topic,
|
|
1825
|
+
type: 'mqtt',
|
|
1826
|
+
url: net.url,
|
|
1827
|
+
});
|
|
1828
|
+
});
|
|
1829
|
+
this.mqttClients[mqttIndex].on('error', (error) => {
|
|
1830
|
+
this.store.emitter.emit('error', { type: 'mqtt', error });
|
|
1831
|
+
});
|
|
1832
|
+
this.mqttClients[mqttIndex].on('close', () => {
|
|
1833
|
+
if (this.store.options.reconnetTimes) {
|
|
1834
|
+
net.times++;
|
|
1835
|
+
if (net.times >= this.store.options.reconnetTimes) {
|
|
1836
|
+
net.times = 0;
|
|
1837
|
+
this.mqttClients && this.mqttClients[net.index]?.end();
|
|
1838
|
+
}
|
|
1748
1839
|
}
|
|
1749
|
-
|
|
1750
|
-
|
|
1840
|
+
});
|
|
1841
|
+
if (net.topics) {
|
|
1842
|
+
this.mqttClients[mqttIndex].subscribe(net.topics.split(','));
|
|
1843
|
+
}
|
|
1844
|
+
mqttIndex += 1;
|
|
1845
|
+
}
|
|
1846
|
+
else if (net.protocol === 'websocket') {
|
|
1847
|
+
net.index = websocketIndex;
|
|
1848
|
+
this.connectNetWebSocket(net);
|
|
1849
|
+
// this.websockets[websocketIndex] = new WebSocket(
|
|
1850
|
+
// net.url,
|
|
1851
|
+
// net.protocols || undefined
|
|
1852
|
+
// );
|
|
1853
|
+
// this.websockets[websocketIndex].onmessage = (e) => {
|
|
1854
|
+
// this.socketCallback(e.data, { type: 'websocket', url: net.url });
|
|
1855
|
+
// };
|
|
1856
|
+
// this.websockets[websocketIndex].onerror = (error) => {
|
|
1857
|
+
// this.store.emitter.emit('error', { type: 'websocket', error });
|
|
1858
|
+
// };
|
|
1859
|
+
// this.websockets[websocketIndex].onclose = () => {
|
|
1860
|
+
// if (this.store.options.reconnetTimes) {
|
|
1861
|
+
// net.times++;
|
|
1862
|
+
// if (net.times >= this.store.options.reconnetTimes) {
|
|
1863
|
+
// net.times = 0;
|
|
1864
|
+
// this.websockets[net.index]?.close();
|
|
1865
|
+
// return;
|
|
1866
|
+
// }
|
|
1867
|
+
// }
|
|
1868
|
+
// console.info('Canvas websocket closed and reconneting...');
|
|
1869
|
+
// };
|
|
1870
|
+
websocketIndex += 1;
|
|
1871
|
+
}
|
|
1872
|
+
else if (net.protocol === 'http') {
|
|
1873
|
+
https.push({
|
|
1874
|
+
url: net.url,
|
|
1875
|
+
interval: net.interval,
|
|
1876
|
+
headers: net.headers || undefined,
|
|
1877
|
+
method: net.method,
|
|
1878
|
+
body: net.body,
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
else if (net.protocol === 'iot') {
|
|
1882
|
+
const token = await this.getIotToken(net.devices);
|
|
1883
|
+
//物联网设备
|
|
1884
|
+
if (net.method === 'mqtt') {
|
|
1885
|
+
net.index = mqttIndex;
|
|
1886
|
+
this.mqttClients[mqttIndex] = mqtt.connect(net.url);
|
|
1751
1887
|
this.mqttClients[mqttIndex].on('message', (topic, message) => {
|
|
1752
1888
|
this.socketCallback(message.toString(), {
|
|
1753
|
-
topic
|
|
1754
|
-
type: '
|
|
1889
|
+
topic: `le5le-iot/properties/${token}`,
|
|
1890
|
+
type: 'iot',
|
|
1755
1891
|
url: net.url,
|
|
1892
|
+
method: 'mqtt'
|
|
1756
1893
|
});
|
|
1757
1894
|
});
|
|
1758
1895
|
this.mqttClients[mqttIndex].on('error', (error) => {
|
|
1759
1896
|
this.store.emitter.emit('error', { type: 'mqtt', error });
|
|
1760
1897
|
});
|
|
1761
|
-
this.mqttClients[mqttIndex].
|
|
1762
|
-
if (this.store.options.reconnetTimes) {
|
|
1763
|
-
net.times++;
|
|
1764
|
-
if (net.times >= this.store.options.reconnetTimes) {
|
|
1765
|
-
net.times = 0;
|
|
1766
|
-
this.mqttClients && this.mqttClients[net.index]?.end();
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
});
|
|
1770
|
-
if (net.topics) {
|
|
1771
|
-
this.mqttClients[mqttIndex].subscribe(net.topics.split(','));
|
|
1772
|
-
}
|
|
1898
|
+
this.mqttClients[mqttIndex].subscribe(`le5le-iot/properties/${token}`);
|
|
1773
1899
|
mqttIndex += 1;
|
|
1774
1900
|
}
|
|
1775
|
-
else if (net.
|
|
1901
|
+
else if (net.method === 'websocket') {
|
|
1776
1902
|
net.index = websocketIndex;
|
|
1777
|
-
this.
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
// };
|
|
1785
|
-
// this.websockets[websocketIndex].onerror = (error) => {
|
|
1786
|
-
// this.store.emitter.emit('error', { type: 'websocket', error });
|
|
1787
|
-
// };
|
|
1788
|
-
// this.websockets[websocketIndex].onclose = () => {
|
|
1789
|
-
// if (this.store.options.reconnetTimes) {
|
|
1790
|
-
// net.times++;
|
|
1791
|
-
// if (net.times >= this.store.options.reconnetTimes) {
|
|
1792
|
-
// net.times = 0;
|
|
1793
|
-
// this.websockets[net.index]?.close();
|
|
1794
|
-
// return;
|
|
1795
|
-
// }
|
|
1796
|
-
// }
|
|
1797
|
-
// console.info('Canvas websocket closed and reconneting...');
|
|
1798
|
-
// };
|
|
1903
|
+
this.websockets[websocketIndex] = new WebSocket(`${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.host}/api/ws/iot/properties`, token);
|
|
1904
|
+
this.websockets[websocketIndex].onmessage = (e) => {
|
|
1905
|
+
this.socketCallback(e.data, { type: 'iot', method: 'websocket' });
|
|
1906
|
+
};
|
|
1907
|
+
this.websockets[websocketIndex].onerror = (error) => {
|
|
1908
|
+
this.store.emitter.emit('error', { type: 'websocket', error });
|
|
1909
|
+
};
|
|
1799
1910
|
websocketIndex += 1;
|
|
1800
1911
|
}
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
});
|
|
1912
|
+
}
|
|
1913
|
+
else if (net.protocol === 'sql') {
|
|
1914
|
+
await this.doSqlCode('list', net.dbId, net.sql);
|
|
1915
|
+
if (net.interval) {
|
|
1916
|
+
net.index = sqlIndex;
|
|
1917
|
+
this.sqlTimerList[sqlIndex] = setInterval(async () => {
|
|
1918
|
+
await this.doSqlCode('list', net.dbId, net.sql);
|
|
1919
|
+
}, net.interval);
|
|
1920
|
+
sqlIndex += 1;
|
|
1809
1921
|
}
|
|
1810
1922
|
}
|
|
1923
|
+
// }
|
|
1811
1924
|
});
|
|
1812
1925
|
}
|
|
1813
1926
|
this.onNetworkConnect(https);
|
|
@@ -1842,6 +1955,28 @@ export class Meta2d {
|
|
|
1842
1955
|
}, 2000);
|
|
1843
1956
|
};
|
|
1844
1957
|
}
|
|
1958
|
+
async getIotToken(devices) {
|
|
1959
|
+
const res = await fetch('/api/iot/subscribe/properties', {
|
|
1960
|
+
method: 'POST',
|
|
1961
|
+
body: JSON.stringify({ devices: devices }),
|
|
1962
|
+
});
|
|
1963
|
+
if (res.ok) {
|
|
1964
|
+
const data = await res.text();
|
|
1965
|
+
return JSON.parse(data).token;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
async doSqlCode(type, dbid, sql) {
|
|
1969
|
+
const res = await fetch(`/api/iot/data/sql/${type}`, {
|
|
1970
|
+
method: 'POST',
|
|
1971
|
+
body: JSON.stringify({ dbid, sql, }),
|
|
1972
|
+
});
|
|
1973
|
+
if (res.ok) {
|
|
1974
|
+
const data = await res.text();
|
|
1975
|
+
if (data) {
|
|
1976
|
+
this.socketCallback(data, { type: 'sql', url: `/api/iot/data/sql/${type}` });
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1845
1980
|
randomString(e) {
|
|
1846
1981
|
e = e || 32;
|
|
1847
1982
|
let t = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678', a = t.length, n = '';
|
|
@@ -2159,6 +2294,11 @@ export class Meta2d {
|
|
|
2159
2294
|
clearInterval(_updateTimer);
|
|
2160
2295
|
_updateTimer = undefined;
|
|
2161
2296
|
});
|
|
2297
|
+
this.sqlTimerList &&
|
|
2298
|
+
this.sqlTimerList.forEach((_sqlTimer) => {
|
|
2299
|
+
clearInterval(_sqlTimer);
|
|
2300
|
+
_sqlTimer = undefined;
|
|
2301
|
+
});
|
|
2162
2302
|
}
|
|
2163
2303
|
socketCallback(message, context) {
|
|
2164
2304
|
this.store.emitter.emit('socket', { message, context });
|
|
@@ -2169,6 +2309,7 @@ export class Meta2d {
|
|
|
2169
2309
|
type: context.type,
|
|
2170
2310
|
topic: context.topic,
|
|
2171
2311
|
url: context.url,
|
|
2312
|
+
method: context.method
|
|
2172
2313
|
});
|
|
2173
2314
|
if (!_message) {
|
|
2174
2315
|
return;
|
|
@@ -2240,7 +2381,7 @@ export class Meta2d {
|
|
|
2240
2381
|
penValues.set(pen, penValue);
|
|
2241
2382
|
}
|
|
2242
2383
|
});
|
|
2243
|
-
this.store.bind[v.id]?.forEach((p) => {
|
|
2384
|
+
this.store.bind[v.id || v.dataId]?.forEach((p) => {
|
|
2244
2385
|
const pen = this.store.pens[p.id];
|
|
2245
2386
|
if (!pen) {
|
|
2246
2387
|
return;
|
|
@@ -2445,6 +2586,14 @@ export class Meta2d {
|
|
|
2445
2586
|
}
|
|
2446
2587
|
break;
|
|
2447
2588
|
case 'click':
|
|
2589
|
+
if (this.store.data.locked && e.pen && (!e.pen.disabled)) {
|
|
2590
|
+
if (e.pen.switch) {
|
|
2591
|
+
e.pen.checked = !e.pen.checked;
|
|
2592
|
+
e.pen.calculative.checked = e.pen.checked;
|
|
2593
|
+
e.pen.calculative.gradient = undefined;
|
|
2594
|
+
e.pen.calculative.radialGradient = undefined;
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2448
2597
|
e.pen && e.pen.onClick && (!e.pen.disabled) && e.pen.onClick(e.pen, this.canvas.mousePos);
|
|
2449
2598
|
this.store.data.locked && e.pen && (!e.pen.disabled) && this.doEvent(e.pen, eventName);
|
|
2450
2599
|
break;
|
|
@@ -2610,8 +2759,19 @@ export class Meta2d {
|
|
|
2610
2759
|
pen.events?.forEach((event, index) => {
|
|
2611
2760
|
if (indexArr.includes(index)) {
|
|
2612
2761
|
event.actions.forEach((action) => {
|
|
2613
|
-
if (
|
|
2614
|
-
|
|
2762
|
+
if (action.timeout) {
|
|
2763
|
+
let timer = setTimeout(() => {
|
|
2764
|
+
if (this.events[action.action]) {
|
|
2765
|
+
this.events[action.action](pen, action);
|
|
2766
|
+
clearTimeout(timer);
|
|
2767
|
+
timer = null;
|
|
2768
|
+
}
|
|
2769
|
+
}, action.timeout);
|
|
2770
|
+
}
|
|
2771
|
+
else {
|
|
2772
|
+
if (this.events[action.action]) {
|
|
2773
|
+
this.events[action.action](pen, action);
|
|
2774
|
+
}
|
|
2615
2775
|
}
|
|
2616
2776
|
});
|
|
2617
2777
|
}
|
|
@@ -2649,7 +2809,18 @@ export class Meta2d {
|
|
|
2649
2809
|
realTime.triggers?.forEach((trigger, index) => {
|
|
2650
2810
|
if (indexArr.includes(index)) {
|
|
2651
2811
|
trigger.actions?.forEach((event) => {
|
|
2652
|
-
|
|
2812
|
+
if (event.timeout) {
|
|
2813
|
+
let timer = setTimeout(() => {
|
|
2814
|
+
if (this.events[event.action]) {
|
|
2815
|
+
this.events[event.action](pen, event);
|
|
2816
|
+
clearTimeout(timer);
|
|
2817
|
+
timer = null;
|
|
2818
|
+
}
|
|
2819
|
+
}, event.timeout);
|
|
2820
|
+
}
|
|
2821
|
+
else {
|
|
2822
|
+
this.events[event.action](pen, event);
|
|
2823
|
+
}
|
|
2653
2824
|
});
|
|
2654
2825
|
}
|
|
2655
2826
|
});
|
|
@@ -2681,7 +2852,18 @@ export class Meta2d {
|
|
|
2681
2852
|
this.store.globalTriggers[pen.id]?.forEach((trigger, index) => {
|
|
2682
2853
|
if (indexArr.includes(index)) {
|
|
2683
2854
|
trigger.actions?.forEach((event) => {
|
|
2684
|
-
|
|
2855
|
+
if (event.timeout) {
|
|
2856
|
+
let timer = setTimeout(() => {
|
|
2857
|
+
if (this.events[event.action]) {
|
|
2858
|
+
this.events[event.action](pen, event);
|
|
2859
|
+
clearTimeout(timer);
|
|
2860
|
+
timer = null;
|
|
2861
|
+
}
|
|
2862
|
+
}, event.timeout);
|
|
2863
|
+
}
|
|
2864
|
+
else {
|
|
2865
|
+
this.events[event.action](pen, event);
|
|
2866
|
+
}
|
|
2685
2867
|
});
|
|
2686
2868
|
}
|
|
2687
2869
|
});
|
|
@@ -2709,7 +2891,18 @@ export class Meta2d {
|
|
|
2709
2891
|
}
|
|
2710
2892
|
if (flag) {
|
|
2711
2893
|
state.actions?.forEach((event) => {
|
|
2712
|
-
|
|
2894
|
+
if (event.timeout) {
|
|
2895
|
+
let timer = setTimeout(() => {
|
|
2896
|
+
if (this.events[event.action]) {
|
|
2897
|
+
this.events[event.action](pen, event);
|
|
2898
|
+
clearTimeout(timer);
|
|
2899
|
+
timer = null;
|
|
2900
|
+
}
|
|
2901
|
+
}, event.timeout);
|
|
2902
|
+
}
|
|
2903
|
+
else {
|
|
2904
|
+
this.events[event.action](pen, event);
|
|
2905
|
+
}
|
|
2713
2906
|
});
|
|
2714
2907
|
break;
|
|
2715
2908
|
}
|
|
@@ -2721,7 +2914,7 @@ export class Meta2d {
|
|
|
2721
2914
|
// 事件冒泡,子执行完,父执行
|
|
2722
2915
|
this.doEvent(this.store.pens[pen.parentId], eventName);
|
|
2723
2916
|
};
|
|
2724
|
-
doMessageEvent(eventName) {
|
|
2917
|
+
doMessageEvent(eventName, data) {
|
|
2725
2918
|
if (this.store.messageEvents[eventName]) {
|
|
2726
2919
|
this.store.messageEvents[eventName].forEach((item) => {
|
|
2727
2920
|
let flag = false;
|
|
@@ -3604,6 +3797,7 @@ export class Meta2d {
|
|
|
3604
3797
|
attrs[attr] =
|
|
3605
3798
|
firstPen[attr] !== undefined ? firstPen[attr] :
|
|
3606
3799
|
(this.store.options.defaultFormat[attr] ||
|
|
3800
|
+
this.store.data[attr] ||
|
|
3607
3801
|
this.store.options[attr]);
|
|
3608
3802
|
});
|
|
3609
3803
|
}
|
|
@@ -3613,6 +3807,7 @@ export class Meta2d {
|
|
|
3613
3807
|
formatAttrs.forEach((attr) => {
|
|
3614
3808
|
attrs[attr] =
|
|
3615
3809
|
this.store.options.defaultFormat[attr] ||
|
|
3810
|
+
this.store.data[attr] ||
|
|
3616
3811
|
this.store.options[attr] ||
|
|
3617
3812
|
undefined;
|
|
3618
3813
|
});
|