import { _ as prepareUtils, a as HumanizeErrorType, h as makeReconnectNotice, i as HumanizableError, m as SetPeerIdToSessionStorageType, p as ReconnectingPayload, t as GetPeerIdType } from "./common-DNqltYdj.js"; import EventEmitter from "eventemitter3"; import { Peer } from "peerjs"; declare namespace remote_d_exports { export { IsIgnorableErrorType, PrepareRemoteUtils, WrcRemote, WrcRemoteEvents, prepare as default, makeReconnectNotice, prepareUtils }; } /** * The type of the predicate `prepare` hands out. Declared here rather than in * `common.ts` because it is the remote side's alone: a master does not * reconnect, so nothing on that side can produce the errors this describes. */ export type IsIgnorableErrorType = (error: HumanizableError) => boolean; /** * The events a remote emits. See the note on `WrcMasterEvents`. */ export interface WrcRemoteEvents { /** * The connection to the master closed and a reconnection is starting. Not * fired when the application destroyed the peer itself. */ "remote.disconnect": (payload: { id: string; }) => void; /** * A reconnection attempt is starting. Fired once per attempt, including the * immediate one, and never for the first connection: its retries happen * before `bindConnection` resolves, so there is no one to tell. * * This is what lets an application tell "coming back" from "gone". Without * it the only signal is `peer-unavailable` on the `Peer`, which says nothing * about whether anyone is still trying. `attempt` counts from 1 and * `nextDelayMs` is how long this attempt is given before it is abandoned, so * an application can show a quiet notice at first and escalate to "try * reloading" once the delay has reached its ceiling. */ "remote.reconnecting": (payload: ReconnectingPayload) => void; "remote.reconnect": (payload: { id: string; }) => void; data: (payload: { from: "master"; }, data: unknown) => void; } export interface WrcRemote { send(payload: unknown): void; on: EventEmitter["on"]; off: EventEmitter["off"]; } export interface PrepareRemoteUtils { humanizeError: HumanizeErrorType; getPeerId: GetPeerIdType; setPeerIdToSessionStorage: SetPeerIdToSessionStorageType; /** * Optional, because `prepare` is public and a caller may hand in a * hand-rolled bundle rather than the one `prepareUtils` builds. When it is * absent the default factory fills it in, so what `prepare` returns always * has one - a consumer of the remote side should never have to check. */ reconnectNotice?: (payload: ReconnectingPayload) => TReconnecting | TStalled; } export default function prepare({ humanizeError, getPeerId, setPeerIdToSessionStorage, reconnectNotice }: PrepareRemoteUtils): { humanizeError: (error: HumanizableError) => string; getPeerId: () => string | undefined; /** * Passed straight through, the way `humanizeError` is. The remote side is * the one that reconnects to its master, not the other way round, so this * is where the notice belongs - `master.default` has no use for it. */ reconnectNotice: (payload: ReconnectingPayload) => TReconnecting | TStalled; /** * Whether an error the consumer just received from their `Peer` is one this * library provoked, and so safe not to show anyone. * * Every retry that loses its race to the master re-registering makes peerjs * emit `peer-unavailable`. `humanizeError` turns those into advice to * reload: wrong mid-recovery, right on a first connection, where it ends * the retries. Only this library knows which of the two is happening. * * Rejoining the signaling server can also be refused with `unavailable-id` * while it still holds the id from before the outage; peerjs only * disconnects, and the next attempt tries again. * * Nothing is intercepted; the consumer still gets every event and still * writes the `return`. It is `true` for those two types alone, and it * cannot tell which peer an error is about, since peerjs carries that id * only in the message text - so a page whose `Peer` also connects to ids * this library does not manage should not call it. */ isIgnorableError(error: HumanizableError): boolean; bindConnection(peer: Peer, masterPeerId: string): Promise; }; //#endregion export { makeReconnectNotice, prepareUtils, remote_d_exports as t }; //# sourceMappingURL=remote.d.ts.map