import { RpcInvocationData, PerformRpcParams, Serializer, SerializerInput, SerializerOutput } from 'livekit-client'; import { UseSessionReturn } from './useSession'; /** @beta */ export type RpcHandler = (payload: Input, data: RpcInvocationData) => Promise; /** * Base RPC call parameters with an arbitrary payload type (used when the payload * will be serialized by a serializer). * * @beta */ export type RpcCallParams = Omit & { payload: Payload; }; /** * Options for {@link (useRpc:1)}. * @beta */ export type UseRpcOptions = Serializer> = { /** Only accept RPCs from this participant. Others will receive UNSUPPORTED_METHOD. */ fromIdentity?: string; /** * Serializer applied to the data coming in and leaving the handler. Defaults to `serializers.json()` */ serializer?: S; }; /** @beta */ export type RpcPerformFn = { /** Serializer-wrapped call: payload is serialized and response is parsed by the serializer. */ (params: RpcCallParams, serializer: Serializer): Promise; /** Plain call: payload is already a string, response is returned as a string. */ (params: PerformRpcParams): Promise; }; /** @beta */ export type UseRpcReturn = { perform: RpcPerformFn; }; /** * Hook for declarative RPC method registration and outbound RPC calls. * * Registers a handler for an incoming RPC method and returns a `performRpc` * function for outbound calls. The handler is registered on mount and * unregistered on unmount. Handler identity does not matter (captured by ref), * so inline functions work without `useCallback`. * * @example * ```tsx * const { performRpc } = useRpc(session, "getUserLocation", async (payload: { highAccuracy: boolean }) => { * const pos = await getPosition(payload.highAccuracy); * return { lat: pos.coords.latitude, lng: pos.coords.longitude }; * }); * ``` * * @beta */ export declare function useRpc>(session: UseSessionReturn, methodName: string, handler: RpcHandler, SerializerOutput>, options?: UseRpcOptions): UseRpcReturn; /** @beta */ export declare function useRpc>(methodName: string, handler: RpcHandler, SerializerOutput>, options?: UseRpcOptions): UseRpcReturn; /** @beta */ export declare function useRpc(session: UseSessionReturn): UseRpcReturn; /** @beta */ export declare function useRpc(): UseRpcReturn; //# sourceMappingURL=useRpc.d.ts.map