Monday, 15 February 2010

javascript - Sending notification using node.js + socket.io -



javascript - Sending notification using node.js + socket.io -

i trying send notification using node.js + soket.io

on client side emit server listen

socket.emit('send server',{user_id:user_id,other_stuff:other_stuff})

on node

socket.on('send server',function(date){ socket.emit('notification_'+user_id,'test data'); });

on client side hear notification

socket.on("notification_<?php echo $_session['user_id'];?>",function(date){alert(data)});

problem doesn't send notification other user

if pass own user_id during emit "send server" returns myself if utilize other user_id (who logged in other borwser) doesn't send user.

please point how can send notification different user when action occur.

in case want send notification other users under same namespace:

socket.on('send server',function(data){ socket.broadcast('notification','test data'); })

only specific user (sockets.io 1.x)

socket.on('send server',function(data){ socketid = getsocketidfromuserid(user_id); io.to(socketid).emit('notification', 'test data'); })

there's no need bring together id name of listener on client side:

socket.on('notification',function(data){ alert(data) });

javascript jquery node.js push-notification socket.io

No comments:

Post a Comment