mm_os 4.3.7 → 5.0.1
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 +102 -504
- package/index.js +26 -19
- package/lib/os.js +536 -0
- package/package.json +60 -84
- package/LICENSE +0 -21
- package/README_EN.md +0 -505
- package/adapter/adapter.js +0 -484
- package/adapter/custom_persistence.js +0 -661
- package/adapter/mqtt.js +0 -254
- package/adapter/socket.js +0 -244
- package/adapter/web.js +0 -92
- package/adapter/websocket.js +0 -43
- package/ai.js +0 -130
- package/com/api/README.md +0 -3
- package/com/api/com.json +0 -5
- package/com/api/config.tpl.json +0 -41
- package/com/api/drive.js +0 -732
- package/com/api/index.js +0 -201
- package/com/api/oauth.js +0 -200
- package/com/api/script.tpl.js +0 -32
- package/com/cmd/README.md +0 -11
- package/com/cmd/com.json +0 -5
- package/com/cmd/config.tpl.json +0 -48
- package/com/cmd/drive.js +0 -176
- package/com/cmd/index.js +0 -287
- package/com/cmd/job/config.json +0 -66
- package/com/cmd/job/index.js +0 -241
- package/com/cmd/job/test.js +0 -188
- package/com/cmd/msg.json +0 -48
- package/com/cmd/script.tpl.js +0 -12
- package/com/db/README.md +0 -3
- package/com/db/com.json +0 -5
- package/com/db/drive.js +0 -2206
- package/com/db/index.js +0 -241
- package/com/event/README.md +0 -4
- package/com/event/com.json +0 -5
- package/com/event/config.tpl.json +0 -20
- package/com/event/drive.js +0 -61
- package/com/event/index.js +0 -438
- package/com/event/script.tpl.js +0 -23
- package/com/mqtt/README.md +0 -47
- package/com/mqtt/com.json +0 -5
- package/com/mqtt/config.tpl.json +0 -42
- package/com/mqtt/drive.js +0 -704
- package/com/mqtt/index.js +0 -1052
- package/com/mqtt/index.test.js +0 -503
- package/com/mqtt/script.tpl.js +0 -719
- package/com/nav/README.md +0 -2
- package/com/nav/com.json +0 -5
- package/com/nav/config.tpl.json +0 -84
- package/com/nav/drive.js +0 -702
- package/com/nav/index.js +0 -228
- package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
- package/com/nav/tpl/admin_pc/page_config.vue +0 -280
- package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
- package/com/nav/tpl/admin_pc/page_default.vue +0 -247
- package/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
- package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
- package/com/nav/tpl/admin_pc/page_table.vue +0 -296
- package/com/nav/tpl/admin_pc/page_type.vue +0 -321
- package/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
- package/com/nav/tpl/dev_pc/page_config.vue +0 -253
- package/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/com/nav/tpl/dev_pc/page_form.vue +0 -162
- package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
- package/com/nav/tpl/dev_pc/page_table.vue +0 -247
- package/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/com/nav/tpl/home_pc/page_channel.vue +0 -234
- package/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/com/nav/tpl/home_phone/page_list.vue +0 -234
- package/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/com/nav/viewmodel.js +0 -446
- package/com/param/README.md +0 -2
- package/com/param/com.json +0 -5
- package/com/param/config.tpl.json +0 -136
- package/com/param/drive.js +0 -502
- package/com/param/index.js +0 -158
- package/com/param/script.tpl.js +0 -12
- package/com/pendant/README.md +0 -3
- package/com/pendant/com.json +0 -5
- package/com/pendant/config.tpl.json +0 -32
- package/com/pendant/drive.js +0 -204
- package/com/pendant/index.js +0 -467
- package/com/pendant/pendant.html +0 -16
- package/com/pendant/script.tpl.js +0 -18
- package/com/socket/README.md +0 -47
- package/com/socket/com.json +0 -5
- package/com/socket/config.tpl.json +0 -12
- package/com/socket/drive.js +0 -679
- package/com/socket/index.js +0 -402
- package/com/socket/script.tpl.js +0 -41
- package/com/sql/README.md +0 -3
- package/com/sql/com.json +0 -5
- package/com/sql/config.tpl.json +0 -74
- package/com/sql/drive.js +0 -1328
- package/com/sql/index.js +0 -152
- package/com/sql/script.tpl.js +0 -47
- package/com/static/README.md +0 -2
- package/com/static/com.json +0 -5
- package/com/static/config.tpl.json +0 -24
- package/com/static/drive.js +0 -194
- package/com/static/index.js +0 -237
- package/com/static/script.tpl.js +0 -28
- package/com/task/README.md +0 -3
- package/com/task/com.json +0 -5
- package/com/task/config.tpl.json +0 -24
- package/com/task/drive.js +0 -428
- package/com/task/index.js +0 -159
- package/com/task/script.tpl.js +0 -40
- package/com/template/com.json +0 -5
- package/com/template/config.tpl.json +0 -16
- package/com/template/drive.js +0 -81
- package/com/template/index.js +0 -141
- package/com.js +0 -237
- package/common/README.md +0 -2
- package/common/middleware/web_after/index.js +0 -26
- package/common/middleware/web_after/middleware.json +0 -9
- package/common/middleware/web_base/index.js +0 -113
- package/common/middleware/web_base/middleware.json +0 -19
- package/common/middleware/web_before/index.js +0 -33
- package/common/middleware/web_before/middleware.json +0 -9
- package/common/middleware/web_cors/index.js +0 -87
- package/common/middleware/web_cors/middleware.json +0 -24
- package/common/middleware/web_error/index.js +0 -131
- package/common/middleware/web_error/middleware.json +0 -19
- package/common/middleware/web_ip/index.js +0 -15
- package/common/middleware/web_ip/middleware.json +0 -14
- package/common/middleware/web_logger/index.js +0 -156
- package/common/middleware/web_logger/middleware.json +0 -14
- package/common/middleware/web_main/index.js +0 -26
- package/common/middleware/web_main/middleware.json +0 -9
- package/common/middleware/web_static/index.js +0 -73
- package/common/middleware/web_static/middleware.json +0 -54
- package/common/middleware/web_waf/index.js +0 -395
- package/common/middleware/web_waf/middleware.json +0 -13
- package/core/app/config.tpl.json +0 -67
- package/core/app/index.js +0 -711
- package/core/app/script.tpl.js +0 -52
- package/core/channel/index.js +0 -899
- package/core/channel/matcher.js +0 -585
- package/core/com/config.tpl.json +0 -16
- package/core/com/index.js +0 -77
- package/core/com/script.tpl.js +0 -5
- package/core/component/component.js +0 -42
- package/core/component/config.tpl.json +0 -63
- package/core/component/index.js +0 -273
- package/core/component/script.tpl.js +0 -19
- package/core/controller/config.tpl.json +0 -14
- package/core/controller/index.js +0 -371
- package/core/controller/script.tpl.js +0 -27
- package/core/factory/config.tpl.json +0 -14
- package/core/factory/entity.js +0 -275
- package/core/factory/index.js +0 -241
- package/core/factory/script.tpl.js +0 -16
- package/core/game/bat/index.js +0 -137
- package/core/game/bat/world.js +0 -622
- package/core/game/config.tpl.json +0 -16
- package/core/game/entity_admin.js +0 -230
- package/core/game/index.js +0 -186
- package/core/handler/config.tpl.json +0 -22
- package/core/handler/index.js +0 -181
- package/core/handler/script.tpl.js +0 -23
- package/core/logic/config.tpl.json +0 -14
- package/core/logic/index.js +0 -59
- package/core/logic/script.tpl.js +0 -19
- package/core/middleware/config.tpl.json +0 -16
- package/core/middleware/index.js +0 -117
- package/core/middleware/script.tpl.js +0 -37
- package/core/mod/config.tpl.json +0 -22
- package/core/mod/index.js +0 -136
- package/core/mod/script.tpl.js +0 -34
- package/core/model/config.tpl.json +0 -219
- package/core/model/index.js +0 -272
- package/core/model/model.js +0 -27
- package/core/model/script.tpl.js +0 -20
- package/core/notifier/config.tpl.json +0 -14
- package/core/notifier/index.js +0 -77
- package/core/notifier/script.tpl.js +0 -20
- package/core/plugin/config.tpl.json +0 -36
- package/core/plugin/index.js +0 -267
- package/core/plugin/script.tpl.js +0 -51
- package/core/pusher/config.tpl.json +0 -14
- package/core/pusher/index.js +0 -158
- package/core/pusher/script.tpl.js +0 -20
- package/core/room/bat/index.js +0 -170
- package/core/room/bat/room.js +0 -524
- package/core/room/config.tpl.json +0 -20
- package/core/room/index.js +0 -249
- package/core/room/room.js +0 -61
- package/core/scene/config.tpl.json +0 -14
- package/core/scene/index.js +0 -467
- package/core/scene/loop.js +0 -1306
- package/core/scene/map.js +0 -28
- package/core/scene/script.tpl.js +0 -22
- package/core/sender/config.tpl.json +0 -14
- package/core/sender/index.js +0 -79
- package/core/sender/script.tpl.js +0 -20
- package/core/service/config.tpl.json +0 -14
- package/core/service/index.js +0 -100
- package/core/service/script.tpl.js +0 -25
- package/core/store/config.tpl.json +0 -26
- package/core/store/index.js +0 -1794
- package/core/store/script.tpl.js +0 -22
- package/core/system/config.tpl.json +0 -18
- package/core/system/index.js +0 -312
- package/core/system/script.tpl.js +0 -77
- package/core/view/config.tpl.json +0 -14
- package/core/view/index.js +0 -91
- package/core/view/script.tpl.js +0 -20
- package/core/zone/bat/index.js +0 -744
- package/core/zone/config.tpl.json +0 -54
- package/core/zone/index.js +0 -655
- package/core/zone/script.tpl.js +0 -10
- package/core/zone/zone_bat.js +0 -136
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
- package/os.js +0 -53
- package/server.js +0 -602
- package/ulits/id_gen.js +0 -134
- package/ulits/word.js +0 -206
package/com/event/index.js
DELETED
|
@@ -1,438 +0,0 @@
|
|
|
1
|
-
const Manager = require("mm_machine").Manager;
|
|
2
|
-
const Drive = require("./drive");
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Event事件类
|
|
6
|
-
* @augments {Manager}
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class Event extends Manager {
|
|
10
|
-
/**
|
|
11
|
-
* 配置参数
|
|
12
|
-
* @type {object}
|
|
13
|
-
*/
|
|
14
|
-
static config = {
|
|
15
|
-
/**
|
|
16
|
-
* 名称
|
|
17
|
-
* @type {string}
|
|
18
|
-
*/
|
|
19
|
-
name: "",
|
|
20
|
-
/**
|
|
21
|
-
* 标题
|
|
22
|
-
* @type {string}
|
|
23
|
-
*/
|
|
24
|
-
title: "事件管理",
|
|
25
|
-
/**
|
|
26
|
-
* 描述
|
|
27
|
-
* @type {string}
|
|
28
|
-
*/
|
|
29
|
-
description: "这是事件管理器",
|
|
30
|
-
/**
|
|
31
|
-
* 检索文件名
|
|
32
|
-
* @type {string}
|
|
33
|
-
*/
|
|
34
|
-
filename: "event.json",
|
|
35
|
-
/**
|
|
36
|
-
* 模板目录
|
|
37
|
-
* @type {string}
|
|
38
|
-
*/
|
|
39
|
-
tpl_dir: __dirname,
|
|
40
|
-
/**
|
|
41
|
-
* 基础目录
|
|
42
|
-
* @type {string}
|
|
43
|
-
*/
|
|
44
|
-
base_dir: "../common/event".fullname(__dirname),
|
|
45
|
-
/**
|
|
46
|
-
* 自定义目录,加载项目自定义资源
|
|
47
|
-
* @type {string}
|
|
48
|
-
*/
|
|
49
|
-
dir: "./app".fullname(),
|
|
50
|
-
/**
|
|
51
|
-
* 搜索模式 dir按目录搜索 | file按文件名搜索
|
|
52
|
-
* @type {string}
|
|
53
|
-
*/
|
|
54
|
-
search_way: "dir",
|
|
55
|
-
/**
|
|
56
|
-
* 是否懒加载
|
|
57
|
-
* @type {boolean}
|
|
58
|
-
*/
|
|
59
|
-
lazy_load: true,
|
|
60
|
-
/**
|
|
61
|
-
* 模式
|
|
62
|
-
* 1.生产模式,改变文件不会重新加载
|
|
63
|
-
* 2.热更新模式,改变配置文件会重新加载配置,不重新加载脚本
|
|
64
|
-
* 3.热重载模式,改变配置文件都会加载配置和脚本
|
|
65
|
-
* 4.重载模式,执行完后重新加载脚本,避免变量污染
|
|
66
|
-
* 5.热更新+重载模式,改变配置文件重新加载配置和脚本,执行完后重新加载脚本
|
|
67
|
-
* @type {number}
|
|
68
|
-
*/
|
|
69
|
-
mode: process.env.NODE_ENV === "production" ? 1 : 3,
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* 构造函数
|
|
74
|
-
* @param {object} config 配置参数
|
|
75
|
-
* @param {object} parent 父级模块
|
|
76
|
-
*/
|
|
77
|
-
constructor(config, parent) {
|
|
78
|
-
super({ ...Event.config, ...config }, parent);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 预设事件
|
|
84
|
-
*/
|
|
85
|
-
Event.prototype._preset = function () {
|
|
86
|
-
// 验证前
|
|
87
|
-
this.list_before = [];
|
|
88
|
-
// 验证
|
|
89
|
-
this.list_check = [];
|
|
90
|
-
// 执行
|
|
91
|
-
this.list_main = [];
|
|
92
|
-
// 渲染
|
|
93
|
-
this.list_render = [];
|
|
94
|
-
// 渲染后
|
|
95
|
-
this.list_after = [];
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* 事件驱动类
|
|
100
|
-
* @type {Drive}
|
|
101
|
-
*/
|
|
102
|
-
Event.prototype.Drive = Drive;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* 更新配置,注册模块后重建事件列表
|
|
106
|
-
* @param {string} dir 检索路径
|
|
107
|
-
* @param {boolean} clear 是否清除缓存
|
|
108
|
-
*/
|
|
109
|
-
Event.prototype.update = async function (dir, clear = true) {
|
|
110
|
-
try {
|
|
111
|
-
if (clear) {
|
|
112
|
-
this.clearMods();
|
|
113
|
-
}
|
|
114
|
-
var search_dir = dir || this.config.dir;
|
|
115
|
-
var files = await this._findFiles(search_dir);
|
|
116
|
-
this.regMods(files);
|
|
117
|
-
this.updateInfo();
|
|
118
|
-
if (!this.config.lazy_load) {
|
|
119
|
-
await this.loadMods();
|
|
120
|
-
}
|
|
121
|
-
this._is_loaded = true;
|
|
122
|
-
} catch (err) {
|
|
123
|
-
this.log("error", "更新配置失败", err);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* 清除事件
|
|
129
|
-
* @param {string} stage 阶段
|
|
130
|
-
*/
|
|
131
|
-
Event.prototype.clear = function (stage) {
|
|
132
|
-
if (stage) {
|
|
133
|
-
if (this["list_" + stage]) {
|
|
134
|
-
this["list_" + stage] = [];
|
|
135
|
-
} else {
|
|
136
|
-
this.log(
|
|
137
|
-
"debug",
|
|
138
|
-
"清空失败,事件发展阶段{0}不存在!".replace("{0}", stage),
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
} else {
|
|
142
|
-
this.list_before = [];
|
|
143
|
-
this.list_check = [];
|
|
144
|
-
this.list_main = [];
|
|
145
|
-
this.list_render = [];
|
|
146
|
-
this.list_after = [];
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* 更新模块信息
|
|
152
|
-
*/
|
|
153
|
-
Event.prototype.updateInfo = function () {
|
|
154
|
-
this._preset();
|
|
155
|
-
this.infos = [];
|
|
156
|
-
for (let name in this.mods) {
|
|
157
|
-
let o = this.mods[name];
|
|
158
|
-
let info = {
|
|
159
|
-
name: o.config.name,
|
|
160
|
-
sort: o.config.sort,
|
|
161
|
-
state: o.config.state,
|
|
162
|
-
config_file: o.config_file,
|
|
163
|
-
};
|
|
164
|
-
this.infos.push(info);
|
|
165
|
-
this.pushList(o.config.stage, info);
|
|
166
|
-
}
|
|
167
|
-
this._sort();
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 推送事件信息
|
|
172
|
-
* @param {string} stage 阶段
|
|
173
|
-
* @param {object} info 事件信息
|
|
174
|
-
*/
|
|
175
|
-
Event.prototype.pushList = function (stage, info) {
|
|
176
|
-
switch (stage) {
|
|
177
|
-
case "before":
|
|
178
|
-
this.list_before.push(info);
|
|
179
|
-
break;
|
|
180
|
-
case "check":
|
|
181
|
-
this.list_check.push(info);
|
|
182
|
-
break;
|
|
183
|
-
case "main":
|
|
184
|
-
this.list_main.push(info);
|
|
185
|
-
break;
|
|
186
|
-
case "render":
|
|
187
|
-
this.list_render.push(info);
|
|
188
|
-
break;
|
|
189
|
-
case "after":
|
|
190
|
-
this.list_after.push(info);
|
|
191
|
-
break;
|
|
192
|
-
default:
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* 事件排序
|
|
199
|
-
*/
|
|
200
|
-
Event.prototype._sort = function () {
|
|
201
|
-
this._sortSub(this.list_before);
|
|
202
|
-
this._sortSub(this.list_check);
|
|
203
|
-
this._sortSub(this.list_main);
|
|
204
|
-
this._sortSub(this.list_render);
|
|
205
|
-
this._sortSub(this.list_after);
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* 事件排序
|
|
210
|
-
* @param {Array} list 列表
|
|
211
|
-
*/
|
|
212
|
-
Event.prototype._sortSub = function (list) {
|
|
213
|
-
var sort_key = this.config.sort_key || "sort";
|
|
214
|
-
list.sort((o1, o2) => {
|
|
215
|
-
let s1 = o1[sort_key] || 100;
|
|
216
|
-
let s2 = o2[sort_key] || 100;
|
|
217
|
-
var cha = s1 - s2;
|
|
218
|
-
if (cha === 0) {
|
|
219
|
-
let mod1 = this.getMod(o1.name);
|
|
220
|
-
let mod2 = this.getMod(o2.name);
|
|
221
|
-
if (mod1 && mod2) {
|
|
222
|
-
cha = mod2.config.target.length - mod1.config.target.length;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return cha;
|
|
226
|
-
});
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* 执行事件
|
|
231
|
-
* @param {object} mod 模块
|
|
232
|
-
* @param {object} ctx 请求上下文
|
|
233
|
-
* @param {object} db 数据管理器
|
|
234
|
-
* @returns {object} 执行结果
|
|
235
|
-
*/
|
|
236
|
-
Event.prototype.doing = async function (mod, ctx, db) {
|
|
237
|
-
if (!mod.isLoaded()) {
|
|
238
|
-
await mod.do("load");
|
|
239
|
-
}
|
|
240
|
-
var ret = await mod.run(ctx, db);
|
|
241
|
-
if (this.mode > 4) {
|
|
242
|
-
mod.do("reload");
|
|
243
|
-
}
|
|
244
|
-
return ret;
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* 匹配目标
|
|
249
|
-
* @param {string} str 目标
|
|
250
|
-
* @param {string} pattern 模式
|
|
251
|
-
* @returns {boolean} 是否匹配
|
|
252
|
-
*/
|
|
253
|
-
Event.prototype.isMatch = function (str, pattern) {
|
|
254
|
-
if (str === pattern) {
|
|
255
|
-
return true;
|
|
256
|
-
} else if (pattern.startsWith("*")) {
|
|
257
|
-
let clean = pattern.replaceAll("*", "");
|
|
258
|
-
if (pattern.endsWith("*")) {
|
|
259
|
-
return str.indexOf(clean) !== -1;
|
|
260
|
-
} else {
|
|
261
|
-
return str.endsWith(clean);
|
|
262
|
-
}
|
|
263
|
-
} else if (pattern.endsWith("*")) {
|
|
264
|
-
let clean = pattern.replaceAll("*", "");
|
|
265
|
-
return str.startsWith(clean);
|
|
266
|
-
} else {
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* 执行函数
|
|
273
|
-
* @param {Array} list 列表
|
|
274
|
-
* @param {string} target 目标
|
|
275
|
-
* @param {object} ctx 请求上下文
|
|
276
|
-
* @param {object} db 数据管理器
|
|
277
|
-
* @returns {object} 执行结果
|
|
278
|
-
*/
|
|
279
|
-
Event.prototype.runSub = async function (list, target, ctx, db) {
|
|
280
|
-
for (var i = 0, info; (info = list[i++]);) {
|
|
281
|
-
if (info.state === 1) {
|
|
282
|
-
let mod = this.getMod(info.name);
|
|
283
|
-
if (mod && this.isMatch(target, mod.config.target)) {
|
|
284
|
-
try {
|
|
285
|
-
let ret = await this.doing(mod, ctx, db);
|
|
286
|
-
if (ret) {
|
|
287
|
-
db.ret = ret;
|
|
288
|
-
if (mod.config.end) {
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
} catch (error) {
|
|
293
|
-
// 事件执行异常时继续执行下一个事件
|
|
294
|
-
this.log("error", `事件${info.name}执行失败`, error);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return db.ret;
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* 之前
|
|
304
|
-
* @param {string} target 目标
|
|
305
|
-
* @param {object} ctx 请求上下文
|
|
306
|
-
* @param {object} db 数据管理器
|
|
307
|
-
* @returns {object} 执行结果
|
|
308
|
-
*/
|
|
309
|
-
Event.prototype.before = async function (target, ctx, db) {
|
|
310
|
-
return await this.runSub(this.list_before, target, ctx, db);
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* 验证
|
|
315
|
-
* @param {string} target 目标
|
|
316
|
-
* @param {object} ctx 请求上下文
|
|
317
|
-
* @param {object} db 数据管理器
|
|
318
|
-
* @returns {object} 执行结果
|
|
319
|
-
*/
|
|
320
|
-
Event.prototype.check = async function (target, ctx, db) {
|
|
321
|
-
return await this.runSub(this.list_check, target, ctx, db);
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* 主要
|
|
326
|
-
* @param {string} target 目标
|
|
327
|
-
* @param {object} ctx 请求上下文
|
|
328
|
-
* @param {object} db 数据管理器
|
|
329
|
-
* @returns {object} 执行结果
|
|
330
|
-
*/
|
|
331
|
-
Event.prototype.main = async function (target, ctx, db) {
|
|
332
|
-
return await this.runSub(this.list_main, target, ctx, db);
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* 渲染
|
|
337
|
-
* @param {string} target 目标
|
|
338
|
-
* @param {object} ctx 请求上下文
|
|
339
|
-
* @param {object} db 数据管理器
|
|
340
|
-
* @returns {object} 执行结果
|
|
341
|
-
*/
|
|
342
|
-
Event.prototype.render = async function (target, ctx, db) {
|
|
343
|
-
return await this.runSub(this.list_render, target, ctx, db);
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* 之后
|
|
348
|
-
* @param {string} target 目标
|
|
349
|
-
* @param {object} ctx 请求上下文
|
|
350
|
-
* @param {object} db 数据管理器
|
|
351
|
-
* @returns {object} 执行结果
|
|
352
|
-
*/
|
|
353
|
-
Event.prototype.after = async function (target, ctx, db) {
|
|
354
|
-
return await this.runSub(this.list_after, target, ctx, db);
|
|
355
|
-
};
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* 执行事件
|
|
359
|
-
* @param {string} target 目标
|
|
360
|
-
* @param {object} ctx 请求上下文
|
|
361
|
-
* @param {object} db 数据管理器
|
|
362
|
-
* @returns {object} 执行结果
|
|
363
|
-
*/
|
|
364
|
-
Event.prototype.run = async function (target, ctx, db = {}) {
|
|
365
|
-
var ret = await this.before(target, ctx, db);
|
|
366
|
-
if (!ret) {
|
|
367
|
-
ret = await this.check(target, ctx, db);
|
|
368
|
-
if (!ret) {
|
|
369
|
-
ret = await this.main(target, ctx, db);
|
|
370
|
-
}
|
|
371
|
-
ret = await this.render(target, ctx, db);
|
|
372
|
-
if (ret) {
|
|
373
|
-
ret = await this.after(target, ctx, db);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return ret;
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* 获取事件
|
|
381
|
-
* @param {string} name 名称
|
|
382
|
-
* @param {string} stage 阶段
|
|
383
|
-
* @returns {object} 返回单项配置
|
|
384
|
-
*/
|
|
385
|
-
Event.prototype.get = function (name, stage = "main") {
|
|
386
|
-
var obj;
|
|
387
|
-
var lt = this["list_" + stage];
|
|
388
|
-
var len = lt.length;
|
|
389
|
-
for (var i = 0; i < len; i++) {
|
|
390
|
-
var o = lt[i];
|
|
391
|
-
if (name === o.config.name) {
|
|
392
|
-
obj = o;
|
|
393
|
-
break;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return obj;
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* @module 导出Event类
|
|
401
|
-
*/
|
|
402
|
-
exports.Event = Event;
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Event事件池
|
|
406
|
-
*/
|
|
407
|
-
if (!$.pool.event) {
|
|
408
|
-
$.pool.event = {};
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Event事件池
|
|
413
|
-
* @param {string} scope 作用域
|
|
414
|
-
* @param {string} title 标题
|
|
415
|
-
* @returns {object} 返回一个事件类
|
|
416
|
-
*/
|
|
417
|
-
function eventAdmin(scope, title) {
|
|
418
|
-
var sc = scope || $.val.scope + "";
|
|
419
|
-
var obj = $.pool.event[sc];
|
|
420
|
-
if (!obj) {
|
|
421
|
-
$.pool.event[sc] = new Event({
|
|
422
|
-
name: sc,
|
|
423
|
-
title: title,
|
|
424
|
-
});
|
|
425
|
-
obj = $.pool.event[sc];
|
|
426
|
-
}
|
|
427
|
-
return obj;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Event管理器,用于创建缓存
|
|
432
|
-
* @param {string} scope 作用域
|
|
433
|
-
* @param {string} title 标题
|
|
434
|
-
* @returns {object} 返回一个缓存类
|
|
435
|
-
*/
|
|
436
|
-
if ($.admin) {
|
|
437
|
-
$.admin.event = eventAdmin;
|
|
438
|
-
}
|
package/com/event/script.tpl.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
exports = {
|
|
2
|
-
async init(options) {
|
|
3
|
-
// 使用api管理器
|
|
4
|
-
var api = $.admin.api('${name}_api', '${title}客户端');
|
|
5
|
-
// 首次启动更新api接口;
|
|
6
|
-
await api.call('update', 'app/');
|
|
7
|
-
},
|
|
8
|
-
/**
|
|
9
|
-
* 接口主函数
|
|
10
|
-
* @param {object} ctx HTTP上下文
|
|
11
|
-
* @param {object} db 数据管理器,如: { next: async function{}, ret: {} }
|
|
12
|
-
* @returns {object} 执行结果
|
|
13
|
-
*/
|
|
14
|
-
async main(ctx, db) {
|
|
15
|
-
var sql = $.admin.sql('sys');
|
|
16
|
-
// 使用模板引擎
|
|
17
|
-
db.tpl = new $.Tpl();
|
|
18
|
-
|
|
19
|
-
// 在这定义要访问的数据库 (分布式开发时设置不同的数据库名)
|
|
20
|
-
$.push(db, sql.db(), true);
|
|
21
|
-
return api.run(ctx, db);
|
|
22
|
-
}
|
|
23
|
-
};
|
package/com/mqtt/README.md
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# websocket 开发说明
|
|
2
|
-
|
|
3
|
-
## 简介
|
|
4
|
-
Websocket 是用于与浏览器客户端实现双向通讯的协议,可用来实现即时通讯、交易所、消息推送等。
|
|
5
|
-
|
|
6
|
-
## 关于mm websocket的使用
|
|
7
|
-
前端和服务端均已集成webstock功能,前端使用mm_sdk,后端使用com/websocket框架机制
|
|
8
|
-
|
|
9
|
-
## websocket 使用规范
|
|
10
|
-
为了让前后端通讯更加稳定、可控,前后端均采用json-rpc2.0的方式进行通讯,采用以下传参规范 ↓
|
|
11
|
-
|
|
12
|
-
在客户端给服务端发送消息时,或在服务端给客户端发送消息时(响应格式):
|
|
13
|
-
`
|
|
14
|
-
{
|
|
15
|
-
// 消息ID (用于识别对应请求)
|
|
16
|
-
id: "",
|
|
17
|
-
// 调用方法 (例如聊天时为chat、请求获取联系人时为get_contact)
|
|
18
|
-
method: "",
|
|
19
|
-
// 请求参数
|
|
20
|
-
params: {}
|
|
21
|
-
}
|
|
22
|
-
`
|
|
23
|
-
|
|
24
|
-
如果需要在某一端接收到消息后,告诉对方已收到消息或返回内容,可以给对方端推送一条消息(响应格式):
|
|
25
|
-
`
|
|
26
|
-
{
|
|
27
|
-
// 消息ID (用于响应对应请求)
|
|
28
|
-
id: "",
|
|
29
|
-
// 错误提示 (错误时必须返回)
|
|
30
|
-
error: {
|
|
31
|
-
// 错误码
|
|
32
|
-
code: -32602,
|
|
33
|
-
// 错误提示
|
|
34
|
-
message: ""
|
|
35
|
-
},
|
|
36
|
-
// 响应结果 (成功时必须返回)
|
|
37
|
-
result: {}
|
|
38
|
-
}
|
|
39
|
-
`
|
|
40
|
-
|
|
41
|
-
## mm websocket 通讯json-rpc2.0协议原理
|
|
42
|
-
1. 首先websocket给客户端和服务端提供了一个接收消息的接口,可以收到来自对方的消息
|
|
43
|
-
2. 然后双方可以通过收到的json数据中是否含有method属性来判断对方端是请求查询,还是提交数据
|
|
44
|
-
3. 如果是提交数据,则接收数据处理并存储
|
|
45
|
-
4. 如果是请求查询,则给请求做处理,并回推送一条消息
|
|
46
|
-
5. 为了能够识别消息是否成功推送,通过响应格式中的ID属性来判断
|
|
47
|
-
6. 如果非请求或响应, 只是单向推送数据, 那么可以通过id属性值0或空进行识别
|
package/com/mqtt/com.json
DELETED
package/com/mqtt/config.tpl.json
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
|
|
3
|
-
"name": "${name || 'mqtt'}",
|
|
4
|
-
// mqtt 服务标题
|
|
5
|
-
"title": "${title || '示例mqtt服务'}",
|
|
6
|
-
// mqtt 服务介绍
|
|
7
|
-
"description": "${description || '描述mqtt服务使用方法'}",
|
|
8
|
-
// 状态 0未启用,1启用
|
|
9
|
-
"state": 1,
|
|
10
|
-
// 订阅的主题 {产品类型}/{设备ID}/{数据类型}/{子类型}
|
|
11
|
-
// 接收设备状态、事件、命令回复、设备请求
|
|
12
|
-
"topic": [
|
|
13
|
-
"face/+/status",
|
|
14
|
-
"face/+/event/recognition",
|
|
15
|
-
"face/+/cmd/+/response",
|
|
16
|
-
"face/+/request/+"
|
|
17
|
-
],
|
|
18
|
-
// 回复订阅主题
|
|
19
|
-
"topic_receive": [
|
|
20
|
-
"face/${clientid}/response/${method}"
|
|
21
|
-
],
|
|
22
|
-
// 给客户端推送的主题
|
|
23
|
-
"topic_push": "face/${clientid}/cmd/${method}",
|
|
24
|
-
// 接收方式
|
|
25
|
-
"qos": 2,
|
|
26
|
-
// 保持接收
|
|
27
|
-
"retain": true,
|
|
28
|
-
// 超时反馈
|
|
29
|
-
"longtime": 60000,
|
|
30
|
-
// 客户端ID
|
|
31
|
-
"clientid": "clientid",
|
|
32
|
-
// 消息ID
|
|
33
|
-
"msgid": "msgid",
|
|
34
|
-
// 请求方法
|
|
35
|
-
"method": "method",
|
|
36
|
-
// 参数
|
|
37
|
-
"params": "params",
|
|
38
|
-
// 结果
|
|
39
|
-
"result": "result",
|
|
40
|
-
// 回复方法
|
|
41
|
-
"method_receive": "${method}_ask"
|
|
42
|
-
}
|