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 sendData = <dynamic>[event];
    if (data is ByteBuffer || data is List<int>) {
      sendData.add(data);
    } else if (data is Iterable) {
      sendData.addAll(data);
    } else if (data != null) {
      sendData.add(data);
    }

    var packet = {
      'type': binary ? BINARY_EVENT : EVENT,
      'data': sendData,
      'options': {
        'compress':
            flags != null && flags!.isNotEmpty == true && flags!['compress']
      }
    };

    // event ack callback
    if (ack != null) {
      _logger.fine('emitting packet with ack id $ids');
      acks['$ids'] = ack;
      packet['id'] = '${ids++}';
    }

    if (connected == true) {
      this.packet(packet);
    } else {
      sendBuffer.add(packet);
    }
    flags = null;
  }
}