LiveKit JS Client SDK - v2.25.0
    Preparing search index...

    Interface RpcRoomApiExperimental

    Methods the rpc extension adds to the room.

    interface RpcRoomApi {
        registerRpcMethod(
            method: string,
            handler: (data: RpcInvocationData) => Promise<string>,
        ): void;
        unregisterRpcMethod(method: string): void;
    }

    Hierarchy (View Summary)

    Index
    • Experimental

      Establishes the participant as a receiver for calls of the specified RPC method.

      Parameters

      • method: string

        The name of the indicated RPC method

      • handler: (data: RpcInvocationData) => Promise<string>

        Will be invoked when an RPC request for this method is received

      Returns void

      A promise that resolves when the method is successfully registered

      If a handler for this method is already registered (must call unregisterRpcMethod first)

      room.localParticipant?.registerRpcMethod(
      'greet',
      async (data: RpcInvocationData) => {
      console.log(`Received greeting from ${data.callerIdentity}: ${data.payload}`);
      return `Hello, ${data.callerIdentity}!`;
      }
      );

      The handler should return a Promise that resolves to a string. If unable to respond within responseTimeout, the request will result in an error on the caller's side.

      You may throw errors of type RpcError with a string message in the handler, and they will be received on the caller's side with the message intact. Other errors thrown in your handler will not be transmitted as-is, and will instead arrive to the caller as 1500 ("Application Error").

    • Experimental

      Unregisters a previously registered RPC method.

      Parameters

      • method: string

        The name of the RPC method to unregister

      Returns void