-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstream.js
More file actions
43 lines (31 loc) · 993 Bytes
/
Copy pathstream.js
File metadata and controls
43 lines (31 loc) · 993 Bytes
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
var fs = require('fs'),
request = require('request'),
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = 2086;
// chat template
app.get('/', function(req, res){
res.sendFile(__dirname + '/chat.html');
});
io.on('connection', function(socket){
// refresh how many are watching every 5000 ms
setInterval(function(){
socket.emit('count', Object.keys(io.sockets.connected).length);
}, 5000);
// if a chat is received, push it to everyone
socket.on('chat message', function(msg){
//console.log(msg);
var username;
if(msg.username === ""){
username = "Guest";
} else {
username = msg.username;
}
io.emit('chat message', {'msg': "<b>"+username+":</b> "+msg.msg,'count': Object.keys(io.sockets.connected).length });
});
});
//start app
http.listen(port, function(){
console.log('listening on *:' + port);
});