Callbacks don't work if broadcasted. #770

alexindigo opened this Issue Feb 29, 2012 · 2 comments


None yet
2 participants

When you do socket.broadcast.emit(..., callback) it stored in the socket object

  if ('function' == typeof lastArg) { = ++this.ackPackets;
    packet.ack = lastArg.length ? 'data' : true;
    this.acks[] = lastArg;
    args = args.slice(0, args.length - 1);

and broadcasted packets don't know about it;

after callbacks come

      if (socket.acks[packet.ackId]) {
        socket.acks[packet.ackId].apply(socket, packet.args);
      } else {'unknown ack packet');

they just being dropped.

So quick&dirty fix it I ended up doing following:

socket.js:209, ( in this.acks) ? this.acks[] : null);


SocketNamespace.prototype.packet = function (packet, callback) {
  packet.endpoint =;

  // it's dirty hack but fast one issue github:#770
  if (callback && this.manager.rooms[this.flags.endpoint]) {
    for (var i=0, l=this.manager.rooms[this.flags.endpoint].length; i<l; i++) {
      var id = this.manager.rooms[this.flags.endpoint][i];
      if (!~this.flags.exceptions.indexOf(id)) {
        this.manager.namespaces[this.flags.endpoint].sockets[id].acks[] = callback;

Let me know if you have any questions,
or want real pull request.


jcollum commented May 30, 2013

Well I'd like to see it in a pull request. I assumed a broadcast emit would have a callback, but apparently not. What did the owners say about it?

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment