Improve libility
This commit is contained in:
parent
06653deac7
commit
58c324ff42
1 changed files with 1 additions and 4 deletions
|
|
@ -28,22 +28,19 @@ app.use(cookieParser());
|
||||||
|
|
||||||
io.on('connection',socket => {
|
io.on('connection',socket => {
|
||||||
|
|
||||||
let users = {};
|
|
||||||
|
|
||||||
auth.getSession(socket.request, function(res){
|
auth.getSession(socket.request, function(res){
|
||||||
const getUsername = auth.getUsername(res);
|
const getUsername = auth.getUsername(res);
|
||||||
if (getUsername === -1) {
|
if (getUsername === -1) {
|
||||||
socket.send('error','not authenticated');
|
socket.send('error','not authenticated');
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
console.log(`${getUsername} joined the chat.`);
|
console.log(`${new Date()}] ${getUsername} joined the chat.`);
|
||||||
socket.broadcast.emit('general',[{
|
socket.broadcast.emit('general',[{
|
||||||
username: 'Server',
|
username: 'Server',
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
channel: 'general',
|
channel: 'general',
|
||||||
message: `${getUsername} joined the chat.`
|
message: `${getUsername} joined the chat.`
|
||||||
}]);
|
}]);
|
||||||
users[socket.id] = getUsername;
|
|
||||||
messages.find({}, {'_id':0},{sort: {'date':1}},(err, res) => {
|
messages.find({}, {'_id':0},{sort: {'date':1}},(err, res) => {
|
||||||
if(err) throw err;
|
if(err) throw err;
|
||||||
if(res.length > 0){
|
if(res.length > 0){
|
||||||
|
|
|
||||||
Reference in a new issue