SocketRegistry
Small EventEmitter-backed list for socket-scoped entities (players, rooms, etc.). Emits `added` and `removed` events.
The simple mental model
SocketRegistry is a list with a doorbell: add or remove an item and interested code receives an event.
When should I use it?
Use it for simple application-managed collections with added/removed events. Use RoomRegistry for bounded socket membership or connectedClients for page projections.
Follow the example
This pattern explains the named API. Application classes, credentials, and assets may need to be supplied; use a complete recipe for a runnable starting point.
import { SocketRegistry } from 'redweb'
const players = new SocketRegistry()
players.on('added', player => console.log('Joined:', player.id))
players.add({ id: 'alice' })
players.remove('alice')- 1
add stores an item and emits added; duplicate items are not rejected.
- 2
remove matches an object by identity or an identifier by the chosen property, then emits removed.
- 3
all returns a shallow array copy. The application owns limits and cleanup.
Methods and members
add(item)
Stores the item and emits an `added` event.
remove(itemOrId, by = "id")
Remove by object reference or by matching a property (defaults to "id"); returns true when removal occurred and emits `removed`.
all()
Returns a shallow copy of all stored items.
count()
Convenience getter for `all().length`.