-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
53 lines (44 loc) · 1.28 KB
/
app.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
var io = require('socket.io-client'),
candy = require('./candy');
var port = '80',
server = 'thing.everymote.com';
var connectCandy = function(thing){
console.log(thing);
var socket = io.connect('http://' + server + ':' + port + '/thing'
,{"force new connection":true
,'reconnect': true
,'reconnection delay': 5000
,'reconnection limit': 5000
,'max reconnection attempts': 10 });
socket.on('connect', function () {
console.log('connected');
socket.emit('setup', thing);
}).on('doAction', function (action) {
console.log(action);
if(action.id == "1"){
candy.relese(thing);
}else if(action.id == "2"){
candy.relese(thing);
candy.relese(thing);
}
}).on('connect_failed', function () {
console.log('error:' + socket );
}).on('disconnect', function () {
console.log('disconnected');
}).on('reconnect', function () {
console.log('reconnect');
}).on('reconnecting', function () {
console.log('reconnecting');
}).on('reconnect_failed', function () {
console.log('reconnect_failed');
});
};
var connectThings = function (things){
things.map(connectCandy);
};
candy.getThings(connectThings);
console.log("end");
process.on('uncaughtException', function(err){
console.log('Something bad happened: ' + err);
process.exit(0);
});