emitWithAck method

void emitWithAck(
  1. String event,
  2. dynamic data, {
  3. Function? ack,
  4. bool binary = false,
})

Emits to this client.

@return {Socket} self @api public

Implementation

void emitWithAck(String event, dynamic data,
    {Function? ack, bool binary = false}) {
  if (EVENTS.contains(event)) {
    super.emit(event, data);
  } else {
    var packet = {};
    var sendData = data == null ? [event] : [event, data];

    var flags = this.flags ?? {};

    if (ack != null) {
      if (roomList.isNotEmpty || flags['broadcast'] == true) {
        throw UnsupportedError(
            'Callbacks are not supported when broadcasting');
      }

      acks['${nsp.ids}'] = ack;
      packet['id'] = '${nsp.ids++}';
    }

    packet['type'] = binary ? BINARY_EVENT : EVENT;
    packet['data'] = sendData;

    if (roomList.isNotEmpty || flags['broadcast'] == true) {
      adapter.broadcast(packet, {
        'except': [id],
        'rooms': roomList,
        'flags': flags
      });
    } else {
      // dispatch packet
      this.packet(packet,
          {'volatile': flags['volatile'], compress: flags['compress']});
    }

//      // reset flags
    roomList = [];
    this.flags = null;
//    }
//    return this;
  }
}