@meta2d/core 1.0.53 → 1.0.55
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 +1 -0
- package/src/canvas/canvas.js +62 -24
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +5 -0
- package/src/core.js +211 -50
- package/src/core.js.map +1 -1
- package/src/dialog/dialog.d.ts +8 -1
- package/src/dialog/dialog.js +33 -12
- package/src/dialog/dialog.js.map +1 -1
- package/src/event/event.d.ts +2 -2
- package/src/event/event.js.map +1 -1
- package/src/options.d.ts +1 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +8 -0
- package/src/pen/model.js +11 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +36 -15
- package/src/pen/render.js.map +1 -1
- package/src/store/store.d.ts +5 -0
- package/src/store/store.js.map +1 -1
package/src/core.d.ts
CHANGED
|
@@ -92,6 +92,7 @@ export declare class Meta2d {
|
|
|
92
92
|
* open 后执行初始化 Js ,每个图纸可配置一个初始化 js
|
|
93
93
|
*/
|
|
94
94
|
private doInitJS;
|
|
95
|
+
doInitFn(): void;
|
|
95
96
|
drawLine(lineName?: string): void;
|
|
96
97
|
alignPenToGrid(pen: Pen): void;
|
|
97
98
|
drawingPencil(): void;
|
|
@@ -185,8 +186,10 @@ export declare class Meta2d {
|
|
|
185
186
|
undo(): void;
|
|
186
187
|
redo(): void;
|
|
187
188
|
listenSocket(): boolean;
|
|
189
|
+
websocketTimes: number;
|
|
188
190
|
connectWebsocket(websocket?: string): void;
|
|
189
191
|
closeWebsocket(): void;
|
|
192
|
+
mqttTimes: number;
|
|
190
193
|
connectMqtt(params?: {
|
|
191
194
|
mqtt: string;
|
|
192
195
|
mqttTopics: string;
|
|
@@ -207,6 +210,7 @@ export declare class Meta2d {
|
|
|
207
210
|
updateTimer: any;
|
|
208
211
|
updateTimerList: any[];
|
|
209
212
|
connectNetwork(): void;
|
|
213
|
+
connectNetWebSocket(net: Network): void;
|
|
210
214
|
randomString(e: number): string;
|
|
211
215
|
mockValue(data: any): any;
|
|
212
216
|
dataMock(): void;
|
|
@@ -248,6 +252,7 @@ export declare class Meta2d {
|
|
|
248
252
|
clearRuleLines(): void;
|
|
249
253
|
private onEvent;
|
|
250
254
|
private doEvent;
|
|
255
|
+
doMessageEvent(eventName: string): void;
|
|
251
256
|
doDataEvent: (datas: {
|
|
252
257
|
dataId?: string;
|
|
253
258
|
id?: string;
|
package/src/core.js
CHANGED
|
@@ -83,7 +83,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
83
83
|
};
|
|
84
84
|
import { commonAnchors, commonPens, cube } from './diagrams';
|
|
85
85
|
import { Canvas } from './canvas';
|
|
86
|
-
import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, isShowChild, CanvasLayer, validationPlugin, setLifeCycleFunc, getAllFollowers } from './pen';
|
|
86
|
+
import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, isShowChild, CanvasLayer, validationPlugin, setLifeCycleFunc, getAllFollowers, isInteraction } from './pen';
|
|
87
87
|
import { rotatePoint } from './point';
|
|
88
88
|
import { clearStore, EditType, globalStore, register, registerAnchors, registerCanvasDraw, useStore, } from './store';
|
|
89
89
|
import { formatPadding, loadCss, s8, valueInArray, valueInRange, } from './utils';
|
|
@@ -112,6 +112,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
112
112
|
this.register = register;
|
|
113
113
|
this.registerCanvasDraw = registerCanvasDraw;
|
|
114
114
|
this.registerAnchors = registerAnchors;
|
|
115
|
+
this.websocketTimes = 0;
|
|
116
|
+
this.mqttTimes = 0;
|
|
115
117
|
this.httpTimerList = [];
|
|
116
118
|
this.updateTimerList = [];
|
|
117
119
|
this.onEvent = function (eventName, e) {
|
|
@@ -184,32 +186,14 @@ var Meta2d = /** @class */ (function () {
|
|
|
184
186
|
}
|
|
185
187
|
_this.navigatorTo(e.params);
|
|
186
188
|
break;
|
|
189
|
+
case 'input':
|
|
190
|
+
_this.store.data.locked && e && (!e.disabled) && _this.doEvent(e, eventName);
|
|
191
|
+
break;
|
|
192
|
+
case 'change':
|
|
193
|
+
_this.store.data.locked && e && (!e.disabled) && _this.doEvent(e, eventName);
|
|
194
|
+
break;
|
|
187
195
|
}
|
|
188
|
-
|
|
189
|
-
_this.store.messageEvents[eventName].forEach(function (item) {
|
|
190
|
-
var flag = false;
|
|
191
|
-
if (item.event.conditions && item.event.conditions.length) {
|
|
192
|
-
if (item.event.conditionType === 'and') {
|
|
193
|
-
flag = item.event.conditions.every(function (condition) {
|
|
194
|
-
return _this.judgeCondition(item.pen, condition.key, condition);
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
else if (item.event.conditionType === 'or') {
|
|
198
|
-
flag = item.event.conditions.some(function (condition) {
|
|
199
|
-
return _this.judgeCondition(item.pen, condition.key, condition);
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
flag = true;
|
|
205
|
-
}
|
|
206
|
-
if (flag) {
|
|
207
|
-
item.event.actions.forEach(function (action) {
|
|
208
|
-
_this.events[action.action](item.pen, action);
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
196
|
+
_this.doMessageEvent(eventName);
|
|
213
197
|
};
|
|
214
198
|
this.doEvent = function (pen, eventName) {
|
|
215
199
|
var e_1, _a, e_2, _b;
|
|
@@ -425,7 +409,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
425
409
|
return _this.judgeCondition(pen, condition.key, condition);
|
|
426
410
|
});
|
|
427
411
|
}
|
|
428
|
-
else if (
|
|
412
|
+
else if (state.conditionType === 'or') {
|
|
429
413
|
flag = state.conditions.some(function (condition) {
|
|
430
414
|
return _this.judgeCondition(pen, condition.key, condition);
|
|
431
415
|
});
|
|
@@ -848,10 +832,17 @@ var Meta2d = /** @class */ (function () {
|
|
|
848
832
|
};
|
|
849
833
|
this.events[EventAction.Dialog] = function (pen, e) {
|
|
850
834
|
if (e.params &&
|
|
851
|
-
typeof e.params === 'string'
|
|
852
|
-
e.
|
|
853
|
-
|
|
854
|
-
|
|
835
|
+
typeof e.params === 'string') {
|
|
836
|
+
var url_1 = e.params;
|
|
837
|
+
if (e.params.includes('${')) {
|
|
838
|
+
var keys = e.params.match(/(?<=\$\{).*?(?=\})/g);
|
|
839
|
+
if (keys) {
|
|
840
|
+
keys === null || keys === void 0 ? void 0 : keys.forEach(function (key) {
|
|
841
|
+
url_1 = url_1.replace("${" + key + "}", pen[key]);
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
_this.canvas.dialog.show(e.value, url_1, e.extend);
|
|
855
846
|
}
|
|
856
847
|
};
|
|
857
848
|
this.events[EventAction.SendData] = function (pen, e) {
|
|
@@ -942,7 +933,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
942
933
|
Meta2d.prototype.sendDataToNetWork = function (value, pen, e) {
|
|
943
934
|
var _a;
|
|
944
935
|
return __awaiter(this, void 0, void 0, function () {
|
|
945
|
-
var network, i, keys, params,
|
|
936
|
+
var network, i, keys, params, url_2, keys, res, data, fnJs, clients_1, mqttClient_1, websockets, websocket_1;
|
|
946
937
|
var _this = this;
|
|
947
938
|
return __generator(this, function (_b) {
|
|
948
939
|
switch (_b.label) {
|
|
@@ -967,7 +958,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
967
958
|
}
|
|
968
959
|
}
|
|
969
960
|
params = undefined;
|
|
970
|
-
|
|
961
|
+
url_2 = network.url;
|
|
971
962
|
if (network.method === 'GET') {
|
|
972
963
|
params =
|
|
973
964
|
'?' +
|
|
@@ -976,16 +967,16 @@ var Meta2d = /** @class */ (function () {
|
|
|
976
967
|
.join('&');
|
|
977
968
|
}
|
|
978
969
|
if (network.method === 'POST') {
|
|
979
|
-
if (
|
|
980
|
-
keys =
|
|
970
|
+
if (url_2.indexOf('${') > -1) {
|
|
971
|
+
keys = url_2.match(/(?<=\$\{).*?(?=\})/g);
|
|
981
972
|
if (keys) {
|
|
982
973
|
keys.forEach(function (key) {
|
|
983
|
-
|
|
974
|
+
url_2 = url_2.replace("${" + key + "}", getter(pen, key) || _this.getDynamicParam(key));
|
|
984
975
|
});
|
|
985
976
|
}
|
|
986
977
|
}
|
|
987
978
|
}
|
|
988
|
-
return [4 /*yield*/, fetch(
|
|
979
|
+
return [4 /*yield*/, fetch(url_2 + (params ? params : ''), {
|
|
989
980
|
headers: network.headers || {},
|
|
990
981
|
method: network.method,
|
|
991
982
|
body: network.method === 'POST' ? JSON.stringify(value) : undefined,
|
|
@@ -1248,6 +1239,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1248
1239
|
this.startAnimate();
|
|
1249
1240
|
this.startVideo();
|
|
1250
1241
|
this.doInitJS();
|
|
1242
|
+
this.doInitFn();
|
|
1251
1243
|
if (this.store.data.iconUrls) {
|
|
1252
1244
|
try {
|
|
1253
1245
|
for (var _j = __values(this.store.data.iconUrls), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
@@ -1386,6 +1378,24 @@ var Meta2d = /** @class */ (function () {
|
|
|
1386
1378
|
}
|
|
1387
1379
|
}
|
|
1388
1380
|
};
|
|
1381
|
+
Meta2d.prototype.doInitFn = function () {
|
|
1382
|
+
var params = queryURLParams();
|
|
1383
|
+
var binds = [];
|
|
1384
|
+
for (var key in params) {
|
|
1385
|
+
if (params.hasOwnProperty(key)) {
|
|
1386
|
+
if (key.startsWith('bind-')) {
|
|
1387
|
+
binds.push({
|
|
1388
|
+
id: key.replace('bind-', ''),
|
|
1389
|
+
dataId: key.replace('bind-', ''),
|
|
1390
|
+
value: params[key]
|
|
1391
|
+
});
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
if (binds.length) {
|
|
1396
|
+
this.setDatas(binds, { history: false });
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1389
1399
|
Meta2d.prototype.drawLine = function (lineName) {
|
|
1390
1400
|
lineName && lockedError(this.store);
|
|
1391
1401
|
this.canvas.drawingLineName = lineName;
|
|
@@ -1406,8 +1416,10 @@ var Meta2d = /** @class */ (function () {
|
|
|
1406
1416
|
this.stopPencil();
|
|
1407
1417
|
//恢复可选状态
|
|
1408
1418
|
this.store.data.pens.forEach(function (pen) {
|
|
1419
|
+
var _a;
|
|
1409
1420
|
if (pen.externElement === true) {
|
|
1410
|
-
pen.onMove && pen.onMove(pen);
|
|
1421
|
+
// pen.onMove && pen.onMove(pen);
|
|
1422
|
+
((_a = pen.calculative.singleton) === null || _a === void 0 ? void 0 : _a.div) && setElemPosition(pen, pen.calculative.singleton.div);
|
|
1411
1423
|
}
|
|
1412
1424
|
});
|
|
1413
1425
|
if (lock > 0) {
|
|
@@ -1832,6 +1844,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1832
1844
|
var childRect = calcRelativeRect(pen.calculative.worldRect, rect);
|
|
1833
1845
|
Object.assign(pen, childRect);
|
|
1834
1846
|
pen.locked = (_a = pen.lockedOnCombine) !== null && _a !== void 0 ? _a : LockState.DisableMove;
|
|
1847
|
+
pen.locked = (pen.interaction || isInteraction.includes(pen.name)) ? 0 : pen.locked;
|
|
1835
1848
|
});
|
|
1836
1849
|
//将组合后的父节点置底
|
|
1837
1850
|
this.store.data.pens.splice(minIndex, 0, parent);
|
|
@@ -2057,7 +2070,18 @@ var Meta2d = /** @class */ (function () {
|
|
|
2057
2070
|
url: _this.store.data.websocket,
|
|
2058
2071
|
});
|
|
2059
2072
|
};
|
|
2073
|
+
this.websocket.onerror = function (error) {
|
|
2074
|
+
_this.store.emitter.emit('error', { type: 'websocket', error: error });
|
|
2075
|
+
};
|
|
2060
2076
|
this.websocket.onclose = function () {
|
|
2077
|
+
if (_this.store.options.reconnetTimes) {
|
|
2078
|
+
_this.websocketTimes++;
|
|
2079
|
+
if (_this.websocketTimes >= _this.store.options.reconnetTimes) {
|
|
2080
|
+
_this.websocketTimes = 0;
|
|
2081
|
+
_this.closeWebsocket();
|
|
2082
|
+
return;
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2061
2085
|
console.info('Canvas websocket closed and reconneting...');
|
|
2062
2086
|
_this.connectWebsocket();
|
|
2063
2087
|
};
|
|
@@ -2102,6 +2126,18 @@ var Meta2d = /** @class */ (function () {
|
|
|
2102
2126
|
url: _this.store.data.mqtt,
|
|
2103
2127
|
});
|
|
2104
2128
|
});
|
|
2129
|
+
this.mqttClient.on('error', function (error) {
|
|
2130
|
+
_this.store.emitter.emit('error', { type: 'mqtt', error: error });
|
|
2131
|
+
});
|
|
2132
|
+
this.mqttClient.on('close', function () {
|
|
2133
|
+
if (_this.store.options.reconnetTimes) {
|
|
2134
|
+
_this.mqttTimes++;
|
|
2135
|
+
if (_this.mqttTimes >= _this.store.options.reconnetTimes) {
|
|
2136
|
+
_this.mqttTimes = 0;
|
|
2137
|
+
_this.closeMqtt();
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
});
|
|
2105
2141
|
if (this.store.data.mqttTopics) {
|
|
2106
2142
|
this.mqttClient.subscribe(this.store.data.mqttTopics.split(','));
|
|
2107
2143
|
}
|
|
@@ -2130,10 +2166,19 @@ var Meta2d = /** @class */ (function () {
|
|
|
2130
2166
|
}
|
|
2131
2167
|
https.forEach(function (item, index) {
|
|
2132
2168
|
if (item.http) {
|
|
2169
|
+
item.times = 0;
|
|
2133
2170
|
_this.httpTimerList[index] = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2134
2171
|
return __generator(this, function (_a) {
|
|
2135
2172
|
// 默认每一秒请求一次
|
|
2136
2173
|
this.oldRequestHttp(item);
|
|
2174
|
+
if (this.store.options.reconnetTimes) {
|
|
2175
|
+
item.times++;
|
|
2176
|
+
if (item.times >= this.store.options.reconnetTimes) {
|
|
2177
|
+
item.times = 0;
|
|
2178
|
+
clearInterval(this.httpTimerList[index]);
|
|
2179
|
+
this.httpTimerList[index] = undefined;
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2137
2182
|
return [2 /*return*/];
|
|
2138
2183
|
});
|
|
2139
2184
|
}); }, item.httpTimeInterval || 1000);
|
|
@@ -2172,7 +2217,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2172
2217
|
switch (_a.label) {
|
|
2173
2218
|
case 0:
|
|
2174
2219
|
req = deepClone(_req);
|
|
2175
|
-
if (!req.http) return [3 /*break*/,
|
|
2220
|
+
if (!req.http) return [3 /*break*/, 4];
|
|
2176
2221
|
return [4 /*yield*/, fetch(req.http, {
|
|
2177
2222
|
headers: req.httpHeaders,
|
|
2178
2223
|
method: req.method || 'GET',
|
|
@@ -2185,8 +2230,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
2185
2230
|
case 2:
|
|
2186
2231
|
data = _a.sent();
|
|
2187
2232
|
this.socketCallback(data, { type: 'http', url: req.http });
|
|
2188
|
-
|
|
2189
|
-
case 3:
|
|
2233
|
+
return [3 /*break*/, 4];
|
|
2234
|
+
case 3:
|
|
2235
|
+
this.store.emitter.emit('error', { type: 'http', error: res });
|
|
2236
|
+
_a.label = 4;
|
|
2237
|
+
case 4: return [2 /*return*/];
|
|
2190
2238
|
}
|
|
2191
2239
|
});
|
|
2192
2240
|
});
|
|
@@ -2263,9 +2311,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
2263
2311
|
networks.forEach(function (net) {
|
|
2264
2312
|
if (net.type === 'subscribe') {
|
|
2265
2313
|
if (net.protocol === 'mqtt') {
|
|
2314
|
+
net.index = mqttIndex_1;
|
|
2266
2315
|
if (net.options.clientId && !net.options.customClientId) {
|
|
2267
2316
|
net.options.clientId = s8();
|
|
2268
2317
|
}
|
|
2318
|
+
net.times = 0;
|
|
2269
2319
|
_this.mqttClients[mqttIndex_1] = mqtt.connect(net.url, net.options);
|
|
2270
2320
|
_this.mqttClients[mqttIndex_1].on('message', function (topic, message) {
|
|
2271
2321
|
_this.socketCallback(message.toString(), {
|
|
@@ -2274,16 +2324,48 @@ var Meta2d = /** @class */ (function () {
|
|
|
2274
2324
|
url: net.url,
|
|
2275
2325
|
});
|
|
2276
2326
|
});
|
|
2327
|
+
_this.mqttClients[mqttIndex_1].on('error', function (error) {
|
|
2328
|
+
_this.store.emitter.emit('error', { type: 'mqtt', error: error });
|
|
2329
|
+
});
|
|
2330
|
+
_this.mqttClients[mqttIndex_1].on('close', function () {
|
|
2331
|
+
var _a;
|
|
2332
|
+
if (_this.store.options.reconnetTimes) {
|
|
2333
|
+
net.times++;
|
|
2334
|
+
if (net.times >= _this.store.options.reconnetTimes) {
|
|
2335
|
+
net.times = 0;
|
|
2336
|
+
_this.mqttClients && ((_a = _this.mqttClients[net.index]) === null || _a === void 0 ? void 0 : _a.end());
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
});
|
|
2277
2340
|
if (net.topics) {
|
|
2278
2341
|
_this.mqttClients[mqttIndex_1].subscribe(net.topics.split(','));
|
|
2279
2342
|
}
|
|
2280
2343
|
mqttIndex_1 += 1;
|
|
2281
2344
|
}
|
|
2282
2345
|
else if (net.protocol === 'websocket') {
|
|
2283
|
-
|
|
2284
|
-
_this.
|
|
2285
|
-
|
|
2286
|
-
|
|
2346
|
+
net.index = websocketIndex_1;
|
|
2347
|
+
_this.connectNetWebSocket(net);
|
|
2348
|
+
// this.websockets[websocketIndex] = new WebSocket(
|
|
2349
|
+
// net.url,
|
|
2350
|
+
// net.protocols || undefined
|
|
2351
|
+
// );
|
|
2352
|
+
// this.websockets[websocketIndex].onmessage = (e) => {
|
|
2353
|
+
// this.socketCallback(e.data, { type: 'websocket', url: net.url });
|
|
2354
|
+
// };
|
|
2355
|
+
// this.websockets[websocketIndex].onerror = (error) => {
|
|
2356
|
+
// this.store.emitter.emit('error', { type: 'websocket', error });
|
|
2357
|
+
// };
|
|
2358
|
+
// this.websockets[websocketIndex].onclose = () => {
|
|
2359
|
+
// if (this.store.options.reconnetTimes) {
|
|
2360
|
+
// net.times++;
|
|
2361
|
+
// if (net.times >= this.store.options.reconnetTimes) {
|
|
2362
|
+
// net.times = 0;
|
|
2363
|
+
// this.websockets[net.index]?.close();
|
|
2364
|
+
// return;
|
|
2365
|
+
// }
|
|
2366
|
+
// }
|
|
2367
|
+
// console.info('Canvas websocket closed and reconneting...');
|
|
2368
|
+
// };
|
|
2287
2369
|
websocketIndex_1 += 1;
|
|
2288
2370
|
}
|
|
2289
2371
|
else if (net.protocol === 'http') {
|
|
@@ -2300,6 +2382,39 @@ var Meta2d = /** @class */ (function () {
|
|
|
2300
2382
|
}
|
|
2301
2383
|
this.onNetworkConnect(https);
|
|
2302
2384
|
};
|
|
2385
|
+
Meta2d.prototype.connectNetWebSocket = function (net) {
|
|
2386
|
+
var _this = this;
|
|
2387
|
+
var _a;
|
|
2388
|
+
if (this.websockets[net.index]) {
|
|
2389
|
+
this.websockets[net.index].onclose = undefined;
|
|
2390
|
+
(_a = this.websockets[net.index]) === null || _a === void 0 ? void 0 : _a.close();
|
|
2391
|
+
this.websockets[net.index] = undefined;
|
|
2392
|
+
}
|
|
2393
|
+
this.websockets[net.index] = new WebSocket(net.url, net.protocols || undefined);
|
|
2394
|
+
this.websockets[net.index].onmessage = function (e) {
|
|
2395
|
+
_this.socketCallback(e.data, { type: 'websocket', url: net.url });
|
|
2396
|
+
};
|
|
2397
|
+
this.websockets[net.index].onerror = function (error) {
|
|
2398
|
+
_this.store.emitter.emit('error', { type: 'websocket', error: error });
|
|
2399
|
+
};
|
|
2400
|
+
this.websockets[net.index].onclose = function () {
|
|
2401
|
+
var _a;
|
|
2402
|
+
if (_this.store.options.reconnetTimes) {
|
|
2403
|
+
net.times++;
|
|
2404
|
+
if (net.times >= _this.store.options.reconnetTimes) {
|
|
2405
|
+
net.times = 0;
|
|
2406
|
+
_this.websockets[net.index].onclose = undefined;
|
|
2407
|
+
(_a = _this.websockets[net.index]) === null || _a === void 0 ? void 0 : _a.close();
|
|
2408
|
+
_this.websockets[net.index] = undefined;
|
|
2409
|
+
return;
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
setTimeout(function () {
|
|
2413
|
+
console.info('Canvas websocket closed and reconneting...');
|
|
2414
|
+
_this.connectNetWebSocket(net);
|
|
2415
|
+
}, 2000);
|
|
2416
|
+
};
|
|
2417
|
+
};
|
|
2303
2418
|
Meta2d.prototype.randomString = function (e) {
|
|
2304
2419
|
e = e || 32;
|
|
2305
2420
|
var t = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678', a = t.length, n = '';
|
|
@@ -2479,8 +2594,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
2479
2594
|
if (Object.keys(_d_1).length) {
|
|
2480
2595
|
var data = pen.onBeforeValue ? pen.onBeforeValue(pen, _d_1) : _d_1;
|
|
2481
2596
|
this.canvas.updateValue(pen, data);
|
|
2482
|
-
this.store.emitter.emit('valueUpdate', pen);
|
|
2597
|
+
// this.store.emitter.emit('valueUpdate', pen);
|
|
2483
2598
|
(_a = pen.onValue) === null || _a === void 0 ? void 0 : _a.call(pen, pen);
|
|
2599
|
+
this.store.emitter.emit('valueUpdate', pen);
|
|
2484
2600
|
}
|
|
2485
2601
|
}
|
|
2486
2602
|
};
|
|
@@ -2551,9 +2667,18 @@ var Meta2d = /** @class */ (function () {
|
|
|
2551
2667
|
// }, this.store.data.networkInterval || 1000);
|
|
2552
2668
|
// }
|
|
2553
2669
|
https.forEach(function (_item, index) {
|
|
2670
|
+
_item.times = 0;
|
|
2554
2671
|
_this.updateTimerList[index] = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2555
2672
|
return __generator(this, function (_a) {
|
|
2556
2673
|
this.requestHttp(_item);
|
|
2674
|
+
if (this.store.options.reconnetTimes) {
|
|
2675
|
+
_item.times++;
|
|
2676
|
+
if (_item.times >= this.store.options.reconnetTimes) {
|
|
2677
|
+
_item.times = 0;
|
|
2678
|
+
clearInterval(this.updateTimerList[index]);
|
|
2679
|
+
this.updateTimerList[index] = undefined;
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2557
2682
|
return [2 /*return*/];
|
|
2558
2683
|
});
|
|
2559
2684
|
}); }, _item.interval || 1000);
|
|
@@ -2566,7 +2691,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2566
2691
|
switch (_a.label) {
|
|
2567
2692
|
case 0:
|
|
2568
2693
|
req = deepClone(_req);
|
|
2569
|
-
if (!req.url) return [3 /*break*/,
|
|
2694
|
+
if (!req.url) return [3 /*break*/, 4];
|
|
2570
2695
|
if (typeof req.headers === 'object') {
|
|
2571
2696
|
for (i in req.headers) {
|
|
2572
2697
|
if (typeof req.headers[i] === 'string') {
|
|
@@ -2599,8 +2724,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
2599
2724
|
case 2:
|
|
2600
2725
|
data = _a.sent();
|
|
2601
2726
|
this.socketCallback(data, { type: 'http', url: req.url });
|
|
2602
|
-
|
|
2603
|
-
case 3:
|
|
2727
|
+
return [3 /*break*/, 4];
|
|
2728
|
+
case 3:
|
|
2729
|
+
this.store.emitter.emit('error', { type: 'http', error: res });
|
|
2730
|
+
_a.label = 4;
|
|
2731
|
+
case 4: return [2 /*return*/];
|
|
2604
2732
|
}
|
|
2605
2733
|
});
|
|
2606
2734
|
});
|
|
@@ -2612,7 +2740,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
2612
2740
|
});
|
|
2613
2741
|
this.websockets &&
|
|
2614
2742
|
this.websockets.forEach(function (websocket) {
|
|
2615
|
-
websocket
|
|
2743
|
+
if (websocket) {
|
|
2744
|
+
websocket.onclose = undefined;
|
|
2745
|
+
websocket.close();
|
|
2746
|
+
websocket = undefined;
|
|
2747
|
+
}
|
|
2616
2748
|
});
|
|
2617
2749
|
this.mqttClients = undefined;
|
|
2618
2750
|
this.websockets = undefined;
|
|
@@ -2893,6 +3025,34 @@ var Meta2d = /** @class */ (function () {
|
|
|
2893
3025
|
Meta2d.prototype.clearRuleLines = function () {
|
|
2894
3026
|
this.canvas.clearRuleLines();
|
|
2895
3027
|
};
|
|
3028
|
+
Meta2d.prototype.doMessageEvent = function (eventName) {
|
|
3029
|
+
var _this = this;
|
|
3030
|
+
if (this.store.messageEvents[eventName]) {
|
|
3031
|
+
this.store.messageEvents[eventName].forEach(function (item) {
|
|
3032
|
+
var flag = false;
|
|
3033
|
+
if (item.event.conditions && item.event.conditions.length) {
|
|
3034
|
+
if (item.event.conditionType === 'and') {
|
|
3035
|
+
flag = item.event.conditions.every(function (condition) {
|
|
3036
|
+
return _this.judgeCondition(item.pen, condition.key, condition);
|
|
3037
|
+
});
|
|
3038
|
+
}
|
|
3039
|
+
else if (item.event.conditionType === 'or') {
|
|
3040
|
+
flag = item.event.conditions.some(function (condition) {
|
|
3041
|
+
return _this.judgeCondition(item.pen, condition.key, condition);
|
|
3042
|
+
});
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
else {
|
|
3046
|
+
flag = true;
|
|
3047
|
+
}
|
|
3048
|
+
if (flag) {
|
|
3049
|
+
item.event.actions.forEach(function (action) {
|
|
3050
|
+
_this.events[action.action](item.pen, action);
|
|
3051
|
+
});
|
|
3052
|
+
}
|
|
3053
|
+
});
|
|
3054
|
+
}
|
|
3055
|
+
};
|
|
2896
3056
|
Meta2d.prototype.initGlobalTriggers = function () {
|
|
2897
3057
|
var _this = this;
|
|
2898
3058
|
var _a;
|
|
@@ -3085,6 +3245,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3085
3245
|
var childRect = calcRelativeRect(pen.calculative.worldRect, parent.calculative.worldRect);
|
|
3086
3246
|
Object.assign(pen, childRect);
|
|
3087
3247
|
pen.locked = (_a = pen.lockedOnCombine) !== null && _a !== void 0 ? _a : LockState.DisableMove;
|
|
3248
|
+
pen.locked = (pen.interaction || isInteraction.includes(pen.name)) ? 0 : pen.locked;
|
|
3088
3249
|
if (!oldPen) {
|
|
3089
3250
|
addPens.push(deepClone(pen, true));
|
|
3090
3251
|
}
|