-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (27 loc) · 892 Bytes
/
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
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
app.get('/style.css', function(req, res) {
res.sendFile(__dirname + '/style.css');
});
io.on('connection', function(socket) {
socket.on('enter', function(name) {
socket.name = name;
socket.broadcast.emit('chat message', '--- ' + name + ' entered');
});
socket.on('disconnect', function() {
socket.broadcast.emit('chat message', '--- ' + socket.name + ' quit');
});
socket.on('chat message', function(msg) {
socket.broadcast.emit('chat message', socket.name + '> ' + msg);
});
socket.on('typing', function(is_typing) {
socket.broadcast.emit('typing', socket.name, is_typing);
});
});
http.listen(3000, function() {
console.log('listening on *:3000 ...');
});