Skip to content

Universal DevTools Kit SDK


Universal DevTools Kit SDK / @u-devtools/bridge / ViteRpcClient

Class: ViteRpcClient ​

Defined in: index.ts:9

Client-side RPC implementation (Browser) Works through import.meta.hot with fallback to WebSocket Uses Transport abstraction for communication

Constructors ​

Constructor ​

new ViteRpcClient(hot?, wsUrl?): ViteRpcClient

Defined in: index.ts:14

Parameters ​

ParameterType
hot?{ off?: (event, handler) => void; on: (event, handler) => void; send: (event, data) => void; }
hot.off?(event, handler) => void
hot.on?(event, handler) => void
hot.send?(event, data) => void
wsUrl?string

Returns ​

ViteRpcClient

Methods ​

call() ​

call<T>(method, payload?): Promise<T>

Defined in: index.ts:69

Call a method on the server

Type Parameters ​

Type ParameterDefault type
Tunknown

Parameters ​

ParameterTypeDescription
methodstringMethod name to call
payload?unknownOptional payload to send

Returns ​

Promise<T>

Promise with the method result


dispose() ​

dispose(): void

Defined in: index.ts:116

Clean up all handlers and subscriptions. Should be called on HMR dispose to prevent memory leaks.

Returns ​

void


off() ​

off(event, fn): void

Defined in: index.ts:105

Unsubscribe from events

Parameters ​

ParameterTypeDescription
eventstringEvent name to unsubscribe from
fn(data) => voidEvent handler function to remove

Returns ​

void


on() ​

on(event, fn): () => void

Defined in: index.ts:93

Subscribe to events (returns unsubscribe function)

Parameters ​

ParameterTypeDescription
eventstringEvent name to subscribe to
fn(data) => voidEvent handler function

Returns ​

Function to unsubscribe

(): void

Returns ​

void

Released under the MIT License.