3

I am new to node.js i want to emit socket to specific socket id but i am getting Object #<Namespace> has no method 'socket' error. Here is my code:-

 var io = socketio.listen(app)
 io.sockets.on('connection', function (socket) {
    socket.on("user-typing", function (data) {
       io.sockets.socket(socket.id).emit('user-typing-start', "End Typing");//i am getting error here
    })
 });

I am using socket.io v1.0. i have already try this answer but not working:- This

Please help thanks in advance.

Community
  • 1
  • 1
Umesh Sehta
  • 10,555
  • 5
  • 39
  • 68

1 Answers1

3

The code you have provided does not work with Socket.IO 1.0

Instead you may try this solution:

io.to(socket.id).emit('user-typing-start', "End Typing");

or (if you have access to socket object like in your example):

socket.emit('user-typing-start', "End Typing");
Oleg
  • 22,300
  • 9
  • 68
  • 84