mm_os 2.2.1 → 2.2.3

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.
@@ -138,11 +138,11 @@ MQTT.prototype.update_after = function() {
138
138
  * 重新连接
139
139
  */
140
140
  MQTT.prototype.reconnect = function() {
141
+ $.sleep(this.config.interval);
141
142
  this.retryTimes += 1;
142
143
  if (this.retryTimes > 5) {
143
144
  try {
144
145
  this.client.end();
145
- $.sleep(this.config.interval);
146
146
  this.init();
147
147
  } catch (error) {
148
148
  this.$message.error(error.toString());
@@ -193,7 +193,9 @@ MQTT.prototype.start = function() {
193
193
  resolve(packet);
194
194
  }
195
195
  });
196
- this.client.on("reconnect", this.reconnect);
196
+ this.client.on("reconnect", () => {
197
+ this.reconnect();
198
+ });
197
199
  this.client.on("error", (error) => {
198
200
  console.error("Connection failed", error);
199
201
  });
@@ -264,7 +264,7 @@ exports.update_member_batch = async function(clientid, list, longtime = 0) {
264
264
  /**
265
265
  * 播放语音
266
266
  */
267
- exports.play_audio = function(clientid, type = 3) {
267
+ exports.play_audio = async function(clientid, type = 3) {
268
268
  var body = {};
269
269
  switch (type) {
270
270
  case 1:
@@ -316,27 +316,27 @@ exports.init = function() {
316
316
 
317
317
  m["RecPush"] = async function(clientid, params, msg, id) {
318
318
  var info = msg.body;
319
- "body": {
320
- "e_imgsize": 13485,
321
- "ext_sec": 1709089205,
322
- "hat": -1,
323
- "hcode_status": 0,
324
- "idcard": "",
325
- "img_data": "/9j/4AAQSkZJRgABAQIAdgB2AAD/7wAPAAAAAAAAAAAAAAAAAP",
326
- "isRealtimeData": 601,
327
- "isurl": false,
328
- "mask": -1,
329
- "matched": 93,
330
- "name": "schmidt",
331
- "name_base64": "c2NobWlkdA==",
332
- "per_id": "1706099386778",
333
- "per_id_base64": "MTcwNjA5OTM4Njc3OA==",
334
- "role": 0,
335
- "sequence": 27307,
336
- "sn": "7560d2db-fd20feb7",
337
- "tep": 0,
338
- "usec": 1709118005
339
- }
319
+ // "body": {
320
+ // "e_imgsize": 13485,
321
+ // "ext_sec": 1709089205,
322
+ // "hat": -1,
323
+ // "hcode_status": 0,
324
+ // "idcard": "",
325
+ // "img_data": "/9j/4AAQSkZJRgABAQIAdgB2AAD/7wAPAAAAAAAAAAAAAAAAAP",
326
+ // "isRealtimeData": 601,
327
+ // "isurl": false,
328
+ // "mask": -1,
329
+ // "matched": 93,
330
+ // "name": "schmidt",
331
+ // "name_base64": "c2NobWlkdA==",
332
+ // "per_id": "1706099386778",
333
+ // "per_id_base64": "MTcwNjA5OTM4Njc3OA==",
334
+ // "role": 0,
335
+ // "sequence": 27307,
336
+ // "sn": "7560d2db-fd20feb7",
337
+ // "tep": 0,
338
+ // "usec": 1709118005
339
+ // }
340
340
 
341
341
  var type = 1;
342
342
  switch (params.otype) {
@@ -35,6 +35,12 @@
35
35
  "max_age": 120000,
36
36
  // 代理转发
37
37
  "proxy": {},
38
+ // 跨域
39
+ "cos": {
40
+ "status": true,
41
+ "origin": "*",
42
+ "headers": "Content-Type,Content-Length,Authorization,Accept,X-Requested-With,x-auth-token,token,client_id,appid,apikey,user_id,x-forwarded-for,x-real-ip,user-agent,cache-control,pragma,accept-encoding,connection,host"
43
+ },
38
44
  // 单位秒, 3600 = 1小时
39
45
  "request_duration": 60,
40
46
  // 请求次数上限
@@ -54,7 +60,9 @@
54
60
  // 缓存服务器地址
55
61
  "cache_host": "mongodb://localhost:27017/mosca",
56
62
  // MQTT订阅方式
57
- "subscribe_qos": 0,
63
+ "subscribe_qos": 1,
64
+ // 清除历史
65
+ "clean": true,
58
66
  // 协议头
59
67
  "protocol": "mqtt",
60
68
  // MQTT服务器地址
@@ -22,7 +22,7 @@
22
22
  // 是否启用websocket
23
23
  "socket": true,
24
24
  // 是否启用压缩
25
- "compress": true,
25
+ "compress": false,
26
26
  // 是否启用事件
27
27
  "event": true,
28
28
  // 是否启用事件
@@ -34,7 +34,19 @@
34
34
  // 静态文件缓存时长
35
35
  "max_age": 3600,
36
36
  // 代理转发
37
- "proxy": {}
37
+ "proxy": {},
38
+ // 跨域
39
+ "cos": {
40
+ "status": true,
41
+ "origin": "*"
42
+ // "headers": "Content-Type,Content-Length,Authorization,Accept,X-Requested-With,x-auth-token,token,client_id,appid,apikey,user_id,x-forwarded-for,x-real-ip,User-Agent,cache-control,pragma,accept-encoding,connection,host"
43
+ },
44
+ // 单位秒, 3600 = 1小时
45
+ "request_duration": 60,
46
+ // 请求次数上限
47
+ "request_limit": 100,
48
+ // 是否加入黑名单
49
+ "request_block": true
38
50
  },
39
51
  "mqtt": {
40
52
  "state": true,
@@ -50,6 +62,8 @@
50
62
  "cache_host": "mongodb://localhost:27017/mosca",
51
63
  // MQTT订阅方式
52
64
  "subscribe_qos": 1,
65
+ // 清除历史
66
+ "clean": true,
53
67
  "protocol": "mqtt",
54
68
  "hostname": "127.0.0.1",
55
69
  // MQTT服务器客户端ID
@@ -96,4 +110,4 @@
96
110
  // 密码 无则代表连接不需要账号密码
97
111
  "password": "asd159357"
98
112
  }
99
- }
113
+ }
@@ -4,53 +4,82 @@
4
4
  * @param {Object} config 配置参数
5
5
  */
6
6
  module.exports = function(server, config) {
7
- /* 跨域限制(web防火墙) */
8
- server.use(async (ctx, next) => {
9
- var req = ctx.request;
7
+ var cos = config.cos;
8
+ if (cos && cos.status) {
9
+ if (cos.headers && cos.origin !== "*") {
10
+ /* 跨域限制(web防火墙) */
11
+ server.use(async (ctx, next) => {
12
+ var req = ctx.request;
10
13
 
11
- // 允许来自所有域名请求
12
- ctx.set('Access-Control-Allow-Origin', '*');
13
- // 这样就能只允许 http://localhost:8080 这个域名的请求了
14
- // ctx.set("Access-Control-Allow-Origin", "http://localhost:8080");
14
+ // 允许来自所有域名请求
15
+ ctx.set('Access-Control-Allow-Origin', cos.origin);
16
+ // 这样就能只允许 http://localhost:8080 这个域名的请求了
17
+ // ctx.set("Access-Control-Allow-Origin", "http://localhost:8080");
15
18
 
16
- // 设置所允许的HTTP请求方法OPTIONS,GET,PUT,POST,DELETE
17
- // ctx.set('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,HEAD,OPTIONS');
19
+ // 字段是必需的。它也是一个逗号分隔的字符串,表明服务器支持的所有头信息字段.
20
+ if (req.method == "OPTIONS") {
21
+ ctx.set('Access-Control-Allow-Headers', cos.headers);
18
22
 
19
- // 字段是必需的。它也是一个逗号分隔的字符串,表明服务器支持的所有头信息字段.
20
- // ctx.set('Access-Control-Allow-Headers',
21
- // 'Content-Type,Content-Length,Authorization,Accept,X-Requested-With,x-auth-token,token,client_id,appid,apikey,user_id,x-forwarded-for,x-real-ip,user-agent,cache-control,pragma,accept-encoding,connection,host'
22
- // );
23
+ // 服务器收到请求以后,检查了Origin、Access-Control-Request-Method和Access-Control-Request-Headers字段以后,确认允许跨源请求,就可以做出回应。
24
+ // Content-Type表示具体请求中的媒体类型信息
25
+ // ctx.set("Content-Type", "application/json;charset=utf-8");
26
+ // 设置所允许的HTTP请求方法PUT,POST,GET,DELETE,HEAD,OPTIONS
27
+ // ctx.set('Access-Control-Allow-Methods', 'GET,POST');
23
28
 
24
- // 服务器收到请求以后,检查了Origin、Access-Control-Request-Method和Access-Control-Request-Headers字段以后,确认允许跨源请求,就可以做出回应。
29
+ // 该字段可选。它的值是一个布尔值,表示是否允许发送Cookie。默认情况下,Cookie不包括在CORS请求之中。
30
+ // 当设置成允许请求携带cookie时,需要保证"Access-Control-Allow-Origin"是服务器有的域名,而不能是"*";
31
+ // ctx.set("Access-Control-Allow-Credentials", 'false');
25
32
 
26
- // Content-Type表示具体请求中的媒体类型信息
27
- // ctx.set("Content-Type", "application/json;charset=utf-8");
28
-
29
- // 该字段可选。它的值是一个布尔值,表示是否允许发送Cookie。默认情况下,Cookie不包括在CORS请求之中。
30
- // 当设置成允许请求携带cookie时,需要保证"Access-Control-Allow-Origin"是服务器有的域名,而不能是"*";
31
- // ctx.set("Access-Control-Allow-Credentials", 'true');
32
-
33
- // 该字段可选,用来指定本次预检请求的有效期,单位为秒。
34
- // 当请求方法是PUT或DELETE等特殊方法或者Content-Type字段的类型是application/json时,服务器会提前发送一次请求进行验证
35
- // 下面的的设置只本次验证的有效时间,即在该时间段内服务端可以不用进行验证
36
- // ctx.set("Access-Control-Max-Age", '3600');
37
- /*
38
- CORS请求时,XMLHttpRequest对象的getResponseHeader()方法只能拿到6个基本字段:
39
- Cache-Control
40
- Content-Language、
41
- Content-Type、
42
- Expires、
43
- Last-Modified、
44
- Pragma。
45
- */
46
- // 需要获取其他字段时,使用Access-Control-Expose-Headers,
47
- // getResponseHeader('myData')可以返回我们所需的值
48
- // ctx.set("Access-Control-Expose-Headers", "myData");
49
- if (req.method === 'OPTIONS') {
50
- ctx.status = 204;
33
+ // 该字段可选,用来指定本次预检请求的有效期,单位为秒。
34
+ // 当请求方法是PUT或DELETE等特殊方法或者Content-Type字段的类型是application/json时,服务器会提前发送一次请求进行验证
35
+ // 下面的的设置只本次验证的有效时间,即在该时间段内服务端可以不用进行验证
36
+ // ctx.set("Access-Control-Max-Age", '3600');
37
+ /*
38
+ CORS请求时,XMLHttpRequest对象的getResponseHeader()方法只能拿到6个基本字段:
39
+ Cache-Control、
40
+ Content-Language、
41
+ Content-Type
42
+ Expires、
43
+ Last-Modified、
44
+ Pragma
45
+ */
46
+ // 需要获取其他字段时,使用Access-Control-Expose-Headers,
47
+ // getResponseHeader('myData')可以返回我们所需的值
48
+ // ctx.set("Access-Control-Expose-Headers", "myData");
49
+ ctx.status = 204;
50
+ } else {
51
+ await next();
52
+ }
53
+ });
54
+ } else if (cos.headers && cos.headers !== "*") {
55
+ /* 跨域限制(web防火墙) */
56
+ server.use(async (ctx, next) => {
57
+ var req = ctx.request;
58
+ // 允许来自所有域名请求
59
+ ctx.set('Access-Control-Allow-Origin', '*');
60
+ // ctx.set('Access-Control-Allow-Methods', 'GET,POST,OPTIONS');
61
+ if (req.method === 'OPTIONS') {
62
+ ctx.set('Access-Control-Allow-Headers', cos.headers);
63
+ ctx.status = 204;
64
+ } else {
65
+ await next();
66
+ }
67
+ });
51
68
  } else {
52
- await next();
69
+ /* 跨域限制(web防火墙) */
70
+ server.use(async (ctx, next) => {
71
+ var req = ctx.request;
72
+ // 允许来自所有域名请求
73
+ ctx.set('Access-Control-Allow-Origin', '*');
74
+ // ctx.set('Access-Control-Allow-Methods', 'GET,POST,OPTIONS');
75
+ if (req.method === 'OPTIONS') {
76
+ ctx.set('Access-Control-Allow-Headers', '*');
77
+ ctx.status = 204;
78
+ } else {
79
+ await next();
80
+ }
81
+ });
53
82
  }
54
- });
83
+ }
55
84
  return server;
56
- };
85
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_os",
3
- "version": "2.2.1",
3
+ "version": "2.2.3",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -35,13 +35,13 @@
35
35
  "koa-compress": "^5.1.1",
36
36
  "koa-send": "^5.0.1",
37
37
  "koa-websocket": "^7.0.0",
38
- "mm_check": "^1.4.7",
38
+ "mm_check": "^1.4.8",
39
39
  "mm_excel": "^1.2.0",
40
- "mm_expand": "^1.7.0",
40
+ "mm_expand": "^1.7.2",
41
41
  "mm_html": "^1.1.6",
42
42
  "mm_koa_proxy": "^1.0.0",
43
43
  "mm_logs": "^1.1.4",
44
- "mm_machine": "^1.7.2",
44
+ "mm_machine": "^1.7.3",
45
45
  "mm_mongodb": "^1.4.2",
46
46
  "mm_mqtt": "^1.0.6",
47
47
  "mm_mysql": "^1.8.0",
@@ -52,6 +52,7 @@
52
52
  "mm_tpl": "^2.3.9",
53
53
  "mm_xml": "^1.1.5",
54
54
  "mosca": "^2.8.3",
55
- "mqtt": "^5.10.1"
55
+ "mqtt": "^5.10.2",
56
+ "publish": "^0.6.0"
56
57
  }
57
58
  }