mm_os 2.4.3 → 2.4.5

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.
@@ -275,11 +275,16 @@ Drive.prototype.pushSync = function(clientid, msg, func, longtime = 0) {
275
275
  if (!longtime) {
276
276
  longtime = this.config.longtime || 60000;
277
277
  }
278
- var timer = setTimeout(() => {
278
+ setTimeout(async () => {
279
279
  // 如果时间到了,回调函数还在队列中,则视为无回复
280
280
  if (this.drives[clientid][key]) {
281
+ try {
282
+ await this.drives[clientid][key].func(null);
283
+ } catch (error) {
284
+ $.log.error("MQTT回调错误", key, error);
285
+ //TODO handle the exception
286
+ }
281
287
  this.del_msg(clientid, key);
282
- func(null);
283
288
  }
284
289
  }, longtime);
285
290
  }
@@ -340,7 +345,7 @@ Drive.prototype.push = function(method, clientid, params, longtime = 0) {
340
345
  msg[cg.msgid] = this.get_msgid(method);
341
346
  msg[cg.method] = method;
342
347
  msg[cg.params] = params;
343
- return this.pushS(clientid, msg);
348
+ return this.pushS(clientid, msg, longtime);
344
349
  }
345
350
 
346
351
  /**
@@ -388,7 +388,7 @@ exports.init = function() {
388
388
  }
389
389
  _this.drives[clientid].online = 1;
390
390
  _this.drives[clientid].time_last = new Date().getTime();
391
- console.log("心跳", clientid, _this.drives[clientid]);
391
+ // console.log("心跳", clientid, _this.drives[clientid]);
392
392
  }
393
393
 
394
394
  /**
@@ -10,8 +10,8 @@
10
10
  "mqtt/face/${clientid}"
11
11
  ],
12
12
  "topic_push": "mqtt/face/${clientid}",
13
- "qos": 2,
14
- "qos_push": 2,
13
+ "qos": 1,
14
+ "qos_push": 0,
15
15
  "retain": true,
16
16
  "longtime": 10000,
17
17
  "func_file": "./index.js",
@@ -58,6 +58,9 @@ exports.unlock = async function(clientid, uuid = '0', pass = false, tip = '没
58
58
  // 0不开门,1开门
59
59
  "ctrl_type": pass ? "on" : "off"
60
60
  });
61
+ if (!res) {
62
+ return "请求超时!"
63
+ }
61
64
  if (res.message !== "ACK") {
62
65
  return res.code;
63
66
  }
@@ -75,12 +78,23 @@ exports.delete_member = async function(clientid, uuid) {
75
78
  "per_id": uuid,
76
79
  "type": 0
77
80
  });
81
+ if (!res) {
82
+ return "请求超时!"
83
+ }
78
84
  if (res.message !== "ACK") {
79
85
  return res.code;
80
86
  }
81
87
  return
82
88
  }
83
89
 
90
+ exports.sleep = async function(longtime, param) {
91
+ return new Promise((resolve, reject) => {
92
+ setTimeout(() => {
93
+ resolve(param);
94
+ }, longtime);
95
+ });
96
+ }
97
+
84
98
  /**
85
99
  * 批量删除成员
86
100
  * @param {String} clientid 客户端ID
@@ -91,7 +105,7 @@ exports.delete_member_batch = async function(clientid, arr, longtime) {
91
105
  if (!this.drives[clientid]) {
92
106
  this.drives[clientid] = {};
93
107
  }
94
- if (this.drives[clientid].pushing == 1) {
108
+ if (this.drives[clientid].pushing) {
95
109
  return {
96
110
  detail: "busy"
97
111
  }
@@ -111,8 +125,21 @@ exports.delete_member_batch = async function(clientid, arr, longtime) {
111
125
  var res = await this.push("delete_face", clientid, {
112
126
  "per_id": customId,
113
127
  "type": 0
114
- });
115
- if (res.message == "ACK") {
128
+ }, 10000);
129
+ if (!res) {
130
+ await this.sleep(60000);
131
+ res = await this.push("delete_face", clientid, {
132
+ "per_id": customId,
133
+ "type": 0
134
+ }, 10000);
135
+ }
136
+ if (!res) {
137
+ error_info.push({
138
+ customId,
139
+ errcode: -1,
140
+ time_create: now
141
+ });
142
+ } else if (res.message == "ACK") {
116
143
  success++;
117
144
  success_info.push({
118
145
  customId,
@@ -151,6 +178,9 @@ exports.delete_member_batch = async function(clientid, arr, longtime) {
151
178
  */
152
179
  exports.reboot_device = async function(clientid) {
153
180
  var res = await this.push("reboot_cam", clientid, {});
181
+ if (!res) {
182
+ return "请求超时!"
183
+ }
154
184
  if (res.message !== "ACK") {
155
185
  return res.code;
156
186
  }
@@ -167,6 +197,9 @@ exports.set_device_time = async function(clientid, datetime) {
167
197
  "datetime": datetime
168
198
  }
169
199
  });
200
+ if (!res) {
201
+ return "请求超时!"
202
+ }
170
203
 
171
204
  if (res.message !== "ACK") {
172
205
  return res.code;
@@ -198,7 +231,7 @@ exports.reset_device = function(clientid, record = true, member = false, log = t
198
231
  * 查询下发进度(未完成)
199
232
  * @param {String} clientid 设备sn
200
233
  */
201
- exports.get_progress = function(clientid) {
234
+ exports.get_progress = async function(clientid) {
202
235
  if (!this.drives[clientid]) {
203
236
  this.drives[clientid] = {};
204
237
  }
@@ -281,6 +314,9 @@ exports.get_member = async function(clientid, uuid, name) {
281
314
  qy.name = name;
282
315
  }
283
316
  var res = await this.push("query_face", qy);
317
+ if (!res) {
318
+ return "请求超时!"
319
+ }
284
320
  if (res.code) {
285
321
  return res.pers_id;
286
322
  }
@@ -339,6 +375,9 @@ exports.member_model_out = function(m) {
339
375
  exports.update_member = async function(clientid, user) {
340
376
  var member = this.member_model_out(user);
341
377
  var res = await this.push("update_face_ex", clientid, member);
378
+ if (!res) {
379
+ return "请求超时!"
380
+ }
342
381
  if (res.message !== "ACK") {
343
382
  return res.code;
344
383
  }
@@ -355,7 +394,7 @@ exports.update_member_batch = async function(clientid, list, longtime = 0) {
355
394
  if (!this.drives[clientid]) {
356
395
  this.drives[clientid] = {};
357
396
  }
358
- if (this.drives[clientid].pushing == 1) {
397
+ if (this.drives[clientid].pushing) {
359
398
  return {
360
399
  detail: "busy"
361
400
  }
@@ -372,8 +411,18 @@ exports.update_member_batch = async function(clientid, list, longtime = 0) {
372
411
  var now = new Date().toStr("yyyy-MM-dd hh:mm:ss");
373
412
  for (var i = 0; i < list.length; i++) {
374
413
  var user = list[i];
375
- var res = await this.push("update_face_ex", clientid, this.member_model_out(user));
376
- if (res.message == "ACK") {
414
+ var res = await this.push("update_face_ex", clientid, this.member_model_out(user), 10000);
415
+ if (!res) {
416
+ await this.sleep(60000);
417
+ res = await this.push("update_face_ex", clientid, this.member_model_out(user), 10000);
418
+ }
419
+ if (!res) {
420
+ error_info.push({
421
+ customId: user.customId,
422
+ errcode: -1,
423
+ time_create: now
424
+ });
425
+ } else if (res.message == "ACK") {
377
426
  success++;
378
427
  success_info.push({
379
428
  customId: user.customId,
@@ -434,6 +483,9 @@ exports.play_audio = async function(clientid, type = 3) {
434
483
  body
435
484
  });
436
485
 
486
+ if (!res) {
487
+ return "请求超时!"
488
+ }
437
489
  if (res.message !== "ACK") {
438
490
  return res.code;
439
491
  }
@@ -452,6 +504,9 @@ exports.set_qrcode_mode = async function(clientid, mode = 1) {
452
504
  mode
453
505
  }
454
506
  });
507
+ if (!res) {
508
+ return "请求超时!"
509
+ }
455
510
  if (res.message !== "ACK") {
456
511
  return res.code;
457
512
  }
@@ -469,6 +524,9 @@ exports.send_led = async function(clientid, color = 1) {
469
524
  color
470
525
  }
471
526
  });
527
+ if (!res) {
528
+ return "请求超时!"
529
+ }
472
530
  if (res.message !== "ACK") {
473
531
  return res.code;
474
532
  }
@@ -14,7 +14,9 @@
14
14
  // 给客户端推送的主题
15
15
  "topic_push": "face/${clientid}/request",
16
16
  // 接收方式
17
- "qos": 2,
17
+ "qos": 1,
18
+ // 推送方式
19
+ "qos_push": 0,
18
20
  // 保持接收
19
21
  "retain": true,
20
22
  // 调用的脚本
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_os",
3
- "version": "2.4.3",
3
+ "version": "2.4.5",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -48,7 +48,7 @@
48
48
  "mm_redis": "^1.4.2",
49
49
  "mm_ret": "^1.3.9",
50
50
  "mm_session": "^1.4.8",
51
- "mm_statics": "^1.4.2",
51
+ "mm_statics": "^1.4.8",
52
52
  "mm_tpl": "^2.3.9",
53
53
  "mm_xml": "^1.1.5",
54
54
  "mosca": "^2.8.3",