-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
49 lines (38 loc) · 1.1 KB
/
index.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
var sio = require('socket.io');
var ss = require('socket.io-stream');
path = require('path');
const fs = require('fs');
var forwarded = require('forwarded-for');
var debug = require('debug')('fastslam:io');
process.title = 'fastslam-io';
var port = process.env.PORT || 3000;
module.exports.listen = function(app) {
io = sio.listen(app);
debug('listening on *:' + port);
io.total = 0;
io.on('connection', function(socket){
var fastslam = require('./fastslam');
var tid=-1, src;
var req = socket.request;
var ip = forwarded(req);
debug('New connection from ' + ip.ip);
debug('total: '+(++io.total));
//var ip = req.connection.remoteAddress;
debug('client ip %s',ip.ip);
debug('client ip %s', req.connection.remoteAddress);
ss(socket).on('setup-stream', function(stream) {
debug('setup-stream');
[tid, src] = fastslam.instream();
src.pipe(stream);
})
socket.on('disconnect', function(){
if (tid!=-1) {
fastslam.killthread(tid);
tid=-1;
}
debug('user disconnected.');
--io.total;
});
});
return io;
}