Lesson

Close Multiple WebSocket Clients with MSW

Close multiple connected WebSocket clients at once using Mock Service Worker.

Access
Included
Transcript
Needs source

Event handlers in MSW represent a WebSocket server. And it so happened a single server may manage a communication across multiple clients. Let's see how we can close multiple WebSocket client connections at once!

We can get access to the set of all connected WebSocket clients in the chat.clients property. From then, it's a matter of iterating over them and calling client.close() on individual clients.

Resources