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.
Example
Section titled “Example”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 methodType Parameters
Section titled “Type Parameters”API extends object
The server-side API object type
RETURN
Section titled “RETURN”RETURN
The value type returned to the client
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ServerProxy<
API,RETURN>(api,value?):ServerProxy<API,RETURN>
Defined in: server.ts:419
Parameters
Section titled “Parameters”API
Server-side API object exposed to the client
value?
Section titled “value?”RETURN
Value returned immediately to the client
Returns
Section titled “Returns”ServerProxy<API, RETURN>
Properties
Section titled “Properties”api:
API
Defined in: server.ts:419
Server-side API object exposed to the client
value?
Section titled “value?”
optionalvalue?:RETURN
Defined in: server.ts:419
Value returned immediately to the client
Methods
Section titled “Methods”toString()
Section titled “toString()”toString():
string
Defined in: server.ts:420
Returns
Section titled “Returns”string