-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
77 lines (70 loc) · 2.09 KB
/
node_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var NodeHelper = require("node_helper");
const WebSocket = require('ws');
module.exports = NodeHelper.create({
// ws_action: function(){
// //ws = new ReconnectingWebSocket("ws://192.168.31.232:16666/");
// ws = new ReconnectingWebSocket("ws://192.168.31.232:16666/");
// var that = this;
// ws.onopen = function(){
// ws.send("START");
// console.log("[DB] WebSocket Opened.");
// };
// ws.onmessage = function(event){
// console.log("[DB] Got message: ", event.data);//字符串拼接
// if(event.data.slice(0,9) == "IS_A_FACE"){
// that.sendSocketNotification("IS_A_FACE", payload=event.data.slice(10));
// }
// else if(event.data == "RUNING"){
// that.sendSocketNotification("RUNING");
// }
// };
// ws.onclose = function(){
// console.log('[DB] Websocket Closed.');
// that.sendSocketNotification("CLOSE");
// };
// ws.onerror = function(){
// console.log('[DB] Websocket Error.');
// }
// },
ws_action: function() {
ws = new WebSocket('ws://192.168.31.232:16666/', {
perMessageDeflate: false
});
var that = this;
ws.on('open', function open() {
ws.send("START");
console.log("[DB] WebSocket Opened.");
});
ws.on('message', function incoming(data) {
console.log("[DB] Got message: ", data);//字符串拼接
if(data.slice(0,9) == "IS_A_FACE"){
that.sendSocketNotification("IS_A_FACE", data.slice(10));
}
else if(data == "RUNING"){
that.sendSocketNotification("RUNING");
}
});
ws.on('close', function close() {
console.log('[DB] Websocket Closed. try to reconnect');
that.sendSocketNotification("CLOSE");
setTimeout(function() {
that.ws_action();
}, 1000);
});
ws.on('error', function error() {
console.log('[DB] Websocket Error. try to reconnect');
ws.close();
});
},
socketNotificationReceived: function(notification, payload) {
if(notification == "SHOWED") {
//收到暂时完成
console.log("try to send start");
ws.send("START");//发送socket让识别重新开始
}
else if(notification == "READY") {
this.ws_action();
console.log("[DB] READY");
}
},
});