-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
40 lines (34 loc) · 1.08 KB
/
server.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
37
38
39
var express = require('express')
, http = require('http')
, app = express()
;
app.use(express.static(__dirname + '/public'));
var server = http.createServer(app).listen(3000);
console.log('server start:', 3000);
var io = require('socket.io')
, io = io.listen(server)
;
videoChat = io.sockets.on('connection', function(socket) {
console.log("connect : " + socket);
socket.on('message', function(data){
var room;
console.log("recieve : " + data);
//socket.broadcast.emit('message', data);
socket.get('room', function(err, _room){
room = _room;
});
videoChat.to(room).emit('message', data);
});
//socket.on('disconnect', function(){
// console.log("discon : " + socket);
// socket.broadcast.emit("disconnect", socket);
// });
socket.on('roomId', function(data){
console.log("roomId : " + data);
socket.set('room', data);
videoChat.to(data).emit('rooomId', socket + 'さんが入室');
socket.join(data);
//socket.broadcast.emit('roomId', data);
videoChat.to(data).emit('roomId', socket + 'がきた');
});
});