io.to(testSocketId).emit('updatedDialog', 'you and I') is not working
Hi! I think there is a BUG! I cant send private message to the user with some id.
server.js
socket.on('updateDialog', data => {
console.log('receiver: ', data.receiverId);
let details = {"id": data.id};
let chats = {id: data.id, dialog: data.dialog};
// let socketID = "5bd04d61a9f6ddd0cc23e51b";
// console.log(someTestData);
database.collection('onlineUsers').findOne({"userId": data.receiverId}, (err, item)=> {
if (err) {
res.send(err);
}
testSocketId = item.socketId;
if(data.id) {
database.collection('chats').update(details, chats, (err, item)=>{
if (err){
console.log('error');
} else {
console.log('testSocketId: ', testSocketId);
io.to(testSocketId).emit('updatedDialog', 'you and I');
}
});
} else {
console.log('error');
}
});
});
client.ts
this._chatService.socket.on('updatedDialog', (data) => {
console.log(data);
this.readyToReply();
});
If i replace the io.to(testSocketId).emit('updatedDialog', 'you and I') with io.to(socket.id).emit('updatedDialog', 'you and I') it works pretty well(message 'you and I' appears on my console). My socket.io version: "socket.io": "^2.2.0"
Still the same till this day, had to use io.to(${someId}) like so or make an obj like const socket = { id: someId } and then io.to(socket.id)
forgot the backtics io.to(${someId}) ...
@JoseGabriel-web I tried using a template string like that, but it still didn't work, could you maybe give an example?
I have tried io.to(socket.id).emit(), I have even tried every other one, it is =still not working
@blackgik are you able to reproduce with a basic example? (you can fork the project here)