-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
63 lines (51 loc) · 1.58 KB
/
app.js
File metadata and controls
63 lines (51 loc) · 1.58 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
60
61
62
63
/**
* Created by ETiV on 3/27/15.
*/
var path = require('path');
var config = require('./config');
var httpServer = require('http').createServer();
var io = require('socket.io')(httpServer);
var libSocketServer = require('./socket-server');
var sockets = config['sockets'] || [];
if (typeof sockets == 'object' && sockets.hasOwnProperty('length') && typeof sockets.forEach == 'function') {
sockets.forEach(function (socket) {
var path_socket = path.join(__dirname, 'sockets', socket.name + '.socket');
libSocketServer(path_socket, function (err, data) {
if (err == libSocketServer.SHOULD_EXIT) {
console.error('the socket is in use, program will exit ...');
setTimeout(function () {
process.exit();
}, 100);
return;
}
if (data) {
if (io.sockets.sockets.length > 0) {
io.sockets.emit('WEBLOG', {
string: Buffer.isBuffer(data) ? data.toString('utf8') : data,
socket: socket.name
});
}
}
});
});
}
io.on('connection', function (socket) {
console.log('new connection');
socket.on('disconnect', function () {
console.log('disconnected');
});
socket.on('req:sockets', function () {
socket.emit('resp:sockets', sockets);
});
});
httpServer.listen(config['socket.io']['port'], '127.0.0.1');
//process.on('exit', function () {
// console.log('process is about to exit');
//});
//
//process.on('SIGTERM', function () {
// console.log('process received SIGTERM');
//});
//process.on('SIGINT', function () {
// console.log('process received SIGINT');
//});