API reference
Client
| Member | Description |
|---|---|
new SocketClient(config, contracts, options?) | Builds the client. Throws on an invalid contract. |
createSocketClient(config, contracts, options?) | Same, and connects unless autoConnect: false. |
.modules | The generated surface — modules.<module>.<event>. |
.connect() / .disconnect() / .reconnect() | Connection control. connect() is idempotent. |
.destroy() | Disconnect and drop every handler, middleware and hook. |
.use(middleware) | Attach middleware. Returns a remover. |
.instrument(hook) | Attach an instrumentation hook. Returns a detacher. |
.onConnect/.onDisconnect/.onConnectError(fn) | Lifecycle subscriptions. Each returns an unsubscribe. |
.connected · .id · .raw · .queueSize · .events | Introspection. |
client->server events
| Member | Description |
|---|---|
(input, options?) | Validate and emit. Promise<Ack> when ack is declared, else void. |
.queue(input) | Validate now, send on the next connect. |
.eventId · .event · .def | Metadata for tooling. .def.permission carries the optional requirement. |
server->client events
| Member | Description |
|---|---|
.on(handler) / .once(handler) | Subscribe. Returns an unsubscribe. |
.off(handler) / .offAll() | Detach. |
.wait(options?) | Resolve on the next valid (optionally filtered) payload. |
.listenerCount | Live handler count. |
.eventId · .event · .def | Metadata for tooling. |
Contract helpers
defineSocketContracts · listSocketEvents · validateSocketContracts ·
isClientToServer · isServerToClient · makeEventId · resolveEventName