-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
46 lines (33 loc) · 1.25 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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');
});
io.on('connection', function (socket) {
socket.join(socket.handshake.query.room);
socket.on('channel_1', function (rData) {
socket.emit('channel_2', {
'socketId': socket.id,
'rooms': io.sockets.adapter.rooms,
'active': socket.handshake.query.room
});
//socket.broadcast.emit('msg', {'socketId': socket.id});
//io.emit('msg',{'socketId':socket.id});
});
socket.on('room_1_emit', function (rData) {
io.sockets.in('Room_1').emit('room_1_listen', 'Room_1 Emitted');
});
socket.on('room_2_emit', function (rData) {
io.sockets.in('Room_2').emit('room_2_listen', 'Room_2 Emitted');
});
socket.on('room_3_emit', function (rData) {
io.sockets.in('Room_3').emit('room_3_listen', 'Room_3 Emitted');
});
socket.on('room_all_emit', function (rData) {
io.sockets.in('Room_1').in('Room_2').in('Room_3').emit('room_all_listen', 'Room_1, Room_2, Room_3 Emitted');
});
});
http.listen(3000, function () {
console.log('listening on *:3000');
});