import { Observable } from "rxjs"; import { DurableSocket } from "./durable-socket"; export interface RPCChannel { received: Observable; /** * This optional event signifies that the ongoing state of the channel has been lost, * and any outstanding requests are no longer resolvable. An example of such * an event might be the connection being lost. * * The value of the observable is the error message when state has been lost. */ stateLost?: Observable; /** * This optional event signifies that the channel is ready for communications. * * If provided, then this event must fire as soon as the channel is ready for use * (even if the subscription occurs after the channel becomes ready for use). * * If the channel supports re-establishment, then subscribing to this * observable while re-establishment is occuring must not cause an event until * the channel is re-established. */ ready?: Observable; send(message: string): any; close?(): any; } /** * A channel which operates within the local process. */ export declare class LocalChannel implements RPCChannel { private _received; get received(): Observable; send(message: string): void; private otherChannel; static makePair(): [LocalChannel, LocalChannel]; } /** * A channel that operates over a WebSocket or RTCDataChannel. */ export declare class SocketChannel implements RPCChannel { readonly socket: WebSocket | RTCDataChannel; constructor(socket: WebSocket | RTCDataChannel); private _ready; get ready(): Observable; markReady(): void; markNotReady(): void; private _stateLost; private _stateLost$; get stateLost(): Observable; private _received; private _received$; get received(): Observable; protected stateWasLost(errorMessage: string): void; send(message: any): Promise; close(): void; } /** * A channel that operates on a DurableSocket. */ export declare class DurableSocketChannel extends SocketChannel { constructor(socket: DurableSocket); readonly socket: DurableSocket; } /** * A channel that operates via window-to-window (or frame-to-frame) postMessage. */ export declare class WindowChannel implements RPCChannel { private remoteWindow; constructor(remoteWindow: Window, origin?: string); private handler; private _received; get received(): Observable; send(message: any): void; close(): void; } /** * @unstable Caution: This API may change in minor or patch releases until it is marked as stable. */ interface PostMessageTarget { addEventListener(event: 'message', callback: (ev: MessageEvent) => void): any; removeEventListener(event: 'message', callback: (ev: MessageEvent) => void): any; postMessage(data: string): any; } /** * A channel that operates via window-to-window (or frame-to-frame) postMessage. * @unstable Caution: This API may change in minor or patch releases until it is marked as stable. */ export declare class PostMessageChannel implements RPCChannel { private remote; readonly requiredOrigin?: string; constructor(remote: PostMessageTarget, requiredOrigin?: string); private handler; private _received; get received(): Observable; send(message: any): void; close(): void; } export {};