packet method
Writes a packet to the transport.
packet
packet object
opts
options
Implementation
void packet(packet, [Map? opts]) {
var self = this;
opts ??= {};
// this writes to the actual connection
void writeToEngine(encodedPackets) {
if (opts!['volatile'] != null && self.conn.transport.writable != true) {
return;
}
for (var i = 0; i < encodedPackets.length; i++) {
self.conn.write(encodedPackets[i], {'compress': opts['compress']});
}
}
if ('open' == conn.readyState) {
if (opts['preEncoded'] != true) {
// not broadcasting, need to encode
encoder.encode(packet, (encodedPackets) {
// encode, then write results to engine
writeToEngine(encodedPackets);
});
} else {
// a broadcast pre-encodes a packet
writeToEngine(packet);
}
}
}