spark.RpcOptions
export interface RpcOptions {
/**
* Target to send messages to (Window, Worker, MessagePort, etc).
*
* Usually:
* - Window.parent or window.opener for iframe-parent communication
* - Worker instance for main-worker communication
* - self in a Worker context (for parent to send messages to this worker)
*
* @required
*/
target: MessageTarget;
/**
* Origin for postMessage validation (security measure).
*
* - Use `'*'` for Workers (they don't enforce origin checks)
* - Use `'https://example.com'` for cross-window communication
* - Match the actual origin of the target for security
*
* @default '*' (suitable for workers)
* @example
* ```typescript
* // Communicate with iframe from same origin
* const rpc = new Rpc({
* target: iframeWindow,
* origin: 'https://myapp.com'
* });
*
* // Communicate with worker (always use '*')
* const rpc = new Rpc({
* target: worker,
* origin: '*'
* });
* ```
*/
origin?: string;
/**
* Timeout for method calls in milliseconds.
*
* If a remote method call doesn't receive a response within this time,
* the promise rejects with a timeout error. Network latency and
* long-running operations on the remote side consume this timeout.
*
* Set higher values for operations known to take longer. Set to Infinity
* to disable timeout (not recommended).
*
* @default 30000 (30 seconds)
* @example
* ```typescript
* // Fast operations (default)
* const rpc = new Rpc({ target: worker, origin: '*' });
*
* // Long-running operations
* const rpc = new Rpc({
* target: worker,
* origin: '*',
* timeout: 120000 // 2 minutes
* });
* ```
*/
timeout?: number;
}target(MessageTarget)- – Target to send messages to (Window, Worker, MessagePort, etc). Usually: - Window.parent or window.opener for iframe-parent communication - Worker instance for main-worker communication - self in a Worker context (for parent to send messages to this worker)
origin(string)optional- – Origin for postMessage validation (security measure). - Use
'*'for Workers (they don't enforce origin checks) - Use'https://example.com'for cross-window communication - Match the actual origin of the target for security timeout(number)optional- – Timeout for method calls in milliseconds. If a remote method call doesn't receive a response within this time, the promise rejects with a timeout error. Network latency and long-running operations on the remote side consume this timeout. Set higher values for operations known to take longer. Set to Infinity to disable timeout (not recommended).
Configuration options for creating an RPC instance.
Controls how the RPC communicates with the remote side and validates messages.