I've Implemented Node.js server side, and ios client side for sending pm message . But main issue , my code still acts like text message is broadcasting for all clients. ( I've tried on 3 phone, I just send e message to specific client , but message gone both clients and also mine phone which i sent that message )
My server code looks like that :
io.sockets.on('connection', function (socket) {
var userName;
var userSrcID;
socket.on('setUserName',function(user){
userName = user.name;
userSrcID = user.id;
clients[user.name] = socket;
clients[user.id] = socket;
console.log('data = ',user);
//io.sockets.emit('new user', user.name + " has joined.");
});
socket.on('message', function(msg){
io.sockets.emit('message', msg);
});
socket.on('pm', function(msg){
fromMsg = {from:userSrcID, txt:msg}
//clients[msg.to].emit('private message', fromMsg);
console.log('Gidicek username:',userName);
io.sockets.emit('new message',{msg: msg,destID:userSrcID});
I can build a condition that if that message's destionation user id is not belong my user id, do not show me but it will more like using Old-School HUB Network instead of switch :)
Any help will be appreciated
Best Regards ,