{"version":3,"sources":["../src/rpc.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RpcError as RpcError_Proto } from '@livekit/rtc-ffi-bindings';\n\n/** Parameters for initiating an RPC call */\nexport interface PerformRpcParams {\n  /** The `identity` of the destination participant */\n  destinationIdentity: string;\n  /** The method name to call */\n  method: string;\n  /** The method payload */\n  payload: string;\n  /** Timeout for receiving a response after initial connection (milliseconds). Default: 10000 */\n  responseTimeout?: number;\n}\n\n/**\n * Data passed to method handler for incoming RPC invocations\n */\nexport interface RpcInvocationData {\n  /**\n   * The unique request ID. Will match at both sides of the call, useful for debugging or logging.\n   */\n  requestId: string;\n\n  /**\n   * The unique participant identity of the caller.\n   */\n  callerIdentity: string;\n\n  /**\n   * The payload of the request. User-definable format, typically JSON.\n   */\n  payload: string;\n\n  /**\n   * The maximum time the caller will wait for a response.\n   */\n  responseTimeout: number;\n}\n\n/**\n * Specialized error handling for RPC methods.\n *\n * Instances of this type, when thrown in a method handler, will have their `message`\n * serialized and sent across the wire. The caller will receive an equivalent error on the other side.\n *\n * Built-in types are included but developers may use any string, with a max length of 256 bytes.\n */\n\nexport class RpcError extends Error {\n  code: typeof RpcError.ErrorCode | number;\n  data?: string;\n\n  /**\n   * Creates an error object with the given code and message, plus an optional data payload.\n   *\n   * If thrown in an RPC method handler, the error will be sent back to the caller.\n   *\n   * Error codes 1001-1999 are reserved for built-in errors (see RpcError.ErrorCode for their meanings).\n   */\n  constructor(code: number, message: string, data?: string) {\n    super(message);\n    this.code = code;\n    this.message = message;\n    this.data = data;\n  }\n\n  static fromProto(proto: RpcError_Proto) {\n    return new RpcError(proto.code!, proto.message!, proto.data);\n  }\n\n  toProto() {\n    return {\n      code: this.code as number,\n      message: this.message,\n      data: this.data,\n    } as RpcError_Proto;\n  }\n\n  static ErrorCode = {\n    APPLICATION_ERROR: 1500,\n    CONNECTION_TIMEOUT: 1501,\n    RESPONSE_TIMEOUT: 1502,\n    RECIPIENT_DISCONNECTED: 1503,\n    RESPONSE_PAYLOAD_TOO_LARGE: 1504,\n    SEND_FAILED: 1505,\n\n    UNSUPPORTED_METHOD: 1400,\n    RECIPIENT_NOT_FOUND: 1401,\n    REQUEST_PAYLOAD_TOO_LARGE: 1402,\n    UNSUPPORTED_SERVER: 1403,\n  } as const;\n\n  /**\n   * @internal\n   */\n  static ErrorMessage: Record<keyof typeof RpcError.ErrorCode, string> = {\n    APPLICATION_ERROR: 'Application error in method handler',\n    CONNECTION_TIMEOUT: 'Connection timeout',\n    RESPONSE_TIMEOUT: 'Response timeout',\n    RECIPIENT_DISCONNECTED: 'Recipient disconnected',\n    RESPONSE_PAYLOAD_TOO_LARGE: 'Response payload too large',\n    SEND_FAILED: 'Failed to send',\n\n    UNSUPPORTED_METHOD: 'Method not supported at destination',\n    RECIPIENT_NOT_FOUND: 'Recipient not found',\n    REQUEST_PAYLOAD_TOO_LARGE: 'Request payload too large',\n    UNSUPPORTED_SERVER: 'RPC not supported by server',\n  } as const;\n\n  /**\n   * Creates an error object from the code, with an auto-populated message.\n   *\n   * @internal\n   */\n  static builtIn(key: keyof typeof RpcError.ErrorCode, data?: string): RpcError {\n    return new RpcError(RpcError.ErrorCode[key], RpcError.ErrorMessage[key], data);\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmDO,MAAM,YAAN,MAAM,kBAAiB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWlC,YAAY,MAAc,SAAiB,MAAe;AACxD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,UAAU;AACf,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,OAAO,UAAU,OAAuB;AACtC,WAAO,IAAI,UAAS,MAAM,MAAO,MAAM,SAAU,MAAM,IAAI;AAAA,EAC7D;AAAA,EAEA,UAAU;AACR,WAAO;AAAA,MACL,MAAM,KAAK;AAAA,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