Skip to main content

Interface: RpcClientConfig

Defined in: packages/rpc/src/types.ts:189

Configuration options for creating an RPC client.

Example

import { createRpcClient, createWebSocketTransport } from '@lumenize/rpc';

const client = createRpcClient({
transport: createWebSocketTransport('MY_DO', 'instance-name')
});

Properties

clientId?

optional clientId: string

Defined in: packages/rpc/src/types.ts:211

Optional client identifier for tracking WebSocket connections on the server. Required when using downstream messaging (onDownstream handler). The server can use this to target specific clients when sending messages.


onClose()?

optional onClose: (code, reason) => void | Promise<void>

Defined in: packages/rpc/src/types.ts:263

Optional handler called when the WebSocket connection closes. Receives close code and reason, allowing the application to:

  • Handle authentication expiration (code 4401)
  • Refresh tokens and reconnect
  • Update UI to show disconnected state
  • Implement custom reconnection logic

Common close codes:

  • 1000: Normal closure
  • 1006: Abnormal closure (connection lost)
  • 4401: Custom code for authentication expired

Parameters

code

number

reason

string

Returns

void | Promise<void>

Example

const client = createRpcClient({
transport: createWebSocketTransport('MY_DO', 'instance'),
clientId: 'user-123',
onClose: async (code, reason) => {
if (code === 4401) {
// Authentication expired - refresh and reconnect
const newToken = await refreshToken();
// Create new client with fresh token
}
}
});

onDownstream()?

optional onDownstream: (payload) => void | Promise<void>

Defined in: packages/rpc/src/types.ts:233

Optional handler for downstream messages sent from the server. Receives deserialized payloads with full type support.

When provided:

  • Automatically enables keep-alive mode
  • Requires clientId to be set
  • Connection stays open and auto-reconnects

Parameters

payload

any

Returns

void | Promise<void>

Example

const client = createRpcClient({
transport: createWebSocketTransport('CHAT_ROOM', 'room-123'),
clientId: 'user-456',
onDownstream: (message) => {
console.log('New message:', message);
}
});

transport

transport: RpcTransport

Defined in: packages/rpc/src/types.ts:204

Transport instance for RPC communication. Use createWebSocketTransport() or createHttpTransport() for built-in transports, or provide your own RpcTransport implementation.

Example

import { createWebSocketTransport } from '@lumenize/rpc';

const client = createRpcClient({
transport: createWebSocketTransport('my-do', 'instance-1')
});