packet method

void packet(
  1. Map packet
)

Writes a packet.

@param {Object} packet @api private

Implementation

void packet(Map packet) {
  _logger.fine('writing packet $packet');
  if (packet.containsKey('query') && packet['type'] == 0) {
    packet['nsp'] += '''?${packet['query']}''';
  }

  if (encoding != true) {
    // encode, then write to engine with result
    encoding = true;
    encoder.encode(packet, (encodedPackets) {
      for (var i = 0; i < encodedPackets.length; i++) {
        engine.write(encodedPackets[i], packet['options']);
      }
      encoding = false;
      processPacketQueue();
    });
  } else {
    // add packet to the queue
    packetBuffer.add(packet);
  }
}