mm_os 4.2.6 → 4.2.8
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 +1 -1
- package/README_EN.md +2 -2
- package/adapter/adapter.js +105 -52
- package/adapter/custom_persistence.js +32 -31
- package/adapter/mqtt.js +59 -79
- package/adapter/socket.js +188 -58
- package/adapter/web.js +92 -68
- package/adapter/websocket.js +43 -146
- package/com/api/drive.js +732 -708
- package/com/api/index.js +196 -198
- package/com/cmd/config.tpl.json +48 -122
- package/com/cmd/drive.js +176 -1548
- package/com/cmd/index.js +287 -1066
- package/com/cmd/job/config.json +66 -0
- package/com/cmd/job/index.js +241 -0
- package/com/cmd/job/test.js +188 -0
- package/com/cmd/script.tpl.js +12 -33
- package/com/db/drive.js +2206 -2019
- package/com/db/index.js +241 -242
- package/com/event/config.tpl.json +3 -1
- package/com/event/drive.js +3 -1
- package/com/event/index.js +73 -49
- package/com/event/script.tpl.js +1 -1
- package/com/mqtt/config.tpl.json +16 -8
- package/com/mqtt/drive.js +696 -676
- package/com/mqtt/index.js +1012 -822
- package/com/mqtt/index.test.js +503 -0
- package/com/mqtt/mm_mqtt.js +446 -420
- package/com/mqtt/script.tpl.js +3 -7
- package/com/nav/drive.js +7 -7
- package/com/nav/index.js +228 -231
- package/com/param/index.js +19 -17
- package/com/pendant/index.js +467 -441
- package/com/socket/drive.js +679 -616
- package/com/socket/index.js +94 -48
- package/com/sql/drive.js +1283 -1259
- package/com/sql/index.js +152 -150
- package/com/static/drive.js +1 -1
- package/com/static/index.js +232 -226
- package/com/task/drive.js +428 -405
- package/com/task/index.js +154 -148
- package/com/template/drive.js +1 -1
- package/com/template/index.js +141 -138
- package/com.js +87 -6
- package/common/middleware/web_after/index.js +4 -10
- package/common/middleware/web_base/index.js +1 -1
- package/common/middleware/web_cors/index.js +1 -1
- package/common/middleware/web_error/index.js +131 -119
- package/common/middleware/web_error/middleware.json +2 -1
- package/common/middleware/web_logger/index.js +1 -1
- package/common/middleware/web_main/index.js +2 -0
- package/common/middleware/web_static/index.js +2 -2
- package/common/middleware/web_waf/index.js +1 -1
- package/core/app/config.tpl.json +4 -4
- package/core/app/index.js +710 -534
- package/core/middleware/index.js +1 -9
- package/core/mod/config.tpl.json +1 -1
- package/core/model/config.tpl.json +1 -1
- package/core/plugin/config.tpl.json +15 -3
- package/core/plugin/index.js +31 -0
- package/core/pusher/index.js +158 -161
- package/core/scene/loop.js +1306 -1255
- package/core/store/index.js +1794 -1755
- package/core/store/sql.js +1488 -1464
- package/core/zone/bat/index.js +744 -728
- package/core/zone/config.tpl.json +3 -3
- package/core/zone/index.js +655 -616
- package/os.js +0 -4
- package/package.json +16 -16
- package/server.js +583 -427
- package/com/cmd/nlp.js +0 -525
- package/core/app/index copy.js +0 -611
- package/software.js +0 -194
- package/tcp.js +0 -279
package/core/middleware/index.js
CHANGED
|
@@ -64,15 +64,7 @@ Middleware.prototype._initCore = async function (adapter, eventer, logger) {
|
|
|
64
64
|
*/
|
|
65
65
|
Middleware.prototype._register = async function () {
|
|
66
66
|
// 注册中间件到Koa应用
|
|
67
|
-
this.getAdapter().use(this.create());
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 注册中间件
|
|
72
|
-
* @returns {Promise<void>}
|
|
73
|
-
*/
|
|
74
|
-
Middleware.prototype.register = async function () {
|
|
75
|
-
await this._register();
|
|
67
|
+
this.getAdapter().web.use(this.create());
|
|
76
68
|
};
|
|
77
69
|
|
|
78
70
|
/**
|
package/core/mod/config.tpl.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"version": "${version || '1.0.0'}",
|
|
10
10
|
// 作者
|
|
11
11
|
"author": "${author || '(匿名)'}",
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
// 用于什么应用
|
|
13
|
+
"app": "${app || 'sys'}",
|
|
14
14
|
// 主文件
|
|
15
15
|
"main": "${main || 'index.js'}",
|
|
16
16
|
// 状态 0:禁用 1:启用
|
|
@@ -20,5 +20,17 @@
|
|
|
20
20
|
// git仓库地址
|
|
21
21
|
"git": "${git || ''}",
|
|
22
22
|
// 依赖的npm module
|
|
23
|
-
"dependencies": []
|
|
23
|
+
"dependencies": [],
|
|
24
|
+
// 是否显示在管理员挂件列表中
|
|
25
|
+
"show_admin": true,
|
|
26
|
+
// 是否显示在用户挂件列表中
|
|
27
|
+
"show_user": true,
|
|
28
|
+
// 是否显示在商户挂件列表中
|
|
29
|
+
"show_cloud": true,
|
|
30
|
+
// 是否显示在网站首页挂件列表中
|
|
31
|
+
"show_home": true,
|
|
32
|
+
// 是否显示在GM挂件列表中
|
|
33
|
+
"show_merchant": true,
|
|
34
|
+
// 是否显示在VIP页面列表中
|
|
35
|
+
"show_vip": true
|
|
24
36
|
}
|
package/core/plugin/index.js
CHANGED
|
@@ -294,4 +294,35 @@ Drive.prototype.getModel = function (type) {
|
|
|
294
294
|
return model;
|
|
295
295
|
};
|
|
296
296
|
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* 安装插件
|
|
300
|
+
* @private
|
|
301
|
+
*/
|
|
302
|
+
Plugin.prototype._install = async function () {
|
|
303
|
+
return this;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* 安装插件
|
|
308
|
+
*/
|
|
309
|
+
Plugin.prototype.install = async function () {
|
|
310
|
+
return this._install();
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* 卸载插件
|
|
315
|
+
* @private
|
|
316
|
+
*/
|
|
317
|
+
Plugin.prototype._uninstall = async function () {
|
|
318
|
+
return this;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* 卸载插件
|
|
323
|
+
*/
|
|
324
|
+
Plugin.prototype.uninstall = async function () {
|
|
325
|
+
return this._uninstall();
|
|
326
|
+
};
|
|
327
|
+
|
|
297
328
|
exports.Plugin = Plugin;
|
package/core/pusher/index.js
CHANGED
|
@@ -1,161 +1,158 @@
|
|
|
1
|
-
const { Drive } = require(
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 广播器
|
|
5
|
-
* 进行websocket、socket、mqtt广播
|
|
6
|
-
*/
|
|
7
|
-
class Pusher extends Drive {
|
|
8
|
-
static config = {
|
|
9
|
-
// 广播器名称
|
|
10
|
-
name:
|
|
11
|
-
// 推送配置
|
|
12
|
-
// 推送类型: websocket, mqtt、socket
|
|
13
|
-
type:
|
|
14
|
-
// 推送策略: realtime(实时), batch(批量)
|
|
15
|
-
strategy:
|
|
16
|
-
// 批量推送间隔(毫秒)
|
|
17
|
-
batch_interval: 100,
|
|
18
|
-
// 推送队列大小
|
|
19
|
-
queue_size: 1000,
|
|
20
|
-
// 最大重试次数
|
|
21
|
-
max_retry: 3,
|
|
22
|
-
// 重试间隔(毫秒)
|
|
23
|
-
retry_interval: 500,
|
|
24
|
-
// 是否启用压缩
|
|
25
|
-
compression: false
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* 构造函数
|
|
29
|
-
* @param {object} config 配置参数
|
|
30
|
-
* @param {object} parent 父对象
|
|
31
|
-
*/
|
|
32
|
-
constructor(config, parent) {
|
|
33
|
-
super({ ...Pusher.config, ...config || {} }, parent);
|
|
34
|
-
// 推送队列
|
|
35
|
-
this._push_queue = [];
|
|
36
|
-
// 推送计时器
|
|
37
|
-
this._batch_timer = null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 获取模板目录
|
|
43
|
-
* @returns {string} 模板目录
|
|
44
|
-
*/
|
|
45
|
-
Pusher.prototype.getTplDir = function () {
|
|
46
|
-
return __dirname;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 初始化核心
|
|
51
|
-
* @param {object} adapter 适配器
|
|
52
|
-
* @param {object} eventer 事件总线
|
|
53
|
-
* @param {object} logger 日志管理器
|
|
54
|
-
*/
|
|
55
|
-
Pusher.prototype._initCore = async function (adapter, eventer, logger) {
|
|
56
|
-
// 初始化依赖项
|
|
57
|
-
if (logger) {
|
|
58
|
-
this.setLogger(logger);
|
|
59
|
-
}
|
|
60
|
-
if (eventer) {
|
|
61
|
-
this.getEventer = function () {
|
|
62
|
-
return eventer;
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
if (adapter) {
|
|
66
|
-
this.getAdapter = function () {
|
|
67
|
-
return adapter[this.config.type];
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 初始化批量推送计时器
|
|
72
|
-
if (this.config.strategy ===
|
|
73
|
-
this._startBatchTimer();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// 注册事件监听
|
|
77
|
-
this._registerEvents();
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* 注册事件监听
|
|
82
|
-
* @private
|
|
83
|
-
*/
|
|
84
|
-
Pusher.prototype._registerEvents = function () {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
eventer.on(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
this.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
exports.Pusher = Pusher;
|
|
1
|
+
const { Drive } = require("mm_machine");
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 广播器
|
|
5
|
+
* 进行websocket、socket、mqtt广播
|
|
6
|
+
*/
|
|
7
|
+
class Pusher extends Drive {
|
|
8
|
+
static config = {
|
|
9
|
+
// 广播器名称
|
|
10
|
+
name: "default",
|
|
11
|
+
// 推送配置
|
|
12
|
+
// 推送类型: websocket, mqtt、socket
|
|
13
|
+
type: "websocket",
|
|
14
|
+
// 推送策略: realtime(实时), batch(批量)
|
|
15
|
+
strategy: "realtime",
|
|
16
|
+
// 批量推送间隔(毫秒)
|
|
17
|
+
batch_interval: 100,
|
|
18
|
+
// 推送队列大小
|
|
19
|
+
queue_size: 1000,
|
|
20
|
+
// 最大重试次数
|
|
21
|
+
max_retry: 3,
|
|
22
|
+
// 重试间隔(毫秒)
|
|
23
|
+
retry_interval: 500,
|
|
24
|
+
// 是否启用压缩
|
|
25
|
+
compression: false,
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* 构造函数
|
|
29
|
+
* @param {object} config 配置参数
|
|
30
|
+
* @param {object} parent 父对象
|
|
31
|
+
*/
|
|
32
|
+
constructor(config, parent) {
|
|
33
|
+
super({ ...Pusher.config, ...(config || {}) }, parent);
|
|
34
|
+
// 推送队列
|
|
35
|
+
this._push_queue = [];
|
|
36
|
+
// 推送计时器
|
|
37
|
+
this._batch_timer = null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 获取模板目录
|
|
43
|
+
* @returns {string} 模板目录
|
|
44
|
+
*/
|
|
45
|
+
Pusher.prototype.getTplDir = function () {
|
|
46
|
+
return __dirname;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 初始化核心
|
|
51
|
+
* @param {object} adapter 适配器
|
|
52
|
+
* @param {object} eventer 事件总线
|
|
53
|
+
* @param {object} logger 日志管理器
|
|
54
|
+
*/
|
|
55
|
+
Pusher.prototype._initCore = async function (adapter, eventer, logger) {
|
|
56
|
+
// 初始化依赖项
|
|
57
|
+
if (logger) {
|
|
58
|
+
this.setLogger(logger);
|
|
59
|
+
}
|
|
60
|
+
if (eventer) {
|
|
61
|
+
this.getEventer = function () {
|
|
62
|
+
return eventer;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (adapter) {
|
|
66
|
+
this.getAdapter = function () {
|
|
67
|
+
return adapter[this.config.type];
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 初始化批量推送计时器
|
|
72
|
+
if (this.config.strategy === "batch") {
|
|
73
|
+
this._startBatchTimer();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 注册事件监听
|
|
77
|
+
this._registerEvents();
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 注册事件监听
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
Pusher.prototype._registerEvents = function () {
|
|
85
|
+
var eventer = this.getEventer();
|
|
86
|
+
this._ev_changed = (data) => {
|
|
87
|
+
this.log("info", "entity_changed", data);
|
|
88
|
+
};
|
|
89
|
+
this._ev_created = (data) => {
|
|
90
|
+
this.log("info", "entity_created", data);
|
|
91
|
+
};
|
|
92
|
+
this._ev_deleted = (data) => {
|
|
93
|
+
this.log("info", "entity_deleted", data);
|
|
94
|
+
};
|
|
95
|
+
eventer.on("entity_changed", this._ev_changed);
|
|
96
|
+
eventer.on("entity_created", this._ev_created);
|
|
97
|
+
eventer.on("entity_deleted", this._ev_deleted);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 广播消息给所有连接的客户端
|
|
102
|
+
* @param {string} method 方法名
|
|
103
|
+
* @param {object} params 参数
|
|
104
|
+
*/
|
|
105
|
+
Pusher.prototype.broadcast = function (method, params) {};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 启动
|
|
109
|
+
*/
|
|
110
|
+
Pusher.prototype._start = async function () {
|
|
111
|
+
this.log("info", "启动");
|
|
112
|
+
|
|
113
|
+
// 启动批量推送计时器
|
|
114
|
+
if (this.config.strategy === "batch") {
|
|
115
|
+
this._startBatchTimer();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 停止
|
|
121
|
+
*/
|
|
122
|
+
Pusher.prototype._stop = async function () {
|
|
123
|
+
// 停止批量推送计时器
|
|
124
|
+
if (this._batch_timer) {
|
|
125
|
+
clearInterval(this._batch_timer);
|
|
126
|
+
this._batch_timer = null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 清空推送队列
|
|
130
|
+
this._push_queue = [];
|
|
131
|
+
|
|
132
|
+
this.log("info", "stopped");
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 销毁
|
|
137
|
+
*/
|
|
138
|
+
Pusher.prototype._destroy = function () {
|
|
139
|
+
try {
|
|
140
|
+
// 停止批量推送计时器
|
|
141
|
+
if (this._batch_timer) {
|
|
142
|
+
clearInterval(this._batch_timer);
|
|
143
|
+
this._batch_timer = null;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// 清空存储引用
|
|
147
|
+
this._push_queue = [];
|
|
148
|
+
|
|
149
|
+
this.log("info", "destroyed");
|
|
150
|
+
|
|
151
|
+
// 移除所有监听器
|
|
152
|
+
this.removeAllListeners();
|
|
153
|
+
} catch (error) {
|
|
154
|
+
this.log("error", `销毁失败`, error);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
exports.Pusher = Pusher;
|