Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Library API

The four full libraries share one design: announce for peers, start a hub for hubs, typed protocols, and an error with a spec error code. The table maps the names; details follow per language. Doc comments in each package carry the full API.

ConceptTypeScriptRustC#Java
Announceannounce(a, { onHubs })funlink::announce(a) / Announcer::builder(a).on_hubs(f).start()FunlinkPeer.Announce(a, onHubs)Funlink.announce(a, onHubs)
Updateannouncer.update(a)announcer.update(a)?peer.Update(a)announcer.update(a)
Stop peerawait announcer.close()drop / close()await DisposeAsync()close()
Start hubawait startHub(options)Hub::builder(name).supports(..).start(f)?await FunlinkHub.StartAsync(options, f)Funlink.hub(options, f)
Record answerhub.setState(peer, state)hub.set_state(&peer, state)hub.SetState(peer, state)hub.setState(peer, state)
Stop hubawait hub.close()drop / close()await DisposeAsync()close()
Serve OFS (ofs-ws-extended)await serveOfs(options)OfsServer::builder(name).start(f)?await OfsServer.StartAsync(options, f)Ofs.serve(options, f)
Feed itsetMedia, setScript, setPlaying, setTime, …set_media, set_script, …SetMedia, SetScript, …setMedia, setScript, …
Move a rangesetRange(player?, output, axis, min, max)set_range(..)?SetRange(..)setRange(..)
Local network peerannounce(a, { lan: true })Announcer::builder(a).lan(true).start()FunlinkPeer.Announce(a, options: new AnnounceOptions { Lan = true })Funlink.announcer(a).lan(true).start()
Local network hublan: true, queryHosts, hub.search().lan(true), .query_hosts(..), hub.search()Lan, QueryHosts, hub.Search()withLan(true), withQueryHosts(..), hub.search()
Network address of a peerpeer.addresspeer.addresspeer.Addresspeer.address()
Custom protocolcustomProtocol(v, n)Protocol::custom(v, n)?Protocol.Custom(v, n)Protocol.custom(v, n)
ErrorFunlinkError (.code)funlink::Error (.code())FunlinkException (.Code)FunlinkException (.code())

The C library and the Godot add-on are peers only; they have sections of their own below.

TypeScript

announce(announcement: Announcement, options?: { onHubs?(hubs: HubStatus[]): void; lan?: boolean }): Announcer
// Announcer: session, hubs, update(a), close(); AsyncDisposable

startHub(options: {
  name: string; version?: string; id?: string;
  supports: Protocol[];
  onEvent(event: HubEvent): void;
  allowBrowsers?: boolean;
  lan?: boolean; queryHosts?: string[];
}): Promise<Hub>
// Hub: info, port, peers, search(), setState(peer, "available" | "connected" | "dismissed"), close(); AsyncDisposable

type HubEvent =
  | { type: "found"; peer: Peer }
  | { type: "updated"; peer: Peer }
  | { type: "lost"; peer: Peer; reason: "bye" | "expired" | "restarted" };
// Peer: id, session, name, version?, icon?, services, ext?, origin?, address?, state, usable

await using works with both objects. Also exported: REGISTERED_PROTOCOLS, DEFAULT_PORTS, isRegistered.

Rust

#![allow(unused)]
fn main() {
Announcement::new(id, name).version(..).icon(..).service(Protocol, endpoint)
    .with_service(Service::new(p, e).feature(..)).ext(key, serde_json::Value)

funlink::announce(a) -> Result<Announcer, Error>
Announcer::builder(a).on_hubs(|&[HubStatus]| ..).lan(bool).port(p).start()
// Announcer: session(), hubs(), update(a), close(); says bye on Drop

Hub::builder(name).version(..).id(..).supports([..]).allow_browsers(bool)
    .lan(bool).query_hosts([IpAddr]).port(p)
    .start(|HubEvent| ..) -> Result<Hub, Error>
// Hub: info(), port(), peers(), search(), set_state(&peer, PeerState) -> Option<Peer>; stops on Drop
// Peer::address: Option<IpAddr>, Some for local network peers

enum HubEvent { Found(Peer), Updated(Peer), Lost { peer, reason: LostReason } }   // #[non_exhaustive]
}

Plain threads, no async runtime. Callbacks run on a library thread.

C#

new Announcement(id, name, [new Service(protocol, endpoint) { Features = [..] }])
    { Version = .., Icon = .., Ext = new Dictionary<string, JsonElement> { .. } }

FunlinkPeer.Announce(announcement, Action<IReadOnlyList<HubStatus>>? onHubs = null,
    AnnounceOptions? options = null)   // new AnnounceOptions { Lan = true }
// FunlinkPeer: Session, Hubs, Update(a); IAsyncDisposable

await FunlinkHub.StartAsync(new HubOptions(name, supports) { Version = .., Id = .., AllowBrowsers = .., Lan = .., QueryHosts = [..] },
    Action<HubEvent> onEvent)
// FunlinkHub: Info, Port, Peers, Search(), SetState(peer, PeerState) -> Peer?; IAsyncDisposable
// Peer.Address: IPAddress?, set for local network peers

// Events: PeerFound(Peer), PeerUpdated(Peer), PeerLost(Peer, LostReason)

.NET 8+, no dependencies, trimming and AOT friendly.

Java

Announcement.of(id, name, Service.of(protocol, endpoint), ...)
    .withVersion(..).withIcon(..).withServices(..).withExt(key, value)

Funlink.announce(announcement[, Consumer<List<HubStatus>> onHubs]) -> Announcer
Funlink.announcer(announcement).onHubs(..).lan(true).start() -> Announcer
// Announcer: session(), hubs(), update(a), close(); AutoCloseable

Funlink.hub(HubOptions.of(name, protocols...).withVersion(..).withId(..).withBrowsers(bool)
    .withLan(bool).withQueryHosts(InetAddress...),
    Consumer<HubEvent> onEvent) -> Hub
// Hub: info(), port(), peers(), search(), setState(peer, PeerState) -> Optional<Peer>, close(); AutoCloseable
// Peer.address(): Optional<InetAddress>, present for local network peers

// sealed interface HubEvent: Found(peer), Updated(peer), Lost(peer, reason)

Java 17+, JPMS module io.github.faplandpartydev.funlink. Callbacks run on background threads, one at a time; exceptions go to the thread’s uncaught exception handler.

C and Arduino

A peer for the local network only, without malloc, for ESP32, ESP8266, Pico W and POSIX systems. See its README for the platform callbacks.

// Arduino
Funlink funlink;
funlink.addService(protocol, port[, path, features, scheme]);
funlink.setExt(json);
funlink.begin(id, name[, version, transports]) -> bool   // FUNLINK_TRANSPORT_ALL, _BEACON or _MDNS
funlink.loop();  funlink.end();
funlink.connectedHub() -> const char*;  funlink.hub() -> const funlink_hub*
funlink.session();  funlink.lastError() -> funlink_err
/* C */
funlink_peer_init(&peer, &platform);
funlink_peer_configure(&peer, &record, now_ms) -> funlink_err
funlink_peer_start(&peer, now_ms) -> funlink_err
funlink_peer_on_datagram(&peer, socket, from_ip, from_port, data, length, now_ms);
funlink_peer_poll(&peer, now_ms);
funlink_peer_stop(&peer, now_ms);
funlink_peer_session(&peer) -> const char*
funlink_strerror(err) -> const char*

Godot

A GDScript node for Godot 4.2 or later that announces over loopback HTTP and, with lan, over the beacon. See Godot game.

FunlinkPeer.new()
# Properties: app_id, app_name, app_version, services (Array of {protocol, endpoint, features?}),
#   icon (Texture2D), ext (Dictionary), lan, lan_hosts, autostart
# Methods: start() -> Error, update() -> Error, stop(), is_running()
# Signal: hubs_changed(hubs: Array)  # each {hub, supported, state, address}
# Read-only: session, hubs, last_error

OFS server

All four full libraries: options id, name, version, port derived from id (ofsPort / default_port / DefaultPortFor / defaultPort; advanced override manualPort), path (/ofs), announce (on), extended (on); events connected, hello, devices, command, disconnected; players, endpoint, port, hubs. Bad numbers (NaN, infinity) and empty script names are rejected (TypeScript/Rust/Java: invalid_argument error; C#: ArgumentException). See Send scripts to a device player.

Ports

All libraries use 37420–37429, or only FUNLINK_PORT when it is set (Java also -Dfunlink.port=). Rust builders also take .port(p).