/** * Core transport layer. * * Ported from triangle-js-sdks `packages/host-api/src/transport.ts`, * adapted for the new architecture: * * 1. Auto-detects incoming message format (Uint8Array → SCALE, * plain object → structured clone) and auto-upgrades the * outgoing codec when structured clone is detected. * 2. Exposes a `swapCodecAdapter` method so codec negotiation can * explicitly upgrade the wire format. * 3. Keeps the full API surface: `request`, `handleRequest`, * `subscribe`, `handleSubscription`, plus low-level * `postMessage` / `listenMessages`. */ import type { CodecAdapter } from "../codec/adapter.js"; import type { RequestMethod, SubscriptionMethod, ActionString, RequestCodecType, ResponseCodecType, StartCodecType, ReceiveCodecType } from "../../api/protocol.js"; import type { Provider } from "./provider.js"; /** Interval (ms) between handshake retries. */ export declare const HANDSHAKE_INTERVAL = 50; /** Maximum time (ms) to wait for a handshake response. */ export declare const HANDSHAKE_TIMEOUT = 10000; /** Error thrown when a request targets a method with no registered handler. */ export declare class MethodNotSupportedError extends Error { constructor(method: string); } export type ConnectionStatus = "connecting" | "connected" | "disconnected"; export type Subscription = { unsubscribe: () => void; onInterrupt(callback: () => void): () => void; }; export type Transport = { /** Resolves when the handshake completes. Rejects on timeout or disposal. */ whenReady(): Promise; destroy(): void; onConnectionStatusChange(callback: (status: ConnectionStatus) => void): () => void; onDestroy(callback: () => void): () => void; /** Swap the codec adapter (e.g. after negotiation). */ swapCodecAdapter(adapter: CodecAdapter): void; request(method: M, payload: RequestCodecType, signal?: AbortSignal): Promise>; handleRequest(method: M, handler: (message: RequestCodecType) => Promise>): () => void; subscribe(method: M, payload: StartCodecType, callback: (payload: ReceiveCodecType) => void): Subscription; handleSubscription(method: M, handler: (params: StartCodecType, send: (value: ReceiveCodecType) => void, interrupt: () => void) => () => void): () => void; postMessage(requestId: string, payload: { tag: ActionString; value: unknown; }): void; listenMessages(action: ActionString, callback: (requestId: string, value: unknown) => void, onError?: (error: unknown) => void): () => void; }; export type CreateTransportOptions = { provider: Provider; /** * Handshake role: * - `'initiate'`: eagerly sends handshake requests until the other side responds. * - `'respond'`: registers a handler that responds to incoming handshake requests. */ handshake: "initiate" | "respond"; /** * Protocol version id sent during handshake. * Defaults to `1` (the original JAM_CODEC_PROTOCOL_ID). */ protocolVersionId?: number; /** * Prefix for generated request IDs. * * Use `"h:"` on the host side and `"p:"` on the product side so that * IDs from independent counters never collide on the shared channel. */ idPrefix?: string; }; export declare function createTransport(options: CreateTransportOptions): Transport; //# sourceMappingURL=transport.d.ts.map