chat sender dont receive own messages
This commit is contained in:
@@ -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);
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user