import { Environment, RimlessEvent, Schema, Target } from './types'; /** Private symbol to which we will assign transferable objects */ declare const SYM_TRANSFERABLES: unique symbol; /** * for each function in methods * 1. subscribe to an event that the remote can call * 2. listen for calls from the remote. When called execute the function and emit the results. * * @param methods an object of method ids : methods from the local schema * @param rpcConnectionID * @param listenTo Environment to listen for incoming messages * @param sendTo Target to send outgoing messages * @param remote The remote API object for the current connection * @return a function to cancel all subscriptions */ export declare function registerLocalMethods(methods: Record any> | undefined, rpcConnectionID: string, listenTo: Environment, sendTo: Target, remote: Schema): () => void; /** * Create a function that will make an RPC request to the remote with some arguments. * Listen to an event that returns the results from the remote. * * @param rpcCallName * @param rpcConnectionID * @param event * @param listeners * @param guest * * @returns a promise with the result of the RPC */ export declare function createRPC(rpcCallName: string, rpcConnectionID: string, event: RimlessEvent, listeners: Array<() => void> | undefined, listenTo: Environment, sendTo: Target): (...args: any[]) => Promise; /** * create an object based on the remote schema's methods. Functions in that object will * emit an event that will trigger the RPC on the remote. * * @param schema * @param methods * @param connectionID * @param event * @param guest */ export declare function registerRemoteMethods(schema: Schema | undefined, methodNames: Iterable | undefined, connectionID: string, event: RimlessEvent, listenTo: Environment, sendTo: Target): { remote: { [x: string]: any; }; unregisterRemote: () => void; }; /** * This function is used by API schema declarations and remote function calls alike to * indicate which variables should be declared as transferable over `postMessage` calls. * * @param cb a function that takes a transfer function as an argument and returns an object * (in the loose, `typeof foo === "object"` sense) * @return result the callback's return value, with an extra array of transferable objects * assigned to rimless' private symbol `SYM_TRANSFERABLES` * * The `transfer(...)` function is called with an object to transfer; if there * are many objects to transfer, you may call it multiple times. It will always * return the input object. Calling `transfer` only modifies the callback * result, not the transferred object itself (or objects themselves). * * @example * host.connect({ * foo: (...args) => { * const foo = new ArrayBuffer(8); * return withTransferable((transfer) => transfer(foo)); * }), * }); * * @example * host.remote.foo(withTransferable((transfer) => ({ * stream: transfer(new ReadableStream()), * }))); */ export declare const withTransferable: (cb: (transfer: (transferable: T) => T) => Result) => Result & { [SYM_TRANSFERABLES]: Transferable[]; }; export {};