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

Function broadcastWithAck

packages/socket.io-adapter/lib/cluster-adapter.ts:476–508  ·  view source on GitHub ↗
(
    packet: any,
    opts: BroadcastOptions,
    clientCountCallback: (clientCount: number) => void,
    ack: (...args: any[]) => void,
  )

Source from the content-addressed store, hash-verified

474 }
475
476 override broadcastWithAck(
477 packet: any,
478 opts: BroadcastOptions,
479 clientCountCallback: (clientCount: number) => void,
480 ack: (...args: any[]) => void,
481 ) {
482 const onlyLocal = opts?.flags?.local;
483 if (!onlyLocal) {
484 const requestId = randomId();
485
486 this.ackRequests.set(requestId, {
487 clientCountCallback,
488 ack,
489 });
490
491 this.publish({
492 type: MessageType.BROADCAST,
493 data: {
494 packet,
495 requestId,
496 opts: encodeOptions(opts),
497 },
498 });
499
500 // we have no way to know at this level whether the server has received an acknowledgement from each client, so we
501 // will simply clean up the ackRequests map after the given delay
502 setTimeout(() => {
503 this.ackRequests.delete(requestId);
504 }, opts.flags!.timeout);
505 }
506
507 super.broadcastWithAck(packet, opts, clientCountCallback, ack);
508 }
509
510 override async addSockets(opts: BroadcastOptions, rooms: Room[]) {
511 const onlyLocal = opts.flags?.local;

Callers

nothing calls this directly

Calls 4

encodeOptionsFunction · 0.85
broadcastWithAckMethod · 0.80
randomIdFunction · 0.70
publishMethod · 0.45

Tested by

no test coverage detected