sendPacket method

void sendPacket(
  1. dynamic type, {
  2. dynamic data,
  3. dynamic options,
  4. dynamic callback,
})

Sends a packet.

Implementation

void sendPacket(type, {data, options, callback}) {
  options = options ?? {};
  options['compress'] = false != options['compress'];

  if ('closing' != readyState && 'closed' != readyState) {
//      _logger.fine('sending packet "%s" (%s)', type, data);

    var packet = {'type': type, 'options': options};
    if (data != null) packet['data'] = data;

    // exports packetCreate event
    emit('packetCreate', packet);

    writeBuffer.add(packet);

    // add send callback to object, if defined
    if (callback != null) packetsFn.add(callback);

    flush();
  }
}