-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (27 loc) · 966 Bytes
/
index.js
File metadata and controls
36 lines (27 loc) · 966 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
// http://stackoverflow.com/questions/10058226/send-response-to-all-clients-except-sender-socket-io
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
// configuration
app.use(express.static('public'));
app.set('port', (process.env.PORT || 5000));
// route
app.get('/', function(req, res){
res.sendFile('index.html');
})
var handleClient = function(socket) {
console.log('a user connected, id: ' + socket.id);
socket.on('disconnect', function(){
console.log('user disconnected');
});
socket.on('signal_message', function(msg){
// broadcast to all the connected clients except the sender
socket.broadcast.emit('signal_message', msg);
console.log('signal_message: ' + msg);
});
};
io.on('connection', handleClient);
http.listen(app.get('port'), function(){
console.log('listening on *:' + app.get('port'));
});