3

Here I am facing one issue with Callbacks in socket.io with nodejs

io.sockets.to(usersocketid).emit('receivemsg', 
{'success':'1','data':message},function(deliverycb){ 
    console.log('delivery call back');
    console.log(deliverycb);
});

Where i am facing error of Callbacks are not supported when broadcasting so anyone have solution of this.

Umang Kothari
  • 53
  • 2
  • 7

3 Answers3

0

Since you are using callback for acknowledgement,and according to socket.io documentation.

  1. Acknowledgements are not supported when broadcasting.
  2. Acknowledgements are not supported when emitting from namespace.

I would say, if you need to send acknowledgement to the server, then emit another event from the client-side.

0

First, get socket object from id, which you can refer to Socket.IO 1.0.x: Get socket by id

Then with the socket object, socket.emit('type', 'message', ack =>{});

Qiulang
  • 10,295
  • 11
  • 80
  • 129
0

It's possible you were trying to emit the acknoledgement from the server side, without specifying the socket.id;

By the way, you can avoid that error, moving the acknowledgement request to the clint-side and just work the callback on the server-side.