ws-asyncapi API / client / WsClient
Interface: WsClient<T>
Defined in: .api-entries/client/index.d.ts:111
The fully-typed client surface, parameterized by a channel's maps. Returned by createClient<typeof channel>() (codegen-free) and structurally identical to what websocketAsyncAPI returns for a CLI-generated channel.
Type Parameters
T
T extends object
Properties
~original
readonly~original:WebSocket
Defined in: .api-entries/client/index.d.ts:131
the underlying browser WebSocket (current connection)
connected
readonlyconnected:boolean
Defined in: .api-entries/client/index.d.ts:132
sessionId
readonlysessionId:string
Defined in: .api-entries/client/index.d.ts:134
server-assigned session id (stable across reconnects)
recovered
readonlyrecovered:boolean
Defined in: .api-entries/client/index.d.ts:136
whether the most recent (re)connect recovered missed events
opened
readonlyopened:Promise<void>
Defined in: .api-entries/client/index.d.ts:138
resolves once the first connection opens
presence
presence:
PresenceApi<T["presenceState"]>
Defined in: .api-entries/client/index.d.ts:166
Typed presence: announce this connection's state, observe the room roster, or leave. Available when the channel declares .presence(...). Join/leave/ update changes are delivered as diffs and reconciled into a live roster; the last announced state is re-sent automatically after a reconnect.
Methods
onOpen()
onOpen(
callback): () =>void
Defined in: .api-entries/client/index.d.ts:139
Parameters
callback
(event) => void
Returns
() => void
onClose()
onClose(
callback): () =>void
Defined in: .api-entries/client/index.d.ts:140
Parameters
callback
(event) => void
Returns
() => void
onError()
onError(
callback): () =>void
Defined in: .api-entries/client/index.d.ts:141
Parameters
callback
(event) => void
Returns
() => void
onRecover()
onRecover(
callback): () =>void
Defined in: .api-entries/client/index.d.ts:142
Parameters
callback
(recovered) => void
Returns
() => void
onEvent()
onEvent<
E>(event,callback): () =>void
Defined in: .api-entries/client/index.d.ts:143
Type Parameters
E
E extends string | number | symbol
Parameters
event
E
callback
(data) => void
Returns
() => void
onRequest()
onRequest<
N>(name,handler): () =>void
Defined in: .api-entries/client/index.d.ts:145
Answer a server→client RPC: receive the server's input, return output.
Type Parameters
N
N extends string | number | symbol
Parameters
name
N
handler
(input) => T["serverRpcMap"][N]["output"] | Promise<T["serverRpcMap"][N]["output"]>
Returns
() => void
call()
call<
C>(command, ...data):void
Defined in: .api-entries/client/index.d.ts:146
Type Parameters
C
C extends string | number | symbol
Parameters
command
C
data
...T["commandMap"][C] extends never ? [] : [T["commandMap"][C]]
Returns
void
request()
request<
C>(command,input,options?):Promise<T["rpcMap"][C]["output"]>
Defined in: .api-entries/client/index.d.ts:147
Type Parameters
C
C extends string | number | symbol
Parameters
command
C
input
T["rpcMap"][C]["input"]
options?
Returns
Promise<T["rpcMap"][C]["output"]>
safeRequest()
safeRequest<
C>(command,input,options?):Promise<SafeResult<T["rpcMap"][C]["output"],T["rpcMap"][C]["errors"]>>
Defined in: .api-entries/client/index.d.ts:148
Type Parameters
C
C extends string | number | symbol
Parameters
command
C
input
T["rpcMap"][C]["input"]
options?
Returns
Promise<SafeResult<T["rpcMap"][C]["output"], T["rpcMap"][C]["errors"]>>
stream()
stream<
N>(name,input):AsyncIterable<T["streamMap"][N]["output"]>
Defined in: .api-entries/client/index.d.ts:151
Open a typed stream; consume with for await. Stopping iteration cancels it server-side; a server error throws an RpcError into the loop.
Type Parameters
N
N extends string | number | symbol
Parameters
name
N
input
T["streamMap"][N]["input"]
Returns
AsyncIterable<T["streamMap"][N]["output"]>
authenticate()
authenticate(
credentials):Promise<void>
Defined in: .api-entries/client/index.d.ts:159
Refresh credentials on the live connection (token refresh) — the server re-runs its .onAuth handler and replaces the connection context without a reconnect. Resolves once accepted; rejects with a typed RpcError if the server rejects the credentials. The last credentials passed are re-sent automatically after a reconnect, so the refreshed identity survives drops.
Parameters
credentials
T["authCredentials"]
Returns
Promise<void>
history()
history(
room,options?):Promise<HistoryEntry<T["eventMap"]>[]>
Defined in: .api-entries/client/index.d.ts:173
Fetch a room's retained recent events (history / rewind) — e.g. the chat backlog when opening a room. Returns a typed, discriminated list (narrow on entry.event). Only rooms this connection is subscribed to are readable. Requires .history(event) on the server; otherwise resolves to [].
Parameters
room
string
options?
limit?
number
Returns
Promise<HistoryEntry<T["eventMap"]>[]>
close()
close(
code?,reason?):void
Defined in: .api-entries/client/index.d.ts:176
Parameters
code?
number
reason?
string
Returns
void