# SocketRegistry

> Documentation for Redweb 0.16.1. Install that exact version when following these examples.

Small EventEmitter-backed list for socket-scoped entities (players, rooms, etc.). Emits `added` and `removed` events.

## Explain it like I’m five

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 API pattern illustrates the named surface; it may require application-owned classes, credentials, or assets. Start from a complete recipe for a runnable application.

```js
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`.

## What should I watch for?

This registry is unbounded and is not SocketRoute.clients. It does not automatically register connections, remove disconnected sockets, or drain them.
