feat: broadcast and expect multiple acks

Syntax:

```js
io.timeout(1000).emit("some-event", (err, responses) => {
  // ...
});
```

The adapter exposes two additional methods:

- `broadcastWithAck(packets, opts, clientCountCallback, ack)`

Similar to `broadcast(packets, opts)`, but:

* `clientCountCallback()` is called with the number of clients that
  received the packet (can be called several times in a cluster)
* `ack()` is called for each client response

- `serverCount()`

It returns the number of Socket.IO servers in the cluster (1 for the
in-memory adapter).

Those two methods will be implemented in the other adapters (Redis,
Postgres, MongoDB, ...).

Related:

- https://github.com/socketio/socket.io/issues/1811
- https://github.com/socketio/socket.io/issues/4163
- https://github.com/socketio/socket.io-redis-adapter/issues/445
This commit is contained in:
Damien Arrachequesne
2022-03-31 07:36:41 +02:00
parent 0b7d70ca42
commit 8b204570a9
8 changed files with 238 additions and 16 deletions

View File

@@ -50,7 +50,7 @@
"base64id": "~2.0.0",
"debug": "~4.3.2",
"engine.io": "~6.1.2",
"socket.io-adapter": "~2.3.3",
"socket.io-adapter": "~2.4.0",
"socket.io-parser": "~4.0.4"
},
"devDependencies": {