Skip to content

ServerProxy

Defined in: server.ts:414

Wraps a server-side API object to create a stateful, type-safe proxy accessible from clients. Use for authentication, sessions, or any stateful context that persists across RPC calls.

If the API object has an onDrop() method, it is called when the proxy is dropped, either because the client cancelled the request (scope cleanup) or the WebSocket disconnected. Use this to clean up server-side state kept on behalf of the client.

export class UserAPI {
constructor(public user: User) {}
getSecret() { return this.user.secret; }
onDrop() { console.log('client gone'); }
}
export async function authenticate(token: string) {
const user = await validateToken(token);
return new ServerProxy(new UserAPI(user), user.name);
}
// Client: auth.value is user name, auth.serverProxy.getSecret() calls UserAPI method

API extends object

The server-side API object type

RETURN

The value type returned to the client

new ServerProxy<API, RETURN>(api, value?): ServerProxy<API, RETURN>

Defined in: server.ts:419

API

Server-side API object exposed to the client

RETURN

Value returned immediately to the client

ServerProxy<API, RETURN>

api: API

Defined in: server.ts:419

Server-side API object exposed to the client


optional value?: RETURN

Defined in: server.ts:419

Value returned immediately to the client

toString(): string

Defined in: server.ts:420

string