mm_os 3.3.0 → 4.0.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.
- package/LICENSE +21 -201
- package/README.md +491 -99
- package/README_EN.md +498 -0
- package/adapter/adapter.js +431 -0
- package/adapter/custom_persistence.js +660 -0
- package/adapter/mqtt.js +273 -0
- package/adapter/socket.js +113 -0
- package/adapter/web.js +67 -0
- package/adapter/websocket.js +146 -0
- package/com/api/com.json +5 -0
- package/{core/com → com}/api/config.tpl.json +8 -8
- package/com/api/drive.js +708 -0
- package/com/api/index.js +198 -0
- package/com/api/oauth.js +200 -0
- package/com/api/script.tpl.js +32 -0
- package/com/cmd/README.md +11 -0
- package/com/cmd/com.json +5 -0
- package/com/cmd/config.tpl.json +122 -0
- package/com/cmd/drive.js +1548 -0
- package/com/cmd/index.js +1066 -0
- package/com/cmd/msg.json +48 -0
- package/com/cmd/nlp.js +525 -0
- package/com/cmd/script.tpl.js +32 -0
- package/com/db/com.json +5 -0
- package/com/db/drive.js +1999 -0
- package/com/db/index.js +242 -0
- package/com/event/com.json +5 -0
- package/{core/com → com}/event/config.tpl.json +8 -8
- package/com/event/drive.js +59 -0
- package/com/event/index.js +409 -0
- package/com/event/script.tpl.js +23 -0
- package/com/mqtt/com.json +5 -0
- package/{core/com → com}/mqtt/config.tpl.json +3 -5
- package/com/mqtt/drive.js +676 -0
- package/com/mqtt/index.js +822 -0
- package/com/mqtt/mm_mqtt.js +425 -0
- package/com/mqtt/script.tpl.js +723 -0
- package/com/nav/com.json +5 -0
- package/com/nav/config.tpl.json +84 -0
- package/com/nav/drive.js +702 -0
- package/com/nav/index.js +231 -0
- package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
- package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
- package/com/nav/tpl/admin_pc/page_form.vue +180 -0
- package/com/nav/tpl/admin_pc/page_view.vue +124 -0
- package/com/nav/tpl/dev_pc/page_default.vue +247 -0
- package/com/nav/tpl/dev_pc/page_type.vue +313 -0
- package/com/nav/tpl/home_pc/page_default.vue +234 -0
- package/com/nav/tpl/home_pc/page_form.vue +137 -0
- package/com/nav/tpl/home_pc/page_list.vue +234 -0
- package/com/nav/tpl/home_pc/page_nav.vue +221 -0
- package/com/nav/tpl/home_pc/page_type.vue +234 -0
- package/com/nav/tpl/home_pc/page_view.vue +125 -0
- package/com/nav/tpl/home_phone/page_channel.vue +234 -0
- package/com/nav/tpl/home_phone/page_default.vue +234 -0
- package/com/nav/tpl/home_phone/page_form.vue +137 -0
- package/com/nav/tpl/home_phone/page_nav.vue +237 -0
- package/com/nav/tpl/home_phone/page_type.vue +234 -0
- package/com/nav/tpl/home_phone/page_view.vue +125 -0
- package/com/nav/viewmodel.js +446 -0
- package/com/param/com.json +5 -0
- package/{core/com → com}/param/config.tpl.json +7 -1
- package/com/param/drive.js +502 -0
- package/com/param/index.js +155 -0
- package/com/param/script.tpl.js +12 -0
- package/com/pendant/com.json +5 -0
- package/{core/com/component → com/pendant}/config.tpl.json +15 -13
- package/com/pendant/drive.js +204 -0
- package/com/pendant/index.js +441 -0
- package/com/pendant/pendant.html +16 -0
- package/com/pendant/script.tpl.js +18 -0
- package/com/socket/com.json +5 -0
- package/com/socket/config.tpl.json +12 -0
- package/com/socket/drive.js +651 -0
- package/com/socket/index.js +351 -0
- package/com/socket/script.tpl.js +41 -0
- package/com/sql/com.json +5 -0
- package/{core/com → com}/sql/config.tpl.json +13 -9
- package/com/sql/drive.js +1259 -0
- package/com/sql/index.js +150 -0
- package/com/sql/script.tpl.js +47 -0
- package/com/static/com.json +5 -0
- package/{core/com → com}/static/config.tpl.json +10 -6
- package/com/static/drive.js +194 -0
- package/com/static/index.js +226 -0
- package/com/static/script.tpl.js +28 -0
- package/com/task/com.json +5 -0
- package/{core/com → com}/task/config.tpl.json +4 -6
- package/com/task/drive.js +405 -0
- package/com/task/index.js +148 -0
- package/com/task/script.tpl.js +37 -0
- package/com/template/com.json +5 -0
- package/com/template/config.tpl.json +16 -0
- package/com/template/drive.js +80 -0
- package/com/template/index.js +141 -0
- package/com.js +156 -0
- package/common/README.md +2 -0
- package/common/handler/msg/handler.json +22 -0
- package/common/handler/msg/index.js +23 -0
- package/common/handler/player/handler.json +22 -0
- package/common/handler/player/index.js +287 -0
- package/common/handler/user/handler.json +22 -0
- package/common/handler/user/index.js +23 -0
- package/common/middleware/web_after/index.js +29 -0
- package/common/middleware/web_after/middleware.json +9 -0
- package/common/middleware/web_base/index.js +113 -0
- package/common/middleware/web_base/middleware.json +19 -0
- package/common/middleware/web_before/index.js +33 -0
- package/common/middleware/web_before/middleware.json +9 -0
- package/common/middleware/web_cors/index.js +87 -0
- package/common/middleware/web_cors/middleware.json +24 -0
- package/common/middleware/web_error/index.js +119 -0
- package/common/middleware/web_error/middleware.json +18 -0
- package/common/middleware/web_ip/index.js +15 -0
- package/common/middleware/web_ip/middleware.json +14 -0
- package/common/middleware/web_logger/index.js +156 -0
- package/common/middleware/web_logger/middleware.json +14 -0
- package/common/middleware/web_main/index.js +24 -0
- package/common/middleware/web_main/middleware.json +9 -0
- package/common/middleware/web_static/index.js +73 -0
- package/common/middleware/web_static/middleware.json +54 -0
- package/common/middleware/web_waf/index.js +385 -0
- package/common/middleware/web_waf/middleware.json +13 -0
- package/common/model/msg/index.js +88 -0
- package/common/model/msg/model.json +401 -0
- package/common/model/player/index.js +63 -0
- package/common/model/player/model.json +185 -0
- package/common/model/user/index.js +11 -0
- package/common/model/user/model.json +219 -0
- package/core/app/config.tpl.json +67 -0
- package/core/app/index.js +632 -0
- package/core/app/script.tpl.js +52 -0
- package/core/channel/index.js +899 -0
- package/core/channel/matcher.js +585 -0
- package/core/com/config.tpl.json +16 -0
- package/core/com/index.js +74 -0
- package/core/com/script.tpl.js +5 -0
- package/core/component/component.js +42 -0
- package/core/component/config.tpl.json +63 -0
- package/core/component/index.js +273 -0
- package/core/component/script.tpl.js +19 -0
- package/core/controller/config.tpl.json +14 -0
- package/core/controller/index.js +373 -0
- package/core/controller/script.tpl.js +27 -0
- package/core/factory/config.tpl.json +14 -0
- package/core/factory/entity.js +275 -0
- package/core/factory/index.js +241 -0
- package/core/factory/script.tpl.js +16 -0
- package/core/game/bat/index.js +137 -0
- package/core/game/bat/world.js +622 -0
- package/core/game/config.tpl.json +16 -0
- package/core/game/entity_admin.js +230 -0
- package/core/game/index.js +186 -0
- package/core/handler/config.tpl.json +22 -0
- package/core/handler/index.js +181 -0
- package/core/handler/script.tpl.js +23 -0
- package/core/logic/config.tpl.json +14 -0
- package/core/logic/index.js +59 -0
- package/core/logic/script.tpl.js +19 -0
- package/core/middleware/config.tpl.json +16 -0
- package/core/middleware/index.js +125 -0
- package/core/middleware/script.tpl.js +37 -0
- package/core/mod/config.tpl.json +22 -0
- package/core/mod/index.js +130 -0
- package/core/mod/script.tpl.js +34 -0
- package/core/model/config.tpl.json +219 -0
- package/core/model/index.js +272 -0
- package/core/model/model.js +27 -0
- package/core/model/script.tpl.js +20 -0
- package/core/notifier/config.tpl.json +14 -0
- package/core/notifier/index.js +77 -0
- package/core/notifier/script.tpl.js +20 -0
- package/core/plugin/config.tpl.json +24 -0
- package/core/plugin/index.js +232 -0
- package/core/plugin/script.tpl.js +51 -0
- package/core/pusher/config.tpl.json +14 -0
- package/core/pusher/index.js +161 -0
- package/core/pusher/script.tpl.js +20 -0
- package/core/room/bat/index.js +170 -0
- package/core/room/bat/room.js +524 -0
- package/core/room/config.tpl.json +20 -0
- package/core/room/index.js +249 -0
- package/core/room/room.js +61 -0
- package/core/scene/config.tpl.json +14 -0
- package/core/scene/index.js +466 -0
- package/core/scene/loop.js +1255 -0
- package/core/scene/map.js +28 -0
- package/core/scene/script.tpl.js +22 -0
- package/core/sender/config.tpl.json +14 -0
- package/core/sender/index.js +79 -0
- package/core/sender/script.tpl.js +20 -0
- package/core/service/config.tpl.json +14 -0
- package/core/service/index.js +100 -0
- package/core/service/script.tpl.js +25 -0
- package/core/store/config.tpl.json +26 -0
- package/core/store/index.js +1755 -0
- package/core/store/script.tpl.js +22 -0
- package/core/store/sql.js +1464 -0
- package/core/system/config.tpl.json +18 -0
- package/core/system/index.js +312 -0
- package/core/system/script.tpl.js +77 -0
- package/core/view/config.tpl.json +14 -0
- package/core/view/index.js +91 -0
- package/core/view/script.tpl.js +20 -0
- package/core/zone/bat/index.js +725 -0
- package/core/zone/config.tpl.json +54 -0
- package/core/zone/index.js +614 -0
- package/core/zone/script.tpl.js +10 -0
- package/core/zone/zone_bat.js +136 -0
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
- package/index.js +17 -314
- package/os.js +57 -0
- package/package.json +60 -58
- package/server.js +598 -0
- package/README.en.md +0 -36
- package/conf.json +0 -3
- package/core/base/mqtt/index.js +0 -1107
- package/core/base/mqtt/lib.js +0 -40
- package/core/base/web/index.js +0 -243
- package/core/com/api/com.json +0 -4
- package/core/com/api/drive.js +0 -668
- package/core/com/api/index.js +0 -108
- package/core/com/api/oauth.js +0 -158
- package/core/com/api/script.js +0 -32
- package/core/com/app/README.md +0 -3
- package/core/com/app/com.json +0 -4
- package/core/com/app/config.tpl.json +0 -16
- package/core/com/app/drive.js +0 -309
- package/core/com/app/index.js +0 -211
- package/core/com/app/script.js +0 -155
- package/core/com/cmd/com.json +0 -4
- package/core/com/cmd/config.tpl.json +0 -66
- package/core/com/cmd/drive.js +0 -513
- package/core/com/cmd/index.js +0 -354
- package/core/com/cmd/old/5w2h.js +0 -54
- package/core/com/cmd/old/drive.js +0 -423
- package/core/com/cmd/script.js +0 -11
- package/core/com/component/README.md +0 -3
- package/core/com/component/com.json +0 -4
- package/core/com/component/component.html +0 -16
- package/core/com/component/drive.js +0 -197
- package/core/com/component/index.js +0 -312
- package/core/com/component/script.js +0 -18
- package/core/com/db/com.json +0 -4
- package/core/com/db/drive.js +0 -1160
- package/core/com/db/index.js +0 -176
- package/core/com/event/com.json +0 -4
- package/core/com/event/drive.js +0 -133
- package/core/com/event/index.js +0 -345
- package/core/com/event/script.js +0 -26
- package/core/com/eventer/com.js +0 -477
- package/core/com/eventer/com.json +0 -4
- package/core/com/middleware/com.js +0 -153
- package/core/com/middleware/com.json +0 -4
- package/core/com/middleware/config.tpl.json +0 -8
- package/core/com/middleware/script.js +0 -9
- package/core/com/mqtt/com.json +0 -4
- package/core/com/mqtt/drive.js +0 -600
- package/core/com/mqtt/index.js +0 -572
- package/core/com/mqtt/mm_mqtt.js +0 -330
- package/core/com/mqtt/script.js +0 -604
- package/core/com/msg/com.js +0 -296
- package/core/com/msg/com.json +0 -4
- package/core/com/nav/com.json +0 -4
- package/core/com/nav/config.tpl.json +0 -75
- package/core/com/nav/drive.js +0 -549
- package/core/com/nav/index.js +0 -182
- package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/core/com/nav/viewmodel.js +0 -296
- package/core/com/param/drive.js +0 -366
- package/core/com/param/index.js +0 -80
- package/core/com/param/script.js +0 -12
- package/core/com/param/test.js +0 -98
- package/core/com/plugin/README.md +0 -3
- package/core/com/plugin/com.json +0 -4
- package/core/com/plugin/config.tpl.json +0 -26
- package/core/com/plugin/drive.js +0 -536
- package/core/com/plugin/index.js +0 -259
- package/core/com/plugin/script.js +0 -213
- package/core/com/rpc/com.json +0 -4
- package/core/com/rpc/drive.js +0 -160
- package/core/com/rpc/index.js +0 -87
- package/core/com/rpc/rpc.js +0 -118
- package/core/com/socket/com.json +0 -4
- package/core/com/socket/config.tpl.json +0 -14
- package/core/com/socket/drive.js +0 -403
- package/core/com/socket/index.js +0 -62
- package/core/com/socket/script.js +0 -42
- package/core/com/sql/drive.js +0 -1087
- package/core/com/sql/index.js +0 -83
- package/core/com/sql/script.js +0 -48
- package/core/com/static/com.json +0 -4
- package/core/com/static/drive.js +0 -220
- package/core/com/static/index.js +0 -149
- package/core/com/static/script.js +0 -28
- package/core/com/task/com.json +0 -4
- package/core/com/task/drive.js +0 -403
- package/core/com/task/index.js +0 -110
- package/core/com/task/script.js +0 -37
- package/core/com/timer/com.js +0 -217
- package/core/com/timer/com.json +0 -4
- package/core/com/tpl/com.js +0 -19
- package/core/com/tpl/com.json +0 -4
- package/lib/actions.js +0 -50
- package/lib/base.js +0 -361
- package/lib/com.js +0 -29
- package/lib/ref.js +0 -121
- package/middleware/mqtt_base/index.js +0 -10
- package/middleware/mqtt_base/middleware.json +0 -10
- package/middleware/performance/index.js +0 -151
- package/middleware/performance/middleware.json +0 -16
- package/middleware/security_audit/index.js +0 -549
- package/middleware/security_audit/middleware.json +0 -48
- package/middleware/security_headers/index.js +0 -487
- package/middleware/security_headers/middleware.json +0 -45
- package/middleware/waf/index.js +0 -348
- package/middleware/waf/middleware.json +0 -10
- package/middleware/waf_ddos/index.js +0 -520
- package/middleware/waf_ddos/middleware.json +0 -38
- package/middleware/waf_ip/index.js +0 -379
- package/middleware/waf_ip/middleware.json +0 -49
- package/middleware/waf_xss/index.js +0 -269
- package/middleware/waf_xss/middleware.json +0 -18
- package/middleware/web_after/index.js +0 -33
- package/middleware/web_after/middleware.json +0 -9
- package/middleware/web_base/index.js +0 -90
- package/middleware/web_base/middleware.json +0 -9
- package/middleware/web_before/index.js +0 -27
- package/middleware/web_before/middleware.json +0 -9
- package/middleware/web_check/index.js +0 -28
- package/middleware/web_check/middleware.json +0 -9
- package/middleware/web_main/index.js +0 -28
- package/middleware/web_main/middleware.json +0 -9
- package/middleware/web_proxy/index.js +0 -37
- package/middleware/web_proxy/middleware.json +0 -9
- package/middleware/web_render/index.js +0 -87
- package/middleware/web_render/middleware.json +0 -9
- package/middleware/web_socket/index.js +0 -34
- package/middleware/web_socket/middleware.json +0 -9
- package/middleware/web_static/index.js +0 -115
- package/middleware/web_static/middleware.json +0 -9
- /package/{core/com → com}/api/README.md +0 -0
- /package/{core/com → com}/db/README.md +0 -0
- /package/{core/com → com}/event/README.md +0 -0
- /package/{core/com → com}/mqtt/README.md +0 -0
- /package/{core/com → com}/nav/README.md +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
- /package/{core/com → com}/param/README.md +0 -0
- /package/{core/com/cmd → com/pendant}/README.md +0 -0
- /package/{core/com → com}/socket/README.md +0 -0
- /package/{core/com → com}/sql/README.md +0 -0
- /package/{core/com → com}/static/README.md +0 -0
- /package/{core/com → com}/task/README.md +0 -0
package/core/com/eventer/com.js
DELETED
|
@@ -1,477 +0,0 @@
|
|
|
1
|
-
const {
|
|
2
|
-
types
|
|
3
|
-
} = require("util");
|
|
4
|
-
|
|
5
|
-
class Eventer {
|
|
6
|
-
/**
|
|
7
|
-
* 构造函数
|
|
8
|
-
* @param {Object} config 配置参数
|
|
9
|
-
*/
|
|
10
|
-
constructor(config) {
|
|
11
|
-
this.dict = {};
|
|
12
|
-
this.list_add = [];
|
|
13
|
-
this.list_del = [];
|
|
14
|
-
// 模式,0为执行完不重载程序,1为执行完后重载程序。
|
|
15
|
-
this.mode = 0;
|
|
16
|
-
// 自增ID,用于添加事件处理程序后可控更新和卸载。
|
|
17
|
-
this.autoId = 1;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 事件模型
|
|
23
|
-
* @param {String|Number} id ID,用于标识查找事件,方便调用、更替和删除
|
|
24
|
-
*/
|
|
25
|
-
Eventer.prototype.model = function(id = "") {
|
|
26
|
-
if (!id) {
|
|
27
|
-
id = this.autoId;
|
|
28
|
-
this.autoId++;
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
// 事件ID
|
|
32
|
-
id,
|
|
33
|
-
// 消息类型
|
|
34
|
-
type: "发动攻击时",
|
|
35
|
-
// 时态
|
|
36
|
-
tense: "main",
|
|
37
|
-
// 总执行次数 -1为无限次
|
|
38
|
-
count: 0,
|
|
39
|
-
// 执行次数
|
|
40
|
-
num: 0,
|
|
41
|
-
// 状态 1启用,2暂停,0结束
|
|
42
|
-
state: 1,
|
|
43
|
-
// 参数
|
|
44
|
-
param: {},
|
|
45
|
-
// 回调函数
|
|
46
|
-
func: function() {}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 添加事件
|
|
52
|
-
* @param {String} type 事件类型
|
|
53
|
-
* @param {Function} func 回调函数
|
|
54
|
-
* @param {Object} param 回调附加参数
|
|
55
|
-
* @param {String} tense 时态 before执行前|check确认是否执行|main执行|after执行后
|
|
56
|
-
* @param {Number} count 执行次数
|
|
57
|
-
* @param {String|Number} id ID,用于标识查找事件,方便调用、更替和删除
|
|
58
|
-
*/
|
|
59
|
-
Eventer.prototype.add = function(type, func, param, tense, count = -1, id = "") {
|
|
60
|
-
var info;
|
|
61
|
-
if (typeof(type) === "object") {
|
|
62
|
-
info = type;
|
|
63
|
-
if (!info.id) {
|
|
64
|
-
if (!id) {
|
|
65
|
-
id = this.autoId;
|
|
66
|
-
this.autoId++;
|
|
67
|
-
}
|
|
68
|
-
info.id = id;
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
if (!id) {
|
|
72
|
-
id = this.autoId;
|
|
73
|
-
this.autoId++;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
info = {
|
|
77
|
-
id,
|
|
78
|
-
type,
|
|
79
|
-
tense: tense || "main",
|
|
80
|
-
num: 0,
|
|
81
|
-
state: 1,
|
|
82
|
-
count,
|
|
83
|
-
param,
|
|
84
|
-
func
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
this.list_add.push(info);
|
|
88
|
-
return id;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 执行全部事件前
|
|
93
|
-
*/
|
|
94
|
-
Eventer.prototype.do_before = function() {
|
|
95
|
-
// 追加事件
|
|
96
|
-
var list = this.list_add;
|
|
97
|
-
for (var i = 0; i < list.length; i++) {
|
|
98
|
-
var o = list[i];
|
|
99
|
-
var dt = this.dict[o.type];
|
|
100
|
-
if (!dt) {
|
|
101
|
-
this.dict[o.type] = {
|
|
102
|
-
before: [],
|
|
103
|
-
check: [],
|
|
104
|
-
main: [],
|
|
105
|
-
after: []
|
|
106
|
-
};
|
|
107
|
-
dt = this.dict[o.type];
|
|
108
|
-
}
|
|
109
|
-
var lt = dt[o.tense];
|
|
110
|
-
if (lt) {
|
|
111
|
-
lt.add(o);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
this.list_add.clear();
|
|
115
|
-
|
|
116
|
-
// 移除事件
|
|
117
|
-
var list = this.list_del;
|
|
118
|
-
for (var i = 0; i < list.length; i++) {
|
|
119
|
-
var o = list[i];
|
|
120
|
-
var dt = this.dict[o.type];
|
|
121
|
-
if (dt) {
|
|
122
|
-
var lt = dt[o.tense];
|
|
123
|
-
if (lt) {
|
|
124
|
-
lt.del({
|
|
125
|
-
id: o.id
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
if (!dt.before.length && !dt.check.length && !dt.main.length && !dt.after.length) {
|
|
129
|
-
delete this.dict[o.type];
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
this.list_del.clear();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* 执行全部事件后
|
|
138
|
-
*/
|
|
139
|
-
Eventer.prototype.do_after = function() {
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 执行事件
|
|
145
|
-
*/
|
|
146
|
-
Eventer.prototype.doing = async function(o, ...msg) {
|
|
147
|
-
o.num++;
|
|
148
|
-
var ret;
|
|
149
|
-
try {
|
|
150
|
-
ret = o.func(...msg, o.param, o.num);
|
|
151
|
-
if (types.isPromise(ret)) {
|
|
152
|
-
ret = await ret;
|
|
153
|
-
}
|
|
154
|
-
if (this.mode > 4) {
|
|
155
|
-
o.exec('reload', o.filename);
|
|
156
|
-
}
|
|
157
|
-
} catch (err) {
|
|
158
|
-
$.log.error("事件器执行失败!", err);
|
|
159
|
-
}
|
|
160
|
-
if (o.num === o.count) {
|
|
161
|
-
this.list_del.push(o.id);
|
|
162
|
-
}
|
|
163
|
-
return ret;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* 运行事件
|
|
168
|
-
* @param {Array} list 列表
|
|
169
|
-
* @param {String} type 类型
|
|
170
|
-
* @param {Boolean} isBreak 是否中断
|
|
171
|
-
* @param {Object} msg 事件消息
|
|
172
|
-
*/
|
|
173
|
-
Eventer.prototype.run_sub = async function(list, isBreak, ...msg) {
|
|
174
|
-
var ret;
|
|
175
|
-
if (list) {
|
|
176
|
-
for (var i = 0; i < list.length; i++) {
|
|
177
|
-
var o = list[i];
|
|
178
|
-
// 判断是否启用状态
|
|
179
|
-
if (o.state == 1) {
|
|
180
|
-
// 判断是否还需要执行
|
|
181
|
-
if (o.count < 0 || o.num < o.count) {
|
|
182
|
-
ret = await this.doing(o, ...msg);
|
|
183
|
-
if (ret && isBreak) {
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
} else if (!o.state) {
|
|
188
|
-
this.list_del.push({
|
|
189
|
-
id: o.id,
|
|
190
|
-
type: o.type,
|
|
191
|
-
tense: o.tense
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return ret;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* 运行事件
|
|
201
|
-
* @param {String} type 类型
|
|
202
|
-
* @param {Object} msg 事件消息
|
|
203
|
-
*/
|
|
204
|
-
Eventer.prototype.run = async function(type, ...msg) {
|
|
205
|
-
this.do_before();
|
|
206
|
-
var ret;
|
|
207
|
-
var dt = this.dict[type];
|
|
208
|
-
if (dt) {
|
|
209
|
-
ret = await this.run_sub(dt.before, false, ...msg);
|
|
210
|
-
ret = await this.run_sub(dt.check, true, ...msg);
|
|
211
|
-
if (ret) {
|
|
212
|
-
return ret
|
|
213
|
-
}
|
|
214
|
-
ret = await this.run_sub(dt.main, false, ...msg);
|
|
215
|
-
if (ret) {
|
|
216
|
-
var ret_new = await this.run_sub(dt.after, false, ...msg);
|
|
217
|
-
ret = ret_new || ret;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
this.do_after();
|
|
221
|
-
return ret;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* 设置状态
|
|
226
|
-
* @param {Array} lt
|
|
227
|
-
* @param {Object} id
|
|
228
|
-
* @param {Object} state
|
|
229
|
-
*/
|
|
230
|
-
Eventer.prototype.setState_sub = function(lt, id, state) {
|
|
231
|
-
var obj;
|
|
232
|
-
if (lt) {
|
|
233
|
-
if (id) {
|
|
234
|
-
// 如果传入了ID,处理该ID事项
|
|
235
|
-
obj = lt.getObj({
|
|
236
|
-
id
|
|
237
|
-
});
|
|
238
|
-
if (obj) {
|
|
239
|
-
obj.state = state;
|
|
240
|
-
}
|
|
241
|
-
} else {
|
|
242
|
-
// 否则全部处理
|
|
243
|
-
for (var i = 0; i < lt.length; i++) {
|
|
244
|
-
var o = lt[i];
|
|
245
|
-
o.state = state;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
return obj;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* 设置事件状态
|
|
254
|
-
* @param {Number} id 类型
|
|
255
|
-
* @param {String} type 类型
|
|
256
|
-
* @param {String} tense 时态 before执行前|check确认是否执行|main执行|after执行后
|
|
257
|
-
* @param {Number} state 状态
|
|
258
|
-
*/
|
|
259
|
-
Eventer.prototype.setState = function(id, type, tense, state) {
|
|
260
|
-
if (type) {
|
|
261
|
-
// 如果传入了类型,处理该类事件
|
|
262
|
-
var dt = this.dict[type];
|
|
263
|
-
var obj;
|
|
264
|
-
if (dt) {
|
|
265
|
-
if (tense) {
|
|
266
|
-
// 如果传入了时态,处理该事件下该时态的事
|
|
267
|
-
obj = this.setState_sub(dt[tense], id, state);
|
|
268
|
-
} else {
|
|
269
|
-
obj = this.setState_sub(dt.before, id, state);
|
|
270
|
-
if (!obj) {
|
|
271
|
-
obj = this.setState_sub(dt.check, id, state);
|
|
272
|
-
if (!obj) {
|
|
273
|
-
obj = this.setState_sub(dt.main, id, state);
|
|
274
|
-
if (!obj) {
|
|
275
|
-
obj = this.setState_sub(dt.after, id, state);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
if (obj) {
|
|
282
|
-
obj.state = state;
|
|
283
|
-
} else {
|
|
284
|
-
if (id) {
|
|
285
|
-
obj = this.list_add.getObj({
|
|
286
|
-
id
|
|
287
|
-
});
|
|
288
|
-
if (obj) {
|
|
289
|
-
obj.state = state;
|
|
290
|
-
}
|
|
291
|
-
} else if (tense) {
|
|
292
|
-
var lt = this.list_add.get({
|
|
293
|
-
type,
|
|
294
|
-
tense
|
|
295
|
-
});
|
|
296
|
-
for (var i = 0; i < lt.length; i++) {
|
|
297
|
-
var o = lt[i];
|
|
298
|
-
o.state = state;
|
|
299
|
-
}
|
|
300
|
-
} else {
|
|
301
|
-
var lt = this.list_add.get({
|
|
302
|
-
type
|
|
303
|
-
});
|
|
304
|
-
for (var i = 0; i < lt.length; i++) {
|
|
305
|
-
var o = lt[i];
|
|
306
|
-
o.state = state;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
} else {
|
|
311
|
-
var obj;
|
|
312
|
-
for (var k in this.dict) {
|
|
313
|
-
var dt = this.dict[k];
|
|
314
|
-
if (dt) {
|
|
315
|
-
if (tense) {
|
|
316
|
-
obj = this.setState_sub(dt[tense], id, state);
|
|
317
|
-
} else {
|
|
318
|
-
obj = this.setState_sub(dt.before, id, state);
|
|
319
|
-
if (!obj) {
|
|
320
|
-
obj = this.setState_sub(dt.check, id, state);
|
|
321
|
-
if (!obj) {
|
|
322
|
-
obj = this.setState_sub(dt.main, id, state);
|
|
323
|
-
if (!obj) {
|
|
324
|
-
obj = this.setState_sub(dt.after, id, state);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
if (obj) {
|
|
330
|
-
break;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
if (!obj) {
|
|
335
|
-
if (id) {
|
|
336
|
-
obj = this.list_add.getObj({
|
|
337
|
-
id
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
if (obj) {
|
|
342
|
-
obj.state = state;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* 开启
|
|
349
|
-
* @param {Number|String} id 名称或ID
|
|
350
|
-
* @param {String} type 事件类型
|
|
351
|
-
* @param {String} tense 时态 before执行前|check确认是否执行|after执行后
|
|
352
|
-
*/
|
|
353
|
-
Eventer.prototype.start = function(id, type, tense) {
|
|
354
|
-
this.setState(id, type, tense, 1);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* 暂停
|
|
359
|
-
* @param {Number|String} id 名称或ID
|
|
360
|
-
* @param {String} type 事件类型
|
|
361
|
-
* @param {String} tense 时态 before执行前|check确认是否执行|after执行后
|
|
362
|
-
*/
|
|
363
|
-
Eventer.prototype.stop = function(id, type, tense) {
|
|
364
|
-
this.setState(id, type, tense, 2);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* 结束
|
|
369
|
-
* @param {Number|String} id 名称或ID
|
|
370
|
-
* @param {String} type 事件类型
|
|
371
|
-
* @param {String} tense 时态 before执行前|check确认是否执行|after执行后
|
|
372
|
-
*/
|
|
373
|
-
Eventer.prototype.end = function(id, type, tense) {
|
|
374
|
-
this.setState(id, type, tense, 0);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* 删除事件-子程序
|
|
379
|
-
* @param {Object} lt
|
|
380
|
-
*/
|
|
381
|
-
Eventer.prototype.del_sub = function(lt) {
|
|
382
|
-
if (lt) {
|
|
383
|
-
for (var i = 0; i < lt.length; i++) {
|
|
384
|
-
var o = lt[i];
|
|
385
|
-
this.list_del.push({
|
|
386
|
-
id: o.id,
|
|
387
|
-
type: o.type,
|
|
388
|
-
tense: o.tense
|
|
389
|
-
})
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
/**
|
|
395
|
-
* 删除事件
|
|
396
|
-
* @param {Number|String} id 名称或ID
|
|
397
|
-
* @param {String} type 事件类型
|
|
398
|
-
* @param {String} tense 时态 before执行前|check确认是否执行|after执行后
|
|
399
|
-
*/
|
|
400
|
-
Eventer.prototype.del = function(id, type, tense) {
|
|
401
|
-
if (type) {
|
|
402
|
-
if (id) {
|
|
403
|
-
if (tense) {
|
|
404
|
-
this.list_del.push({
|
|
405
|
-
id,
|
|
406
|
-
type,
|
|
407
|
-
tense
|
|
408
|
-
});
|
|
409
|
-
} else {
|
|
410
|
-
this.list_del.push({
|
|
411
|
-
id,
|
|
412
|
-
type,
|
|
413
|
-
tense: "before"
|
|
414
|
-
});
|
|
415
|
-
this.list_del.push({
|
|
416
|
-
id,
|
|
417
|
-
type,
|
|
418
|
-
tense: "check"
|
|
419
|
-
});
|
|
420
|
-
this.list_del.push({
|
|
421
|
-
id,
|
|
422
|
-
type,
|
|
423
|
-
tense: "main"
|
|
424
|
-
});
|
|
425
|
-
this.list_del.push({
|
|
426
|
-
id,
|
|
427
|
-
type,
|
|
428
|
-
tense: "after"
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
} else {
|
|
432
|
-
var dt = this.dict[type];
|
|
433
|
-
if (dt) {
|
|
434
|
-
if (tense) {
|
|
435
|
-
this.del_sub(dt[tense]);
|
|
436
|
-
} else {
|
|
437
|
-
this.del_sub(dt.before);
|
|
438
|
-
this.del_sub(dt.check);
|
|
439
|
-
this.del_sub(dt.main);
|
|
440
|
-
this.del_sub(dt.after);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
} else if (id) {
|
|
445
|
-
var obj;
|
|
446
|
-
for (var k in this.dict) {
|
|
447
|
-
var dt = this.dict[k];
|
|
448
|
-
if (dt) {
|
|
449
|
-
for (var t in dt) {
|
|
450
|
-
var lt = dt[t];
|
|
451
|
-
if (lt) {
|
|
452
|
-
obj = lt.getObj({
|
|
453
|
-
id
|
|
454
|
-
});
|
|
455
|
-
if (obj) {
|
|
456
|
-
break
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
if (!obj) {
|
|
463
|
-
obj = this.list_add.getObj({
|
|
464
|
-
id
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
if (obj) {
|
|
468
|
-
obj.state = 0;
|
|
469
|
-
this.list_del.push({
|
|
470
|
-
id: obj.id,
|
|
471
|
-
type: obj.type
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
module.exports = Eventer;
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
class Middleware {
|
|
2
|
-
/**
|
|
3
|
-
* 构造函数
|
|
4
|
-
* @param {Object} config 配置参数
|
|
5
|
-
*/
|
|
6
|
-
constructor(config) {
|
|
7
|
-
// 中间件列表
|
|
8
|
-
this.list = [];
|
|
9
|
-
|
|
10
|
-
this.config = {
|
|
11
|
-
path: "./middleware".fullname($.runPath),
|
|
12
|
-
file: "middleware.json",
|
|
13
|
-
mode: "web"
|
|
14
|
-
};
|
|
15
|
-
this.init(config);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
Middleware.prototype.init = function(config) {
|
|
20
|
-
if (config) {
|
|
21
|
-
Object.assign(this.config, config);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 新建脚本
|
|
27
|
-
* @param {String} 文件
|
|
28
|
-
*/
|
|
29
|
-
Middleware.prototype.new_script = function(file) {
|
|
30
|
-
var fl = __dirname + "/script.js";
|
|
31
|
-
if (fl.hasFile()) {
|
|
32
|
-
var text = fl.loadText();
|
|
33
|
-
if (text) {
|
|
34
|
-
var l = $.slash;
|
|
35
|
-
if (file.indexOf('middleware' + l) !== -1) {
|
|
36
|
-
var name = file.between('middleware' + l, l);
|
|
37
|
-
text = text.replaceAll("{0}", name);
|
|
38
|
-
}
|
|
39
|
-
file.saveText(text);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 新建配置
|
|
46
|
-
* @param {String} 文件
|
|
47
|
-
*/
|
|
48
|
-
Middleware.prototype.new_config = function(file) {
|
|
49
|
-
var fl = __dirname + "/config.tpl.json";
|
|
50
|
-
if (fl.hasFile()) {
|
|
51
|
-
var text = fl.loadText();
|
|
52
|
-
if (text) {
|
|
53
|
-
var l = $.slash;
|
|
54
|
-
if (file.indexOf('middleware' + l) !== -1) {
|
|
55
|
-
var name = file.between('middleware' + l, l);
|
|
56
|
-
text = text.replaceAll("{0}", name);
|
|
57
|
-
}
|
|
58
|
-
file.saveText(text);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 加载配置
|
|
65
|
-
* @param {String} file 配置文件路径
|
|
66
|
-
*/
|
|
67
|
-
Middleware.prototype.load_item = function(file) {
|
|
68
|
-
var config = file.loadJson();
|
|
69
|
-
if (config) {
|
|
70
|
-
var cg = this.list.getObj({
|
|
71
|
-
name: config.name
|
|
72
|
-
});
|
|
73
|
-
if (cg) {
|
|
74
|
-
$.push(cg, config, true);
|
|
75
|
-
} else {
|
|
76
|
-
cg = {
|
|
77
|
-
func_file: file.replace(this.config.file, 'index.js')
|
|
78
|
-
}
|
|
79
|
-
$.push(cg, config, true);
|
|
80
|
-
this.list.push(cg);
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
this.new_config(file);
|
|
84
|
-
}
|
|
85
|
-
var script_file = file.replace('middleware.json', 'index.js');
|
|
86
|
-
if (!script_file.hasFile()) {
|
|
87
|
-
this.new_script(script_file);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 遍历加载配置
|
|
93
|
-
* @param {Object} path
|
|
94
|
-
*/
|
|
95
|
-
Middleware.prototype.update_config_all = function(path, accurate) {
|
|
96
|
-
if (path.hasDir()) {
|
|
97
|
-
var dirs = $.dir.getAll(path);
|
|
98
|
-
// 遍历目录路径
|
|
99
|
-
var file = this.config.file;
|
|
100
|
-
for (var i = 0; i < dirs.length; i++) {
|
|
101
|
-
var d = dirs[i];
|
|
102
|
-
this.load_item(d + file);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* 排序
|
|
109
|
-
*/
|
|
110
|
-
Middleware.prototype.sort = function() {
|
|
111
|
-
return this.list.sortBy('asc', 'sort');
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* 清除接口缓存
|
|
116
|
-
*/
|
|
117
|
-
Middleware.prototype.clear = function() {
|
|
118
|
-
this.list = [];
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* 遍历加载配置
|
|
123
|
-
*/
|
|
124
|
-
Middleware.prototype.update_config = function(path, accurate = true, clear = true) {
|
|
125
|
-
if (clear) {
|
|
126
|
-
this.clear();
|
|
127
|
-
}
|
|
128
|
-
this.update_config_all("../../../middleware/".fullname(__dirname));
|
|
129
|
-
if (path) {
|
|
130
|
-
this.update_config_all(path);
|
|
131
|
-
}
|
|
132
|
-
this.update_config_all(this.config.path);
|
|
133
|
-
var p = "./middleware".fullname($.runPath);
|
|
134
|
-
if (this.config.path !== p) {
|
|
135
|
-
this.update_config_all(p);
|
|
136
|
-
}
|
|
137
|
-
this.sort();
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* 更新
|
|
142
|
-
* @param {String} dir 检索的路径
|
|
143
|
-
* @param {Boolean} loadJS 是否加载JS
|
|
144
|
-
*/
|
|
145
|
-
Middleware.prototype.update = function(dir, accurate = true, loadJS = true, clear = true) {
|
|
146
|
-
this.update_config(dir, accurate, clear);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (!$.middleware) {
|
|
150
|
-
$.middleware = new Middleware();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
module.exports = Middleware;
|
package/core/com/mqtt/com.json
DELETED