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

Method _encode

packages/socket.io-adapter/lib/in-memory-adapter.ts:234–256  ·  view source on GitHub ↗
(packet: unknown, packetOpts: Record<string, unknown>)

Source from the content-addressed store, hash-verified

232 }
233
234 private _encode(packet: unknown, packetOpts: Record<string, unknown>) {
235 const encodedPackets = this.encoder.encode(packet);
236
237 if (
238 canPreComputeFrame &&
239 encodedPackets.length === 1 &&
240 typeof encodedPackets[0] === "string"
241 ) {
242 // "4" being the "message" packet type in the Engine.IO protocol
243 const data = Buffer.from("4" + encodedPackets[0]);
244 // see https://github.com/websockets/ws/issues/617#issuecomment-283002469
245 // @ts-expect-error
246 packetOpts.wsPreEncodedFrame = WebSocket.Sender.frame(data, {
247 readOnly: false,
248 mask: false,
249 rsv1: false,
250 opcode: 1,
251 fin: true,
252 });
253 }
254
255 return encodedPackets;
256 }
257
258 /**
259 * Gets a list of sockets by sid.

Callers 2

broadcastMethod · 0.95
broadcastWithAckMethod · 0.95

Calls 1

encodeMethod · 0.65

Tested by

no test coverage detected