diff --git a/package.json b/package.json index 0329b268..763afa0c 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "Ido Cohen (http://github.com/idoco)" ], "devDependencies": { - "webpack-bundle-analyzer": "^2.2.1", + "webpack-bundle-analyzer": "^3.9.0", "webpack-dev-server": "^3.1.11" }, "dependencies": { @@ -32,7 +32,7 @@ "compression": "^1.6.2", "cors": "^2.8.1", "dateformat": "^2.0.0", - "eslint": "^3.2.2", + "eslint": "^6.5.1", "express": "4.10.2", "preact": "^7.1.0", "request": "^2.79.0", diff --git a/server.js b/server.js index 28facee3..e0149c2d 100644 --- a/server.js +++ b/server.js @@ -29,7 +29,7 @@ app.post('/hook', function(req, res){ } else if (reply) { let replyText = reply.text || ""; let userId = replyText.split(':')[0]; - io.emit(chatId + "-" + userId, {name, text, from: 'admin'}); + io.to(userId).emit(chatId + "-" + userId, {name, text, from: 'admin'}); } else if (text){ io.emit(chatId, {name, text, from: 'admin'}); } @@ -42,22 +42,23 @@ app.post('/hook', function(req, res){ }); // handle chat visitors websocket messages -io.on('connection', function(client){ +io.on('connection', function(socket){ - client.on('register', function(registerMsg){ + socket.on('register', function(registerMsg){ let userId = registerMsg.userId; let chatId = registerMsg.chatId; let messageReceived = false; + socket.join(userId); console.log("useId " + userId + " connected to chatId " + chatId); - client.on('message', function(msg) { + socket.on('message', function(msg) { messageReceived = true; - io.emit(chatId + "-" + userId, msg); + io.to(userId).emit(chatId + "-" + userId, msg); let visitorName = msg.visitorName ? "[" + msg.visitorName + "]: " : ""; sendTelegramMessage(chatId, userId + ":" + visitorName + " " + msg.text); }); - client.on('disconnect', function(){ + socket.on('disconnect', function(){ if (messageReceived) { sendTelegramMessage(chatId, userId + " has left"); } diff --git a/src/chat/message-area.js b/src/chat/message-area.js index 5c17653a..47861aa3 100644 --- a/src/chat/message-area.js +++ b/src/chat/message-area.js @@ -19,7 +19,7 @@ export default class MessageArea extends Component {