mm_os 2.3.5 → 2.3.7

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.
@@ -304,8 +304,9 @@ Drive.prototype.pushS = function(clientid, msg, longtime) {
304
304
  * 更新设备在线
305
305
  * @param {String} clientid 客户端ID
306
306
  * @param {Boolean} online 是否在线 0为没在线 1为在线
307
+ * @param {String} ip 设备IP
307
308
  */
308
- Drive.prototype.update_online = async function(clientid, online = 1) {
309
+ Drive.prototype.update_online = async function(clientid, online = 1, ip = '') {
309
310
  if (!this.drives[clientid]) {
310
311
  this.drives[clientid] = {};
311
312
  }
@@ -320,6 +321,9 @@ Drive.prototype.update_online = async function(clientid, online = 1) {
320
321
  } = await $.server.check_device(clientid);
321
322
  if (device && online && !device.online) {
322
323
  device.online = online;
324
+ if (ip) {
325
+ device.ip = ip;
326
+ }
323
327
  }
324
328
  }
325
329
 
@@ -38,8 +38,10 @@ class MQTT extends Index {
38
38
  longtime: 15000,
39
39
  // 在线有效期时长判断 单位:毫秒,150000毫秒为2.5分钟
40
40
  online_expires: 150000,
41
+ // 在线有效期检测间隔
41
42
  online_interval: 10000,
42
- connectTimeout: 4000,
43
+ // 连接超时
44
+ connectTimeout: 6000,
43
45
  // maxInflight: 20,
44
46
  // 重连间隔
45
47
  // interval: 6000,
@@ -414,26 +416,21 @@ MQTT.prototype.reqASync = function(topic, method, params) {
414
416
  * 保存在线到数据库
415
417
  * @param {Array} arr 客户端ID数组
416
418
  * @param {Number} online 在线情况 0为不在线,1为在线
417
- * @param {Number} time_last 最后上线时间
418
419
  */
419
- MQTT.prototype.save_online = async function(arr, online, time_last) {
420
+ MQTT.prototype.save_online = async function(arr, online = 1) {
420
421
  if (!arr || !arr.length) {
421
422
  return
422
423
  }
423
424
  var body = {
424
425
  online
425
426
  }
426
- if (time_last) {
427
- body.time_last = time_last;
428
- // time_last = (new Date()).toStr('yyyy-MM-dd hh:mm:ss');
429
- }
430
427
  var sql = $.mysql_admin('sys');
431
428
  sql.open();
432
429
  var db = sql.db();
433
430
  db.table = "face_device";
434
431
  db.size = 0;
435
432
  await db.set({
436
- clientid_has: arr
433
+ clientid_has: arr.join(",")
437
434
  }, body);
438
435
  }
439
436
 
@@ -450,7 +447,7 @@ MQTT.prototype.update_online = async function() {
450
447
  var dict = list[i].drives;
451
448
  for (var clientid in dict) {
452
449
  var o = dict[clientid];
453
- if (!o.online) {
450
+ if (o.online === 0) {
454
451
  list_offline.push(clientid);
455
452
  } else {
456
453
  if (o.time_last) {
@@ -463,6 +460,9 @@ MQTT.prototype.update_online = async function() {
463
460
  list_online.push(clientid);
464
461
  }
465
462
  }
463
+ else {
464
+ list_online.push(clientid);
465
+ }
466
466
  }
467
467
  }
468
468
  }
@@ -37,13 +37,32 @@ exports.push_qrcode = function(clientid, param) {
37
37
  * @param {Object} avatar 人脸照片
38
38
  * @param {Number} longtime 超时回馈
39
39
  */
40
- exports.get_member_pic = function(clientid, avatar) {
41
- return this.push("GetPictureSearch", clientid, {
40
+ exports.get_member_pic = async function(clientid, avatar) {
41
+ var res = await this.push("GetPictureSearch", clientid, {
42
42
  "facesluiceId": clientid,
43
43
  "MaxSimilarity": 80,
44
44
  "MaxNum": 1,
45
45
  "picinfo": avatar
46
46
  });
47
+ var user;
48
+ if (res) {
49
+ if (res.result == "fail") {
50
+
51
+ } else {
52
+ var u = res.SearchInfo[0];
53
+ var name = u.name || u.persionName;
54
+ var customId = u.customId.trim();
55
+ var phone = (u.telnum || "").trim();
56
+ var idcard = (u.idCard || "").trim();
57
+ user = {
58
+ name,
59
+ customId,
60
+ phone,
61
+ idcard
62
+ }
63
+ }
64
+ }
65
+ return user
47
66
  }
48
67
 
49
68
  /**
@@ -53,13 +72,17 @@ exports.get_member_pic = function(clientid, avatar) {
53
72
  * @param {Boolean} pass 是否可通行 true为是
54
73
  * @param {String} tip 提示
55
74
  */
56
- exports.unlock = function(clientid, uuid = '0', pass = false, tip = '没有访问权限') {
57
- return this.push("Unlock", clientid, {
75
+ exports.unlock = async function(clientid, uuid = '0', pass = false, tip = '没有访问权限') {
76
+ var res = await this.push("Unlock", clientid, {
58
77
  "uid": uuid,
59
78
  // 0不开门,1开门
60
79
  "openDoor": pass ? "1" : "0",
61
80
  "showInfo": tip
62
81
  });
82
+
83
+ if (!res || res.result == "fail") {
84
+ return "非内部人员!";
85
+ }
63
86
  }
64
87
 
65
88
  /**
@@ -68,7 +91,7 @@ exports.unlock = function(clientid, uuid = '0', pass = false, tip = '没有访
68
91
  * @param {String} uuid 用户唯一标识
69
92
  * @param {Number} longtime 超时回馈
70
93
  */
71
- exports.del_member = function(clientid, uuid) {
94
+ exports.delete_member = function(clientid, uuid) {
72
95
  return this.push("DeletePersons", clientid, {
73
96
  "customId": uuid
74
97
  });
@@ -80,7 +103,7 @@ exports.del_member = function(clientid, uuid) {
80
103
  * @param {Object} arr 成员列表
81
104
  * @param {Number} longtime 超时回馈
82
105
  */
83
- exports.del_member_batch = function(clientid, arr, longtime) {
106
+ exports.delete_member_batch = function(clientid, arr, longtime) {
84
107
  return this.push("DeletePersons", clientid, {
85
108
  DataBegin: "BeginFlag",
86
109
  DataEnd: "EndFlag",
@@ -102,8 +125,8 @@ exports.reboot_device = function(clientid) {
102
125
  * @param {String} clientid 设备sn
103
126
  * @param {String} datetime 日期时间
104
127
  */
105
- exports.set_device_time = function(clientid, datetime) {
106
- var res = this.push("SetSysTime", clientid, {
128
+ exports.set_device_time = async function(clientid, datetime) {
129
+ var res = await this.push("SetSysTime", clientid, {
107
130
  "SysTime": datetime.replace(" ", "T")
108
131
  });
109
132
  if (!res || res.result == "ok") {
@@ -119,20 +142,42 @@ exports.set_device_time = function(clientid, datetime) {
119
142
  * @param {Boolean} member 是否恢复成员,true为恢复
120
143
  * @param {Boolean} log 是否恢复请求日志,true为恢复
121
144
  */
122
- exports.reset_device = function(clientid, record = true, member = false, log = true) {
123
- return this.push("SetFactoryDefault", clientid, {
145
+ exports.reset_device = async function(clientid, record = true, member = false, log = true) {
146
+ var res = await this.push("SetFactoryDefault", clientid, {
124
147
  DefaltRecord: record ? "1" : "0",
125
148
  DefaltPerson: member ? "1" : "0",
126
149
  DefaltLog: log ? "1" : "0"
127
150
  });
151
+
152
+ if (!res || res.result == "ok") {
153
+ return
154
+ }
155
+ return "恢复出厂设置失败"
128
156
  }
129
157
 
130
158
  /**
131
159
  * 查询下发进度
132
160
  * @param {String} clientid 设备sn
161
+ * @param {String} mode 查询方式 默认为更新
133
162
  */
134
- exports.get_progress = function(clientid) {
135
- return this.push("QueryProgress", clientid, {});
163
+ exports.get_progress = async function(clientid, mode = 'update') {
164
+ var type = "";
165
+ if (mode == 'update') {
166
+ type = "EditPersonsNew";
167
+ } else {
168
+ type = "DeletePersons";
169
+ }
170
+ var res = await this.push("QueryProgress", clientid, {
171
+ "QueryType": type
172
+ });
173
+ if (res) {
174
+ if (res.Status !== "0") {
175
+ return 1;
176
+ } else {
177
+ return 0;
178
+ }
179
+ }
180
+ return -1;
136
181
  }
137
182
 
138
183
  /**
@@ -141,8 +186,12 @@ exports.get_progress = function(clientid) {
141
186
  * @param {Object} param 其他信息
142
187
  * @param {Number} longtime 超时回馈
143
188
  */
144
- exports.replacement = function(clientid, param, longtime = 0) {
145
- return this.push("PullRecordOnlyName", clientid, param, longtime);
189
+ exports.replacement = function(clientid, uuid, time, avatar) {
190
+ return this.push("PullRecordOnlyName", clientid, {
191
+ "personID": uuid,
192
+ "time": time,
193
+ "picinfo": avatar
194
+ }, longtime);
146
195
  }
147
196
 
148
197
  /**
@@ -191,7 +240,9 @@ exports.member_model_out = function(m) {
191
240
  "cardType": 0,
192
241
  "picURI": this.fullUrl(m.avatar)
193
242
  }
194
- if (m.time_valid_end && m.time_valid_end > date && m.time_valid_end <= endDate) {
243
+
244
+ if (m.time_valid_end && m.time_valid_end > "2021-01-01 00:00:00".toTime() && m.time_valid_end <=
245
+ "2038-01-01 00:00:00".toTime()) {
195
246
  if (typeof(m.time_valid_start) == "object") {
196
247
  obj.cardValidBegin = m.time_valid_start.toStr("yyyy-MM-dd hh:mm:ss");
197
248
  } else {
@@ -215,17 +266,18 @@ exports.member_model_out = function(m) {
215
266
  * @param {Array} list 人员名单
216
267
  * @param {Number} longtime 超时回馈
217
268
  */
218
- exports.update_member_batch = function(clientid, list, longtime = 0) {
219
- return this.pushS(clientid, {
269
+ exports.update_member_batch = async function(clientid, list, longtime = 180) {
270
+ var res = await this.pushS(clientid, {
220
271
  "messageId": this.get_msgid('EditPersonsNew'),
221
272
  "DataBegin": "BeginFlag",
222
273
  "DataEnd": "EndFlag",
223
- "method": "EditPersonsNew",
274
+ "operator": "EditPersonsNew",
224
275
  "PersonNum": list.length,
225
276
  "info": list.map((o) => {
226
277
  return this.member_model_out(o);
227
278
  })
228
279
  }, longtime);
280
+ return res;
229
281
  }
230
282
 
231
283
  /**
@@ -257,7 +309,7 @@ exports.init = function() {
257
309
  }
258
310
  _this.drives[clientid].online = 1;
259
311
  _this.drives[clientid].time_last = new Date().getTime();
260
- console.log("心跳", clientid, _this.drives[clientid]);
312
+ // console.log("心跳", clientid, _this.drives[clientid]);
261
313
  }
262
314
 
263
315
  /**
@@ -266,10 +318,8 @@ exports.init = function() {
266
318
  * @param {Object} param 其他信息
267
319
  */
268
320
  m["Offline"] = async function(clientid, params) {
269
- if (_this.drives[clientid]) {
270
- _this.drives[clientid].online = 0;
271
- }
272
- console.log("离线", clientid, _this.drives[clientid]);
321
+ _this.update_online(clientid, 0);
322
+ // console.log("离线", clientid, _this.drives[clientid]);
273
323
  };
274
324
 
275
325
  /**
@@ -278,10 +328,13 @@ exports.init = function() {
278
328
  * @param {Object} param 其他信息
279
329
  */
280
330
  m["Online"] = async function(clientid, params) {
281
- if (!_this.drives[clientid]) {
282
- _this.drives[clientid] = {};
283
- }
284
- _this.drives[clientid].online = 1;
331
+ await _this.update_online(clientid, 1, params.ip);
332
+ return {
333
+ "facesluiceId": clientid,
334
+ "result": "ok",
335
+ "detail": ""
336
+ };
337
+ console.log("上线", clientid, _this.drives[clientid]);
285
338
  };
286
339
 
287
340
  m["RecPush"] = async function(clientid, params, msg, id) {
@@ -366,7 +419,7 @@ exports.init = function() {
366
419
  pass,
367
420
  tip,
368
421
  device
369
- } = $.server.exec_qrcode(clientid, qrcode);
422
+ } = await $.server.exec_qrcode(clientid, qrcode);
370
423
  if (device && device.online) {
371
424
  await _this.unlock(clientid, uuid, pass, tip);
372
425
  }
@@ -1,34 +1,24 @@
1
- {
2
- // 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
3
- "name": "DF",
4
- // mqtt 服务标题
5
- "title": "原设备",
6
- // mqtt 服务介绍
7
- "description": "",
8
- // 状态 0未启用,1启用
9
- "state": 1,
10
- // 订阅的主题
11
- "topic": ["mqtt/face/#"],
12
- // 主题回复
13
- "topic_receive": ["mqtt/face/${clientid}"],
14
- // 给客户端推送的主题
15
- "topic_push": "mqtt/face/${clientid}",
16
- // 接收方式
17
- "qos": 1,
18
- // 保持接收
19
- "retain": true,
20
- // 调用的脚本
21
- "func_file": "./index.js",
22
- // 客户端ID
23
- "clientid": "facesluiceId",
24
- // 消息ID
25
- "msgid": "messageId",
26
- // 请求方法
27
- "method": "operator",
28
- // 参数
29
- "params": "info",
30
- // 结果
31
- "result": "info",
32
- // 回复方法
33
- "method_receive": "${method}-Ack"
1
+ {
2
+ "name": "DF",
3
+ "title": "原设备",
4
+ "description": "",
5
+ "state": 1,
6
+ "topic": [
7
+ "mqtt/face/#"
8
+ ],
9
+ "topic_receive": [
10
+ "mqtt/face/${clientid}"
11
+ ],
12
+ "topic_push": "mqtt/face/${clientid}",
13
+ "qos": 2,
14
+ "qos_push": 2,
15
+ "retain": true,
16
+ "longtime": 10000,
17
+ "func_file": "./index.js",
18
+ "clientid": "facesluiceId",
19
+ "msgid": "messageId",
20
+ "method": "operator",
21
+ "params": "info",
22
+ "result": "info",
23
+ "method_receive": "${method}-Ack"
34
24
  }
@@ -53,11 +53,12 @@ exports.get_member_pic = function(clientid, avatar) {
53
53
  * @param {Boolean} pass 是否可通行 true为是
54
54
  * @param {String} tip 提示
55
55
  */
56
- exports.unlock = function(clientid, uuid = '0', pass = false, tip = '没有访问权限') {
57
- return this.push("gpio control", clientid, {
56
+ exports.unlock = async function(clientid, uuid = '0', pass = false, tip = '没有访问权限') {
57
+ var res = await this.push("gpio control", clientid, {
58
58
  // 0不开门,1开门
59
59
  "ctrl_type": pass ? "on" : "off"
60
60
  });
61
+ return res
61
62
  }
62
63
 
63
64
  /**
@@ -115,12 +116,13 @@ exports.reboot_device = function(clientid) {
115
116
  * @param {String} clientid 设备sn
116
117
  * @param {String} datetime 日期时间
117
118
  */
118
- exports.set_device_time = function(clientid, datetime) {
119
- return this.push("ss_set_timing", clientid, {
119
+ exports.set_device_time = async function(clientid, datetime) {
120
+ var res = await this.push("ss_set_timing", clientid, {
120
121
  "body": {
121
122
  "datetime": datetime
122
123
  }
123
124
  });
125
+ return
124
126
  }
125
127
 
126
128
  /**
@@ -149,7 +151,52 @@ exports.reset_device = function(clientid, record = true, member = false, log = t
149
151
  * @param {String} clientid 设备sn
150
152
  */
151
153
  exports.get_progress = function(clientid) {
152
- return this.push("QueryProgress", clientid, {});
154
+ // return this.push("QueryProgress", clientid, {});
155
+ }
156
+
157
+ /**
158
+ * 转换进入的消息
159
+ * @param {Object} push_topic
160
+ * @param {Object} msg
161
+ * @param {Object} topic
162
+ */
163
+ exports.convert_in = function(push_topic, msg, topic) {
164
+ var cg = this.config;
165
+ var method = msg[cg.method];
166
+ var json = {
167
+ clientid: "",
168
+ id: msg[cg.msgid] || this.get_msgid(method, 'client'),
169
+ method
170
+ };
171
+ if (msg[cg.params]) {
172
+ json.params = msg[cg.params];
173
+ }
174
+ if (msg[cg.result]) {
175
+ json.result = msg[cg.result];
176
+ }
177
+ json.clientid = this.get_clientid(push_topic, json.params || json.result || {}, msg, topic);
178
+
179
+ if (push_topic.indexOf("heartbeat") !== -1) {
180
+ json.method = "mqtt_heartbeat";
181
+ }
182
+ return json;
183
+ }
184
+
185
+ // exports.main = function(push_topic, params, msg, topic, index) {
186
+ // console.log(push_topic, params, msg, topic, index);
187
+ // }
188
+
189
+ /**
190
+ * 转换消息并推送
191
+ */
192
+ exports.push = function(method, clientid, params, longtime = 0) {
193
+ var cg = this.config;
194
+ var msg = {};
195
+ msg.client_id = clientid;
196
+ msg[cg.msgid] = this.get_msgid(method);
197
+ msg[cg.method] = method;
198
+ Object.assign(msg, params);
199
+ return this.pushS(clientid, msg);
153
200
  }
154
201
 
155
202
  /**
@@ -283,9 +330,14 @@ exports.play_audio = async function(clientid, type = 3) {
283
330
  break;
284
331
  }
285
332
  body.type = 0;
286
- var res = await this.push("trylisten_wav", clientid, body);
333
+ var res = await this.push("trylisten_wav", clientid, {
334
+ body
335
+ });
287
336
  }
288
337
 
338
+ // exports.convert_in = function(push_topic, msg, topic, index) {
339
+ // console.log("收到", push_topic, msg, topic, index);
340
+ // }
289
341
 
290
342
  /**
291
343
  * 初始化函数, 用于定义开放给前端的函数
@@ -299,6 +351,7 @@ exports.init = function() {
299
351
  _this.drives[clientid] = {};
300
352
  }
301
353
  _this.drives[clientid].online = 1;
354
+ _this.drives[clientid].time_last = new Date().getTime();
302
355
  console.log("心跳", clientid, _this.drives[clientid]);
303
356
  }
304
357
 
@@ -308,10 +361,8 @@ exports.init = function() {
308
361
  * @param {Object} param 其他信息
309
362
  */
310
363
  m["mqtt_online"] = async function(clientid, params) {
311
- if (!_this.drives[clientid]) {
312
- _this.drives[clientid] = {};
313
- }
314
- _this.drives[clientid].online = 1;
364
+ _this.update_online(clientid, 1);
365
+ console.log("上线", clientid, _this.drives[clientid]);
315
366
  };
316
367
 
317
368
  m["RecPush"] = async function(clientid, params, msg, id) {
@@ -414,14 +465,20 @@ exports.init = function() {
414
465
  pass,
415
466
  tip,
416
467
  device
417
- } = $.server.exec_qrcode(clientid, qrcode);
468
+ } = await $.server.exec_qrcode(clientid, qrcode);
469
+ console.log('扫码', qrcode, uuid,
470
+ pass,
471
+ tip,
472
+ device)
418
473
  if (device && device.online) {
419
- await _this.unlock(clientid, uuid, pass, tip);
474
+ console.log("看门", clientid.toLocaleUpperCase(), uuid, pass, tip);
475
+ await _this.unlock(clientid.toLocaleUpperCase(), uuid, pass, tip);
420
476
  }
421
-
422
477
  if (tip) {
423
- if (tip.indexOf("过期")) {
478
+ if (tip.indexOf("过期") !== -1) {
424
479
  _this.play_audio(clientid, 1);
480
+ } else if (tip.indexOf("通行") !== -1) {
481
+ // _this.play_audio(clientid, 3);
425
482
  } else {
426
483
  _this.play_audio(clientid, 2);
427
484
  }
@@ -8,13 +8,13 @@
8
8
  // 状态 0未启用,1启用
9
9
  "state": 1,
10
10
  // 订阅的主题
11
- "topic": ["face/response", "qr/response", "online/response", "heartbeat/response"],
11
+ "topic": ["face/+/response", "face/response", "qr/response", "online/response", "heartbeat/response"],
12
12
  // 主题回复
13
- "topic_receive": ["mqtt/face/${clientid}"],
13
+ "topic_receive": ["face/${clientid}/request", "face/request"],
14
14
  // 给客户端推送的主题
15
15
  "topic_push": "face/${clientid}/request",
16
16
  // 接收方式
17
- "qos": 1,
17
+ "qos": 2,
18
18
  // 保持接收
19
19
  "retain": true,
20
20
  // 调用的脚本
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_os",
3
- "version": "2.3.5",
3
+ "version": "2.3.7",
4
4
  "description": "这是超级美眉服务端框架,用于快速构建应用程序。",
5
5
  "main": "index.js",
6
6
  "scripts": {