-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsocketeer.js
36 lines (31 loc) · 915 Bytes
/
socketeer.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
var sio = require("socket.io"),
fs = require("fs");
function socketeer(server, site, app){
var io = sio(server);
io.set('log level', 1);
io.on('connection', function(socket){
console.log('connection opened');
var viewer = {socket: socket};
site.liveViewers.push(viewer);
socket.on('disconnect', function(){
site.liveViewers.splice(site.liveViewers.indexOf(viewer), 1);
});
});
fs.exists('socketscripts', function(exists){
if(exists){
fs.readdir('socketscripts', function(error, files){
for(var i in files){
if(files[i].indexOf('.js') !== -1){
try{
require('./socketscripts/' + files[i]).start(io, app);
}
catch(e){
console.log('error: ' + e);
}
}
}
});
}
});
}
exports.socketeer = socketeer;