|
@@ -202,7 +202,7 @@ io.use( async (socket, next) => {
|
|
|
const token = socket.handshake.auth.token;
|
|
|
const sockets = await io.fetchSockets();
|
|
|
if(!token) {
|
|
|
- console.log('socket disconnect')
|
|
|
+ console.log('token error - socket disconnect')
|
|
|
socket.disconnect();
|
|
|
return;
|
|
|
}
|
|
@@ -244,11 +244,11 @@ io.on("connection", async (socket) => {
|
|
|
|
|
|
|
|
|
|
|
|
- const users = [];
|
|
|
+ const usersInSocket = [];
|
|
|
for (let [id, socket] of io.of("/").sockets) {
|
|
|
|
|
|
const dbUser = await getOneUser(socket.user.userName)
|
|
|
- users.push({...dbUser._doc,socketId: id });
|
|
|
+ usersInSocket.push({...dbUser._doc,socketId: id });
|
|
|
}
|
|
|
|
|
|
|
|
@@ -267,8 +267,9 @@ io.on("connection", async (socket) => {
|
|
|
|
|
|
|
|
|
|
|
|
+console.log(usersInSocket.userName)
|
|
|
|
|
|
- io.emit('usersOnline', users);
|
|
|
+ io.emit('usersOnline', usersInSocket);
|
|
|
|
|
|
|
|
|
|
|
@@ -294,10 +295,6 @@ socket.emit('my chats', privateChats)
|
|
|
const messagesToShow = await Message.find({}).sort({ 'createDate': -1 }).limit(20).populate( {path:'user'});
|
|
|
socket.emit('allmessages', messagesToShow.reverse());
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
socket.on("message", async (data) => {
|
|
|
const dateNow = Date.now();
|
|
|
const post = await Message.findOne({userName}).sort({ 'createDate': -1 })
|