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

Function flattenPayload

packages/socket.io-redis-streams-emitter/lib/index.ts:400–428  ·  view source on GitHub ↗
(message: ClusterMessage)

Source from the content-addressed store, hash-verified

398}
399
400function flattenPayload(message: ClusterMessage) {
401 const rawMessage = {
402 uid: message.uid,
403 nsp: message.nsp,
404 type: message.type.toString(),
405 data: undefined as string | undefined,
406 };
407
408 // @ts-expect-error
409 const data = message.data;
410
411 if (data) {
412 const mayContainBinary = [
413 MessageType.BROADCAST,
414 MessageType.FETCH_SOCKETS_RESPONSE,
415 MessageType.SERVER_SIDE_EMIT,
416 MessageType.SERVER_SIDE_EMIT_RESPONSE,
417 MessageType.BROADCAST_ACK,
418 ].includes(message.type);
419
420 if (mayContainBinary && hasBinary(data)) {
421 rawMessage.data = Buffer.from(encode(data)).toString("base64");
422 } else {
423 rawMessage.data = JSON.stringify(data);
424 }
425 }
426
427 return rawMessage;
428}
429
430export interface RedisStreamsEmitterOptions {
431 /**

Callers 1

publishMethod · 0.85

Calls 2

hasBinaryFunction · 0.90
encodeFunction · 0.50

Tested by

no test coverage detected