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

Method send

packages/engine.io/lib/transports-uws/websocket.ts:41–70  ·  view source on GitHub ↗

* Writes a packet payload. * * @param {Array} packets * @private

(packets)

Source from the content-addressed store, hash-verified

39 * @private
40 */
41 send(packets) {
42 this.writable = false;
43
44 for (let i = 0; i < packets.length; i++) {
45 const packet = packets[i];
46 const isLast = i + 1 === packets.length;
47
48 const send = (data) => {
49 const isBinary = typeof data !== "string";
50 const compress =
51 this.perMessageDeflate &&
52 Buffer.byteLength(data) > this.perMessageDeflate.threshold;
53
54 debug('writing "%s"', data);
55 this.socket.send(data, isBinary, compress);
56
57 if (isLast) {
58 this.emit("drain");
59 this.writable = true;
60 this.emit("ready");
61 }
62 };
63
64 if (packet.options && typeof packet.options.wsPreEncoded === "string") {
65 send(packet.options.wsPreEncoded);
66 } else {
67 this.parser.encodePacket(packet, this.supportsBinary, send);
68 }
69 }
70 }
71
72 /**
73 * Closes the transport.

Callers

nothing calls this directly

Calls 3

debugFunction · 0.85
emitMethod · 0.65
sendFunction · 0.50

Tested by

no test coverage detected