import EventEmitter from "eventemitter3"; import { Peer } from "peerjs"; //#region src/common.d.ts /** * The shape `humanizeError` accepts. peerjs errors carry a `type`, but the * function is deliberately tolerant: anything with an optional `type` and * `message` works, including a plain `Error`. */ interface HumanizableError { type?: string; message?: string; } /** * A fallback entry may be a string or a function of the error. Only the * `default` key is ever called; every other key is a plain string. */ type HumanErrorsDefault = string | ((error: HumanizableError) => string); interface HumanErrorsMapping { [errorType: string]: string | HumanErrorsDefault | undefined; default?: HumanErrorsDefault; } interface MakeHumanizeErrorOptions { mapping?: HumanErrorsMapping; withTechicalErrorMessage?: boolean; } /** * What `remote.reconnecting` carries. Declared here rather than in `remote.ts` * so `makeReconnectNotice` can name it without the two modules importing each * other. */ interface ReconnectingPayload { id: string; attempt: number; nextDelayMs: number; } /** * A notice may be a plain value or a function of the payload, the way the * `default` entry of the error mapping may be. */ type ReconnectMessage = T | ((payload: ReconnectingPayload) => T); interface MakeReconnectNoticeOptions { /** Shown while recovery is still plausible. */ reconnecting?: ReconnectMessage; /** Shown once the backoff has reached its ceiling. */ stalled?: ReconnectMessage; } interface PrepareUtilsOptions { sessionStorageKey?: string; humanErrors?: MakeHumanizeErrorOptions; reconnectNotice?: MakeReconnectNoticeOptions; } declare function reconnectDelay(attempt: number): number; /** * How many refusals of a first `open` with `unavailable-id` the stored id gets, * each followed by a wait of `reconnectDelay(attempt)`, before a fresh id is * asked for: about 23 seconds in all. Deliberately shorter than the signaling * server's timeout for a socket that died without closing (60 to 90 seconds): * nobody waits that long in front of a screen that says nothing. */ declare const ID_TAKEN_MAX_ATTEMPTS = 5; /** * Calls `listener` when the signaling server refuses `peer`'s id before its * first `open`, and returns a function that stops listening. * * That is the one `unavailable-id` peerjs answers by destroying the peer, so * recovering means building a new one; after an `open`, peerjs only * disconnects. Nothing public on the peer tells the two apart, which is why * this watches `open` itself. It stops listening once the peer opens. */ declare function onIdTakenBeforeOpen(peer: Peer, listener: (error: HumanizableError) => void): () => void; /** * Builds the function that turns a `remote.reconnecting` payload into * something to show, choosing between "still trying" and "probably gone". * * That choice is the point of it. It is made by comparing `nextDelayMs` * against the backoff ceiling, and a consumer should not have to know that * number - or notice when it changes - to tell a user whether waiting is still * worth it. * * Both messages are overridable, and both may be a value or a function of the * payload. The type parameters are inferred from whatever is passed, so * returning something richer than a string - a React node, say - needs no * annotation at the call site and no cast. */ declare function makeReconnectNotice({ reconnecting, stalled }?: MakeReconnectNoticeOptions): (payload: ReconnectingPayload) => TReconnecting | TStalled; declare function prepareUtils({ sessionStorageKey, humanErrors, reconnectNotice: reconnectNoticeOptions }?: PrepareUtilsOptions): { humanizeError: (error: HumanizableError) => string; reconnectNotice: (payload: ReconnectingPayload) => TReconnecting | TStalled; isConnectionFromRemote: (conn: { metadata?: unknown; }) => boolean; getPeerId: () => string | undefined; setPeerIdToSessionStorage: (peerId: string) => void; }; type HumanizeErrorType = ReturnType["humanizeError"]; type IsConnectionFromRemoteType = ReturnType["isConnectionFromRemote"]; type ReconnectNoticeType = ReturnType["reconnectNotice"]; type GetPeerIdType = ReturnType["getPeerId"]; type SetPeerIdToSessionStorageType = ReturnType["setPeerIdToSessionStorage"]; //#endregion export { prepareUtils as _, HumanizeErrorType as a, MakeHumanizeErrorOptions as c, ReconnectMessage as d, ReconnectNoticeType as f, onIdTakenBeforeOpen as g, makeReconnectNotice as h, HumanizableError as i, MakeReconnectNoticeOptions as l, SetPeerIdToSessionStorageType as m, HumanErrorsDefault as n, ID_TAKEN_MAX_ATTEMPTS as o, ReconnectingPayload as p, HumanErrorsMapping as r, IsConnectionFromRemoteType as s, GetPeerIdType as t, PrepareUtilsOptions as u, reconnectDelay as v }; //# sourceMappingURL=common-DNqltYdj.d.ts.map