sendPacket method

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

Sends a packet.

@param {String} packet type. @param {String} data. @param {Object} options. @param {Function} callback function. @api private

Implementation

void sendPacket({type, data, options, EventHandler? callback}) {
  if ('closing' == readyState || 'closed' == readyState) {
    return;
  }

  options = options ?? {};
  options['compress'] = false != options['compress'];

  var packet = {'type': type, 'data': data, 'options': options};
  emit('packetCreate', packet);
  writeBuffer.add(packet);
  if (callback != null) once('flush', callback);
  flush();
}