chat sender dont receive own messages

This commit is contained in:
lenovo
2022-11-30 17:52:39 +01:00
parent 55f77d2259
commit 9aec5bd015
7 changed files with 36 additions and 20 deletions

View File

@@ -11,6 +11,7 @@ const { Server } = require("socket.io");
// https://socket.io/docs/v4/handling-cors/
const io = new Server(server, {
cors: {
// change this for the real front origin
origin: "*"
}
});
@@ -24,7 +25,7 @@ const io = new Server(server, {
// console.log(req.headers);
//})
io.on('connection', function (socket) {
io.on('connection', (socket) => {
console.log('a user is connected');
@@ -34,7 +35,8 @@ io.on('connection', function (socket) {
socket.on('chat_message', function (msg) {
console.log('message received: ' + msg);
io.emit('chat_message', msg);
socket.broadcast.emit('chat_message', msg);
//io.emit('chat_message', msg);
})
});