|
14 | 14 | * |
15 | 15 | * A WsServer listens to any path, allowing an app to have the concept of |
16 | 16 | * distinct 'rooms' that only certain clients are participating in. As soon as a |
17 | | - * single client connects to a new path, this listener will be called with a |
18 | | - * GetIdChanges callback that you can use to determine its Id. |
| 17 | + * single client connects to a new path, this listener will be called with the |
| 18 | + * Id of the new path and an `addedOrRemoved` value of `1`. |
19 | 19 | * |
20 | | - * When the final client disconnects from a path, it will be called again with a |
21 | | - * GetIdChanges callback that you can again use to determine its Id. |
| 20 | + * When the final client disconnects from a path, it will be called again with |
| 21 | + * the Id of the deactivated path and an `addedOrRemoved` value of `-1`. |
22 | 22 | * |
23 | 23 | * A PathIdsListener is provided when using the addPathIdsListener method. See |
24 | 24 | * that method for specific examples. |
25 | 25 | * @param wsServer A reference to the WsServer. |
26 | | - * @param getIdChanges A function that returns information about the path Id |
27 | | - * change. |
| 26 | + * @param pathId The Id of the path being added or removed. |
| 27 | + * @param addedOrRemoved Whether the path was added (`1`) or removed (`-1`). |
28 | 28 | * @category Listener |
29 | | - * @since v5.0.0 |
| 29 | + * @since v5.0.3 |
30 | 30 | */ |
31 | 31 | /// PathIdsListener |
32 | 32 | /** |
|
35 | 35 | * |
36 | 36 | * A WsServer listens to any path, allowing an app to have the concept of |
37 | 37 | * distinct 'rooms' that only certain clients are participating in. As soon as a |
38 | | - * new client connects to a path, this listener will be called with a |
39 | | - * GetIdChanges callback that you can use to determine its Id. |
| 38 | + * new client connects to a path, this listener will be called with the Id of |
| 39 | + * the path, the Id of the new client, and an `addedOrRemoved` value of `1`. |
40 | 40 | * |
41 | | - * When the client disconnects from a path, it will be called again with a |
42 | | - * GetIdChanges callback that you can again use to determine its Id. |
| 41 | + * When the client disconnects from a path, it will be called again with the Id |
| 42 | + * of the path, the Id of the leaving client, and an `addedOrRemoved` value of |
| 43 | + * `-1`. |
43 | 44 | * |
44 | 45 | * A ClientIdsListener is provided when using the addClientIdsListener method. |
45 | 46 | * See that method for specific examples. |
46 | 47 | * @param wsServer A reference to the WsServer. |
47 | 48 | * @param pathId The path that the client joined or left. |
48 | | - * @param getIdChanges A function that returns information about the client Id |
49 | | - * change. |
| 49 | + * @param clientId The Id of the client being added or removed. |
| 50 | + * @param addedOrRemoved Whether the client was added (`1`) or removed (`-1`). |
50 | 51 | * @category Listener |
51 | | - * @since v5.0.0 |
| 52 | + * @since v5.0.3 |
52 | 53 | */ |
53 | 54 | /// ClientIdsListener |
54 | 55 | /** |
|
228 | 229 | * import {createWsSynchronizer} from 'tinybase/synchronizers/synchronizer-ws-client'; |
229 | 230 | * |
230 | 231 | * const server = createWsServer(new WebSocketServer({port: 8047})); |
231 | | - * const listenerId = server.addPathIdsListener((server, getIdChanges) => { |
232 | | - * console.log(getIdChanges()); |
233 | | - * console.log(server.getPathIds()); |
234 | | - * }); |
| 232 | + * const listenerId = server.addPathIdsListener( |
| 233 | + * (server, pathId, addedOrRemoved) => { |
| 234 | + * console.log(pathId + (addedOrRemoved == 1 ? ' added' : ' removed')); |
| 235 | + * console.log(server.getPathIds()); |
| 236 | + * }, |
| 237 | + * ); |
235 | 238 | * |
236 | 239 | * const synchronizer1 = await createWsSynchronizer( |
237 | 240 | * createMergeableStore(), |
238 | 241 | * new WebSocket('ws://localhost:8047/roomA'), |
239 | 242 | * ); |
240 | | - * // -> {'roomA': 1} |
| 243 | + * // -> 'roomA added' |
241 | 244 | * // -> ['roomA'] |
242 | 245 | * |
243 | 246 | * const synchronizer2 = await createWsSynchronizer( |
244 | 247 | * createMergeableStore(), |
245 | 248 | * new WebSocket('ws://localhost:8047/roomB'), |
246 | 249 | * ); |
247 | | - * // -> {'roomB': 1} |
| 250 | + * // -> 'roomB added' |
248 | 251 | * // -> ['roomA', 'roomB'] |
249 | 252 | * |
250 | 253 | * synchronizer1.destroy(); |
251 | 254 | * // ... |
252 | | - * // -> {'roomA': -1} |
| 255 | + * // -> 'roomA removed' |
253 | 256 | * // -> ['roomB'] |
254 | 257 | * |
255 | 258 | * synchronizer2.destroy(); |
256 | 259 | * // ... |
257 | | - * // -> {'roomB': -1} |
| 260 | + * // -> 'roomB removed' |
258 | 261 | * // -> [] |
259 | 262 | * |
260 | 263 | * server.delListener(listenerId); |
|
0 commit comments