-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
35 lines (27 loc) · 833 Bytes
/
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
var express = require('express');
var app = express();
var socketIO = require('socket.io')();
// var db = require('../models/db');
// db.connect();
var userList = [];
socketIO.on('connection', function(_socket) {
_socket.on('send-msg', function(chatInfo) {
var time = Date.now();
chatInfo.time = time;
if (chatInfo.user && chatInfo.content) {
_socket.broadcast.emit('user-say', chatInfo);
return _socket.emit('user-say', chatInfo);
}
});
_socket.on('user-login', function(user) {
if (user) {
userList.push(user);
_socket.broadcast.emit('user-join', user);
return _socket.emit('my-login', user);
}
});
});
exports.userList = userList;
exports.listen = function(server) {
socketIO.listen(server);
};