-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
71 lines (64 loc) · 2.08 KB
/
app.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var express = require('express'),
app = express(),
server = require('http').Server(app),
io = require('socket.io').listen(server);
server.listen(3001, function() {
console.log("3001");
});
//在线用户
var onlineUsers = {};
//在线用户服务对象
var onlineUsersSever = {};
app.get('/*', function(req, res) {
res.sendfile(__dirname + req.originalUrl);
});
io.sockets.on('connection', function(socket) {
socket.on("adminLogin", function(obj) {
socket.name = obj.userid;
if (!onlineUsers.hasOwnProperty(socket.debug)) {
onlineUsers[obj.debug] = [];
}
if (!onlineUsers[obj.debug][obj.userid]) {
onlineUsers[obj.debug].push(obj.userid);
onlineUsersSever[obj.userid] = socket;
}
})
socket.on("login", function(obj) {
socket.name = obj.userid;
if (obj.debug && onlineUsers[obj.debug]) {
var data = onlineUsers[obj.debug];
for (var i = data.length - 1; i >= 0; i--) {
var id = data[i];
console.log("login")
onlineUsersSever[id].emit("login", obj);
};
}
});
socket.on("log", function(obj) {
if (obj.debug && onlineUsers[obj.debug]) {
var data = onlineUsers[obj.debug];
for (var i = data.length - 1; i >= 0; i--) {
var id = data[i];
onlineUsersSever[id].emit("log", obj);
};
}
})
socket.on("info", function(obj) {
if (obj.debug && onlineUsers[obj.debug]) {
var data = onlineUsers[obj.debug];
for (var i = data.length - 1; i >= 0; i--) {
var id = data[i];
onlineUsersSever[id].emit("info", obj);
};
}
})
socket.on("errer", function(obj) {
if (obj.debug && onlineUsers[obj.debug]) {
var data = onlineUsers[obj.debug];
for (var i = data.length - 1; i >= 0; i--) {
var id = data[i];
onlineUsersSever[id].emit("errer", obj);
};
}
})
});