-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (30 loc) · 1013 Bytes
/
server.js
File metadata and controls
46 lines (30 loc) · 1013 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
44
45
46
//Test Server
var express = require('express')();
var http = require('http');
var fs = require('fs');
var app = http.Server(express);
var io = require('socket.io')(app);
app.listen(9000, function(){
console.log('listening on 9000');
});
io.on('connection', function(socket){
console.log('Socket connected: ', socket.connected);
socket.on('signal', function(data){
console.log(socket.id, 'Forwarding to', data.to);
socket.broadcast.to( data.to ).emit('signal', { message:data, id:socket.id });
});
socket.on('join', function(data){
socket.join(data.room);
socket.myroom = data.room;
console.log('joined to room', data);
socket.broadcast.to( data.room ).emit('new-peer', { id:socket.id });
});
socket.on('disconnect', function(){
console.log('user disco', socket.id);
socket.broadcast.to( socket.myroom ).emit('peer-disconnect', { id:socket.id });
});
});
express.use('/', function(req,res){
console.log(req.url);
res.sendFile(req.url, {root:'./'});
});