| 398 | } |
| 399 | |
| 400 | function 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 | |
| 430 | export interface RedisStreamsEmitterOptions { |
| 431 | /** |