-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
48 lines (39 loc) · 1.37 KB
/
app.js
File metadata and controls
48 lines (39 loc) · 1.37 KB
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
47
48
var express = require('express')
, app = express()
, http = require('http')
, server = http.createServer(app)
, io = require('socket.io').listen(server);
server.listen(8080);
io.sockets.on('connection', function (socket) {
socket.on('listen', function (data)
{
switch (data.listenType)
{
case 'ROOM':
socket.join(data.roomName);
console.log("joined to room:"+data.roomName)
break;
}
});
socket.on('socketEvent', function (data) {
switch(data.eventType)
{
case 'SEND':
socket.emit(data.eventName, data.data);
break;
case 'BROADCAST':
socket.broadcast.emit(data.eventName, data.data);
break;
case 'SEND_ALL':
io.sockets.emit(data.eventName, data.data);
break;
case 'SEND_TO_ROOM':
io.sockets.in(data.roomName).emit(data.eventName, data.data);
console.log(data.roomName+","+data.eventName+","+data.data);
break;
case 'BROADCAST_TO_ROOM':
socket.broadcast.to(data.roomName).emit(data.eventName, data.data);
break;
}
});
});