import { Envelope } from './types-envelope.ts';import { Fn, FnsBag } from './types-bag.ts';import { Watchable, WatchableSet } from './watchable.ts';
export type Thunk = () => void;
export interface ITransportOpts<BagType extends FnsBag> { deviceId: string; methods: BagType; }
export type TransportStatus = 'OPEN' | 'CLOSED';
export interface ITransport<BagType extends FnsBag> { status: Watchable<TransportStatus>; isClosed: boolean;
methods: BagType; deviceId: string; connections: WatchableSet<IConnection<BagType>>;
onClose(cb: Thunk): Thunk; close(): void;
}
export interface ConnectionOpts<BagType extends FnsBag> { description: string; transport: ITransport<BagType>; deviceId: string; methods: BagType;
sendEnvelope: (conn: IConnection<BagType>, env: Envelope<BagType>) => Promise<void>;}
export type ConnectionStatus = | 'CONNECTING' | 'OPEN' | 'ERROR' | 'CLOSED';
export interface IConnection< MethodsType extends FnsBag,> {
status: Watchable<ConnectionStatus>; _closeCbs: Set<Thunk>;
description: string; _transport: ITransport<MethodsType>; _deviceId: string; _otherDeviceId: string | null; _methods: { [methodName: string]: Fn }; _lastSeen: number;
get isClosed(): boolean; onClose(cb: Thunk): Thunk; close(): void;
_sendEnvelope: (conn: IConnection<MethodsType>, env: Envelope<MethodsType>) => Promise<void>;
handleIncomingEnvelope(env: Envelope<MethodsType>): Promise<void>;
notify<MethodKey extends keyof MethodsType>( method: MethodKey, ...args: Parameters<MethodsType[MethodKey]> ): Promise<void>;
request<MethodKey extends keyof MethodsType>( method: MethodKey, ...args: Parameters<MethodsType[MethodKey]> ): Promise<ReturnType<MethodsType[MethodKey]>>;
}