-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
59 lines (51 loc) · 1.85 KB
/
app.js
File metadata and controls
59 lines (51 loc) · 1.85 KB
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
const express = require('express');
const app = new express();
const server = require("http").createServer(app);
const io = require('socket.io')(server);
var port = process.env.PORT || 5000;
server.listen(port, () => {
console.log("express server is listening on port " + port);
});
let finger = 0;
var window_count = -1;
var LED_count = -1;
io.sockets.on("connection", function(socket) {
console.log("[connect client] " + socket.id);
socket.on("finger_number", function(data){
console.log("finger_number socket connect");
console.log("data.numbers: " + JSON.parse(data).numbers);
finger = JSON.parse(data).numbers;
if (finger == 1) { // 손가락 1일 경우
LED_count += 1;
var status = LED_count % 2; // LED status: 1(on)/0(off)
console.log("finger: " + finger + " status: " + status);
io.sockets.emit("finger_send", {
fingerNum : finger,
status: status
});
}
else if (finger == 2) { //손가락 2일 경우
window_count += 1;
var status = window_count % 2 ; // window status: 1(open)/0(close)
console.log("finger: " + finger + " status: " + status);
io.sockets.emit("finger_send", {
fingerNum : finger,
status: status
});
}
else if (finger == 3) {
var status = 0 ;
console.log("finger: " + finger + " status: " + status);
io.sockets.emit("finger_send", {
fingerNum : finger,
status: status
});
}
});
socket.on("test", function(data) {
console.log("test: " + data);
})
socket.on("disconnection",function(reason){
console.log(`disconnect id : ${socket.id} reason : ${reason}`);
})
});