Skip to content

@fkn/lib

type RelayUnavailableError = Error & object;

What a call carrying a RelayChoice rejects with when no relay can serve the choice: none matches it, the ones that match cannot be reached, or the FKN page is too old to choose. Nothing was sent.

name: typeof RELAY_UNAVAILABLE;
const attachFrame: AttachFrameFunction;

Attaches FKN to an iframe the app mounted, or with { window } opens the attachment in a window of its own. cookies picks the jar and with it the backend (AttachCookies): 'persistent', the default, and 'ephemeral' run on the cloud render proxy whatever is installed, and never wait for the extension; 'native' runs on the extension, waiting up to 2000 ms from the call for it to announce itself, however long after the page’s load that is (waitForExtensionExposure), and showing the install prompt when it does not. A blank attach is the cloud render proxy’s alone, so beside 'native' it is a TypeError. frame.backend() says which backend serves an attachment.

A window opens before the first await, so call this directly in the click or key handler whose activation opens it. On 'persistent' or 'ephemeral' it opens on the cloud, extension or not. On 'native' it opens as a real browser window on the extension, with no exposure wait; an extension that does not announce attachWindow, or none at all, is refused at once with ExtensionOperationUnsupportedError (operation 'attachWindow'), before anything opens or is waited for, so the same click can still open one on another value.

function connect(): Promise<boolean>;

Promise<boolean>


function fetch(input, init?): Promise<Response>;

URL | RequestInfo

RequestInit & object

Promise<Response>


function isRelayUnavailable(error): error is RelayUnavailableError;

Whether error is a RelayUnavailableError, matched on name so it holds across a worker hop.

unknown

error is RelayUnavailableError


function promptRelay(): Promise<string | null>;

Promise<string | null>


function relayOf(served): string | undefined;

The relay that served a cloud answer, socket, server, UDP socket or frame, as an id to pass back in a RelayChoice. Undefined when no relay did (the extension, the desktop, a 'native' frame), before a socket is connected or bound, and on an FKN page too old to say, so a loop that retries on another relay stops there. A frame attached without a choice answers the default relay of its attach once the broker has named it, normally before the attach resolves.

Socket | Server | Socket | Response | Frame

string | undefined


function relayWorker(worker, options?): Promise<void>;

Bridges a worker into the FKN API: once called, the worker can import @fkn/lib and use net / dgram exactly like the main thread. Main thread only.

originA and originB are kept for compatibility and change nothing: the page reaches fkn.app’s broker frame on fkn.app’s origin both ways, and a page nested under fkn.app reaches it over a port.

The page hands its fkn-api channel to the worker for good, and its own calls move to fkn-api-window. Against a cached FKN page from before that channel, the page’s own calls refuse with OwnChannelUnavailableError and FKN’s UI and account changes stay off here until a reload. A socket the page opened through FKN before its first relayWorker rides the channel it hands over, so it closes then.

The bridge ends when unregisterSignal aborts or the worker is gone (terminate(), a crash), the latter seen only for a worker running this version of @fkn/lib or a later one. Every socket the worker opened through FKN’s relay is then closed there, one still opening included, and a worker that lives on has its FKN calls refused. A page relays one worker at a time: with two bridges open, every answer goes to both workers, and one carrying a stream, a promise or a port reaches only the worker relayed first.

Worker

string

string

AbortSignal

Promise<void>

Re-exports account


Re-exports AddScriptTagOptions


Re-exports assertAttachableFrameUrl


Re-exports assertFetchableUrl


Re-exports AttachCookies


Re-exports AttachFrameOptions


Re-exports AttachWindowOptions


Re-exports BACKGROUND_STOPPED


Re-exports BackgroundStoppedError


Re-exports BlankPage


Re-exports ClearCookiesOptions


Re-exports cloud


Re-exports connectButtonUrl


Re-exports CookieDetails


Re-exports cookies


Re-exports desktop


Re-exports dgram


Re-exports dns


Re-exports extension


Re-exports EXTENSION_ABI


Re-exports ExtensionHandshake


Re-exports ExtensionOperationUnsupportedError


Re-exports ExtensionOutdatedError


Re-exports FetchInit


Re-exports FORGEABLE_HEADERS


Re-exports Frame


Re-exports FrameLocator


Re-exports FrameWindowBlockedError


Re-exports FrameWindowOptions


Re-exports FrameWindowRefusal


Re-exports FrameWindowRefusedError


Re-exports fs


Re-exports GotoOptions


Re-exports HeaderOperation


Re-exports http


Re-exports isBackgroundStopped


Re-exports isExtensionExposed


Re-exports isLocalNetworkUrl


Re-exports isLocatorInvalid


Re-exports LOCATOR_INVALID


Re-exports net


Re-exports opfs


Re-exports packages


Re-exports PermissionGrant


Re-exports PermissionRequest


Re-exports permissions


Re-exports promptInstall


Re-exports readExtensionHandshake


Re-exports RELAY_UNAVAILABLE


Re-exports RemoteVideoElement


Re-exports removeRequestHeaderRule


Re-exports RequestHeaderRule


Re-exports REQUIRED_EXTENSION_ABI


Re-exports rooms


Re-exports setMissingExtensionHandler


Re-exports setRequestHeaderRule


Re-exports SiteCookie


Re-exports storage


Re-exports StorageState


Re-exports StorageStateCookie


Re-exports supportsOperation


Re-exports TimeoutError


Re-exports waitForExtensionExposure


Re-exports WindowFrame