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
Mohit Kumar
  • 9,065
  • 2
  • 27
  • 43

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
  • 20,980
  • 9
  • 65
  • 83