MCPcopy
hub / github.com/socketio/socket.io / sendPacket

Method sendPacket

packages/engine.io/lib/socket.ts:468–502  ·  view source on GitHub ↗

* Sends a packet. * * @param {String} type - packet type * @param {String} data * @param {Object} options * @param {Function} callback * * @private

(
    type: PacketType,
    data?: RawData,
    options: SendOptions = {},
    callback?: SendCallback,
  )

Source from the content-addressed store, hash-verified

466 * @private
467 */
468 private sendPacket(
469 type: PacketType,
470 data?: RawData,
471 options: SendOptions = {},
472 callback?: SendCallback,
473 ) {
474 if ("function" === typeof options) {
475 callback = options;
476 options = {};
477 }
478
479 if ("closing" !== this.readyState && "closed" !== this.readyState) {
480 debug('sending packet "%s" (%s)', type, data);
481
482 // compression is enabled by default
483 options.compress = options.compress !== false;
484
485 const packet: Packet = {
486 type,
487 options: options as { compress: boolean },
488 };
489
490 if (data) packet.data = data;
491
492 // exports packetCreate event
493 this.emit("packetCreate", packet);
494
495 this.writeBuffer.push(packet);
496
497 // add send callback to object, if defined
498 if ("function" === typeof callback) this.packetsFn.push(callback);
499
500 this.flush();
501 }
502 }
503
504 /**
505 * Attempts to flush the packets buffer.

Callers 6

onOpenMethod · 0.95
onPacketMethod · 0.95
schedulePingMethod · 0.95
sendMethod · 0.95
writeMethod · 0.95
onMessageFunction · 0.80

Calls 3

emitMethod · 0.95
flushMethod · 0.95
debugFunction · 0.85

Tested by

no test coverage detected