Skip to content

Documentation / @super-line/client / Client

Type Alias: Client<C, R>

Client<C, R> = ClientMethods<C, R> & object

Defined in: packages/client/src/index.ts:64

A typed client proxy, narrowed to role R's effective surface (sharedR). Call requests as methods; listen with on; subscribe to topics with subscribe.

Type Declaration

connected

readonly connected: boolean

Whether the socket is currently open.

role

readonly role: R

This client's role.

close()

close(): void

Close the connection and stop reconnecting.

Returns

void

implement()

implement(handlers): void

Register handlers answering server→client requests. Throw a SocketError for a typed failure.

Parameters

handlers

ServerHandlers<C, R>

Returns

void

on()

on<E>(event, handler): () => void

Listen for a server-pushed event. Returns an unsubscribe function.

Type Parameters

E

E extends string | number | symbol

Parameters

event

E

handler

(data) => void

Returns

() => void

subscribe()

subscribe<T>(topic, handler): Subscription

Subscribe to a topic (auto re-subscribes on reconnect). Await .ready to confirm.

Type Parameters

T

T extends string | number | symbol

Parameters

topic

T

handler

(data) => void

Returns

Subscription

Type Parameters

C

C extends Contract

R

R extends RoleOf<C>

Released under the MIT License.