mm_os 1.6.8 → 1.7.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/core/base/mqtt/index.js +48 -1
- package/core/com/api/index.js +6 -2
- package/core/com/event/drive.js +4 -3
- package/core/com/event/index.js +66 -7
- package/core/com/eventer/com.js +3 -0
- package/core/com/mqtt/index.js +9 -7
- package/core/com/nav/index.js +1 -1
- package/core/com/param/index.js +2 -1
- package/core/com/plugin/drive.js +3 -2
- package/core/com/plugin/index.js +13 -8
- package/core/com/sql/index.js +7 -2
- package/core/com/task/index.js +1 -2
- package/index.js +22 -7
- package/package.json +2 -2
package/core/base/mqtt/index.js
CHANGED
|
@@ -192,7 +192,25 @@ MQTT.prototype.main = function(state) {
|
|
|
192
192
|
this.auth(client, username, password, callback);
|
|
193
193
|
return true;
|
|
194
194
|
};
|
|
195
|
-
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 验证发布,决定客户端可以发布哪些主题
|
|
198
|
+
*/
|
|
199
|
+
sr.authorizePublish = (client, topic, payload, callback) => {
|
|
200
|
+
this.authPublish(client, topic, payload, callback);
|
|
201
|
+
return true;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* 验证订阅,决定客户端可以订阅哪些主题
|
|
207
|
+
*/
|
|
208
|
+
sr.authorizeSubscribe = (client, topic, callback) => {
|
|
209
|
+
this.authSubscribe(client, topic, callback);
|
|
210
|
+
return true;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
|
|
196
214
|
/**
|
|
197
215
|
* 当服务开启时
|
|
198
216
|
*/
|
|
@@ -234,6 +252,35 @@ MQTT.prototype.auth = function(client, username, password, callback) {
|
|
|
234
252
|
callback(null, bl);
|
|
235
253
|
};
|
|
236
254
|
|
|
255
|
+
/**
|
|
256
|
+
* 验证发布,决定客户端可以发布哪些主题
|
|
257
|
+
* @param {Object} client 客户端
|
|
258
|
+
* @param {String} topic 用户名
|
|
259
|
+
* @param {Object} payload 参数
|
|
260
|
+
* @param {Function} callback 回调函数,回调返回true,则表示验证通过。
|
|
261
|
+
*/
|
|
262
|
+
MQTT.prototype.authPublish = function(client, topic, payload, callback) {
|
|
263
|
+
var bl = true;
|
|
264
|
+
// if(topic == "temperature"){
|
|
265
|
+
// bl = false;
|
|
266
|
+
// }
|
|
267
|
+
// console.log('收到推送', client.id, topic, payload.toString());
|
|
268
|
+
// 回调第二个参数为true表示验证通过, 为false表示验证失败
|
|
269
|
+
callback(null, bl);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 验证订阅,决定客户端可以订阅哪些主题
|
|
274
|
+
* @param {Object} client 客户端
|
|
275
|
+
* @param {String} topic 用户名
|
|
276
|
+
* @param {Function} callback 回调函数,回调返回true,则表示验证通过。
|
|
277
|
+
*/
|
|
278
|
+
MQTT.prototype.authSubscribe = function(client, topic, callback) {
|
|
279
|
+
var bl = true;
|
|
280
|
+
// 回调第二个参数为true表示验证通过, 为false表示验证失败
|
|
281
|
+
callback(null, bl);
|
|
282
|
+
};
|
|
283
|
+
|
|
237
284
|
/**
|
|
238
285
|
* 运行主程序前
|
|
239
286
|
* @param {String} state 状态
|
package/core/com/api/index.js
CHANGED
|
@@ -51,10 +51,13 @@ Api.prototype.run = async function(ctx, db) {
|
|
|
51
51
|
}
|
|
52
52
|
const path = ctx.request.path;
|
|
53
53
|
var lt = this.list;
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
for (var i = 0, o; o = lt[i++];) {
|
|
56
56
|
if (o.config.state === 1 && path.has(o.config.path)) {
|
|
57
57
|
var ret = await o.run(ctx, db);
|
|
58
|
+
if (this.mode) {
|
|
59
|
+
o.load(o.filename);
|
|
60
|
+
}
|
|
58
61
|
if (ret) {
|
|
59
62
|
db.ret = ret;
|
|
60
63
|
break;
|
|
@@ -124,7 +127,8 @@ function api_admin(scope, title) {
|
|
|
124
127
|
}
|
|
125
128
|
return obj;
|
|
126
129
|
}
|
|
130
|
+
|
|
127
131
|
/**
|
|
128
132
|
* @module 导出API管理器
|
|
129
133
|
*/
|
|
130
|
-
$.api_admin = api_admin;
|
|
134
|
+
$.api_admin = api_admin;
|
package/core/com/event/drive.js
CHANGED
|
@@ -33,7 +33,7 @@ class Drive extends Item {
|
|
|
33
33
|
// 文件路径, 当调用函数不存在时,会先从文件中加载
|
|
34
34
|
"func_file": "./main.js",
|
|
35
35
|
// 回调函数名 用于决定调用脚本的哪个函数
|
|
36
|
-
"func_name": "
|
|
36
|
+
"func_name": "",
|
|
37
37
|
// 执行顺序, 数字越小,越优先执行
|
|
38
38
|
"sort": 100,
|
|
39
39
|
// 中断循环
|
|
@@ -105,10 +105,11 @@ Drive.prototype.new_config = function(file) {
|
|
|
105
105
|
* 执行事件
|
|
106
106
|
* @param {Object} ctx 请求上下文
|
|
107
107
|
* @param {Object} db 数据管理器
|
|
108
|
+
* @param {String} method 执行方法
|
|
108
109
|
* @return {Object} 执行结果
|
|
109
110
|
*/
|
|
110
|
-
Drive.prototype.run = async function(ctx, db) {
|
|
111
|
-
var ret = await this
|
|
111
|
+
Drive.prototype.run = async function(ctx, db, method = 'main') {
|
|
112
|
+
var ret = await this[method](ctx, db);
|
|
112
113
|
return ret;
|
|
113
114
|
};
|
|
114
115
|
|
package/core/com/event/index.js
CHANGED
|
@@ -140,6 +140,26 @@ Event.prototype.sort = function(stage) {
|
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 执行事件
|
|
146
|
+
*/
|
|
147
|
+
Event.prototype.doing = async function(o, ctx, db) {
|
|
148
|
+
var ret;
|
|
149
|
+
try {
|
|
150
|
+
ret = o.run(ctx, db);
|
|
151
|
+
if (types.isPromise(ret)) {
|
|
152
|
+
ret = await ret;
|
|
153
|
+
}
|
|
154
|
+
if (this.mode) {
|
|
155
|
+
o.load(o.filename);
|
|
156
|
+
}
|
|
157
|
+
} catch (err) {
|
|
158
|
+
console.error(err);
|
|
159
|
+
}
|
|
160
|
+
return ret;
|
|
161
|
+
}
|
|
162
|
+
|
|
143
163
|
/**
|
|
144
164
|
* 执行函数
|
|
145
165
|
* @param {Array} list 列表
|
|
@@ -152,6 +172,9 @@ Event.prototype.run_sub = async function(list, target, ctx, db) {
|
|
|
152
172
|
for (var i = 0, o; o = list[i++];) {
|
|
153
173
|
if (o.config.state === 1 && target.has(o.config.target)) {
|
|
154
174
|
var ret = await o.run(ctx, db);
|
|
175
|
+
if (this.mode) {
|
|
176
|
+
o.load(o.filename);
|
|
177
|
+
}
|
|
155
178
|
if (ret) {
|
|
156
179
|
db.ret = ret;
|
|
157
180
|
if (o.config.end) {
|
|
@@ -246,6 +269,40 @@ Event.prototype.run = async function(target, ctx, db) {
|
|
|
246
269
|
return ret;
|
|
247
270
|
};
|
|
248
271
|
|
|
272
|
+
/**
|
|
273
|
+
* @description 获取事件
|
|
274
|
+
* @param {String} name 名称
|
|
275
|
+
* @param {String} event_type 事件类型
|
|
276
|
+
* @return {Object} 返回单项配置
|
|
277
|
+
*/
|
|
278
|
+
Event.prototype.get = function(name, event_type = 'main') {
|
|
279
|
+
var obj;
|
|
280
|
+
var lt = this['list_' + event_type];
|
|
281
|
+
var len = lt.length;
|
|
282
|
+
for (var i = 0; i < len; i++) {
|
|
283
|
+
var o = lt[i];
|
|
284
|
+
if (name === o.config.name) {
|
|
285
|
+
obj = o;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return obj;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @description 重载脚本和配置
|
|
294
|
+
* @param {String} file 文件名
|
|
295
|
+
* @return {String} 重载失败返回错误提示,重载成功返回null
|
|
296
|
+
*/
|
|
297
|
+
Event.prototype.reload = function(name, event_type = 'main') {
|
|
298
|
+
var o = this.get(name, event_type);
|
|
299
|
+
if (o) {
|
|
300
|
+
o.load(o.filename);
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
return '没有找到模块';
|
|
304
|
+
}
|
|
305
|
+
|
|
249
306
|
/**
|
|
250
307
|
* @module 导出Event类
|
|
251
308
|
*/
|
|
@@ -258,13 +315,7 @@ if (!$.pool.event) {
|
|
|
258
315
|
$.pool.event = {};
|
|
259
316
|
}
|
|
260
317
|
|
|
261
|
-
|
|
262
|
-
* Event管理器,用于创建缓存
|
|
263
|
-
* @param {String} scope 作用域
|
|
264
|
-
* @param {string} title 标题
|
|
265
|
-
* @return {Object} 返回一个缓存类
|
|
266
|
-
*/
|
|
267
|
-
$.event_admin = function(scope, title) {
|
|
318
|
+
function event_admin(scope, title) {
|
|
268
319
|
if (!scope) {
|
|
269
320
|
scope = $.val.scope + '';
|
|
270
321
|
}
|
|
@@ -275,3 +326,11 @@ $.event_admin = function(scope, title) {
|
|
|
275
326
|
}
|
|
276
327
|
return obj;
|
|
277
328
|
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Event管理器,用于创建缓存
|
|
332
|
+
* @param {String} scope 作用域
|
|
333
|
+
* @param {string} title 标题
|
|
334
|
+
* @return {Object} 返回一个缓存类
|
|
335
|
+
*/
|
|
336
|
+
$.event_admin = event_admin;
|
package/core/com/eventer/com.js
CHANGED
package/core/com/mqtt/index.js
CHANGED
|
@@ -118,13 +118,7 @@ if (!$.pool.mqtt) {
|
|
|
118
118
|
$.pool.mqtt = {};
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
|
|
122
|
-
* mqtt管理器, 用于管理插件
|
|
123
|
-
* @param {string} scope 作用域
|
|
124
|
-
* @param {string} title 标题
|
|
125
|
-
* @return {Object} 返回一个缓存类
|
|
126
|
-
*/
|
|
127
|
-
$.mqtt_admin = function (scope, title) {
|
|
121
|
+
function mqtt_admin(scope, title) {
|
|
128
122
|
if (!scope) {
|
|
129
123
|
scope = $.val.scope + '';
|
|
130
124
|
}
|
|
@@ -135,4 +129,12 @@ $.mqtt_admin = function (scope, title) {
|
|
|
135
129
|
}
|
|
136
130
|
return obj;
|
|
137
131
|
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* mqtt管理器, 用于管理插件
|
|
135
|
+
* @param {string} scope 作用域
|
|
136
|
+
* @param {string} title 标题
|
|
137
|
+
* @return {Object} 返回一个缓存类
|
|
138
|
+
*/
|
|
139
|
+
$.mqtt_admin = mqtt_admin;
|
|
138
140
|
|
package/core/com/nav/index.js
CHANGED
package/core/com/param/index.js
CHANGED
package/core/com/plugin/drive.js
CHANGED
|
@@ -260,10 +260,11 @@ Drive.prototype.main = function(param1, param2) {
|
|
|
260
260
|
* 执行程序
|
|
261
261
|
* @param {Object} param1 参数1
|
|
262
262
|
* @param {Object} param2 参数2
|
|
263
|
+
* @param {String} method 执行方法
|
|
263
264
|
* @return {Object} 返回执行结果
|
|
264
265
|
*/
|
|
265
|
-
Drive.prototype.run = function(param1, param2) {
|
|
266
|
-
return this
|
|
266
|
+
Drive.prototype.run = function(param1, param2, method = 'main') {
|
|
267
|
+
return this[method](param1, param2);
|
|
267
268
|
};
|
|
268
269
|
|
|
269
270
|
/**
|
package/core/com/plugin/index.js
CHANGED
|
@@ -33,6 +33,9 @@ Plugin.prototype.run = function(param1, param2) {
|
|
|
33
33
|
for (var i = 0, o; o = lt[i++];) {
|
|
34
34
|
if (o.config.state === 1) {
|
|
35
35
|
ret = o.run(param1, param2);
|
|
36
|
+
if (this.mode) {
|
|
37
|
+
o.load(o.filename);
|
|
38
|
+
}
|
|
36
39
|
if (ret && o.end) {
|
|
37
40
|
break;
|
|
38
41
|
}
|
|
@@ -154,13 +157,7 @@ if (!$.pool.plugin) {
|
|
|
154
157
|
$.pool.plugin = {};
|
|
155
158
|
}
|
|
156
159
|
|
|
157
|
-
|
|
158
|
-
* plugin管理器, 用于管理插件
|
|
159
|
-
* @param {string} scope 作用域
|
|
160
|
-
* @param {string} title 标题
|
|
161
|
-
* @return {Object} 返回一个缓存类
|
|
162
|
-
*/
|
|
163
|
-
$.plugin_admin = function(scope, title) {
|
|
160
|
+
function plugin_admin(scope, title) {
|
|
164
161
|
if (!scope) {
|
|
165
162
|
scope = $.val.scope + '';
|
|
166
163
|
}
|
|
@@ -170,4 +167,12 @@ $.plugin_admin = function(scope, title) {
|
|
|
170
167
|
obj = $.pool.plugin[scope];
|
|
171
168
|
}
|
|
172
169
|
return obj;
|
|
173
|
-
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* plugin管理器, 用于管理插件
|
|
174
|
+
* @param {string} scope 作用域
|
|
175
|
+
* @param {string} title 标题
|
|
176
|
+
* @return {Object} 返回一个缓存类
|
|
177
|
+
*/
|
|
178
|
+
$.plugin_admin = plugin_admin;
|
package/core/com/sql/index.js
CHANGED
|
@@ -65,7 +65,11 @@ Sql.prototype.sort = function() {
|
|
|
65
65
|
Sql.prototype.run = async function(name, query, body, db) {
|
|
66
66
|
var obj = this.get(name);
|
|
67
67
|
if (obj) {
|
|
68
|
-
|
|
68
|
+
var ret = await obj.run(query, body, db);
|
|
69
|
+
if (this.mode) {
|
|
70
|
+
o.load(o.filename);
|
|
71
|
+
}
|
|
72
|
+
return ret;
|
|
69
73
|
}
|
|
70
74
|
return null;
|
|
71
75
|
};
|
|
@@ -97,7 +101,8 @@ function sql_admin(scope, title) {
|
|
|
97
101
|
}
|
|
98
102
|
return obj;
|
|
99
103
|
}
|
|
104
|
+
|
|
100
105
|
/**
|
|
101
106
|
* @module 导出Sql管理器
|
|
102
107
|
*/
|
|
103
|
-
|
|
108
|
+
$.sql_admin = sql_admin;
|
package/core/com/task/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const Index = require('mm_machine').Index;
|
|
2
2
|
const Drive = require('./drive');
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* 任务类
|
|
7
6
|
* @extends {Index}
|
|
@@ -116,4 +115,4 @@ function task_admin(scope, title) {
|
|
|
116
115
|
/**
|
|
117
116
|
* @module 导出Task管理器
|
|
118
117
|
*/
|
|
119
|
-
|
|
118
|
+
$.task_admin = task_admin;
|
package/index.js
CHANGED
|
@@ -28,6 +28,8 @@ class Soa {
|
|
|
28
28
|
"cache": "memory",
|
|
29
29
|
"lang": "zh_CN",
|
|
30
30
|
"game": false,
|
|
31
|
+
"task": false,
|
|
32
|
+
"log": false
|
|
31
33
|
},
|
|
32
34
|
"web": {
|
|
33
35
|
"state": true,
|
|
@@ -122,9 +124,13 @@ Soa.prototype.loadModule = function(config) {
|
|
|
122
124
|
$.app = new App();
|
|
123
125
|
this.com = $.com;
|
|
124
126
|
this.app = $.app;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
|
|
128
|
+
$.task = $.task_admin('sys');
|
|
129
|
+
if (config.sys) {
|
|
130
|
+
if (config.sys.game) {
|
|
131
|
+
$.game = new Game();
|
|
132
|
+
this.game = $.game;
|
|
133
|
+
}
|
|
128
134
|
}
|
|
129
135
|
}
|
|
130
136
|
|
|
@@ -139,10 +145,10 @@ Soa.prototype.init = function(config) {
|
|
|
139
145
|
this.initBase(this.config);
|
|
140
146
|
}
|
|
141
147
|
|
|
142
|
-
/**
|
|
143
|
-
* 运行基础数据
|
|
144
|
-
* @param {Object} cg - 配置对象
|
|
145
|
-
*/
|
|
148
|
+
/**
|
|
149
|
+
* 运行基础数据
|
|
150
|
+
* @param {Object} cg - 配置对象
|
|
151
|
+
*/
|
|
146
152
|
Soa.prototype.initBase = function(cg) {
|
|
147
153
|
var middleware = $.middleware;
|
|
148
154
|
middleware.init();
|
|
@@ -196,6 +202,9 @@ Soa.prototype.initBase = function(cg) {
|
|
|
196
202
|
$.sql.open();
|
|
197
203
|
}
|
|
198
204
|
}
|
|
205
|
+
|
|
206
|
+
// 启动计时器
|
|
207
|
+
$.timer.run();
|
|
199
208
|
}
|
|
200
209
|
|
|
201
210
|
|
|
@@ -220,6 +229,12 @@ Soa.prototype.main = async function(state) {
|
|
|
220
229
|
this.mqtt.run();
|
|
221
230
|
tip += " mqtt";
|
|
222
231
|
}
|
|
232
|
+
|
|
233
|
+
if (cg.sys && cg.sys.task) {
|
|
234
|
+
console.log('启动定时任务~');
|
|
235
|
+
$.task.update();
|
|
236
|
+
$.task.run();
|
|
237
|
+
}
|
|
223
238
|
console.log(tip);
|
|
224
239
|
};
|
|
225
240
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_os",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "这是超级美眉服务端框架,用于快速构建应用程序。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"mm_html": "^1.1.1",
|
|
41
41
|
"mm_koa_proxy": "^1.0.0",
|
|
42
42
|
"mm_logs": "^1.1.0",
|
|
43
|
-
"mm_machine": "^1.
|
|
43
|
+
"mm_machine": "^1.6.0",
|
|
44
44
|
"mm_mongodb": "^1.3.9",
|
|
45
45
|
"mm_mqtt": "^1.0.5",
|
|
46
46
|
"mm_mysql": "^1.7.1",
|