Announce your app
Your app is a peer when it offers a service other apps can connect to. Announcing takes one call; the library repeats it every 5 seconds and says goodbye when you stop it.
1. Install
Install the library from the GitHub release or from git; Install has the steps for C#, Java and Godot. For a microcontroller, see Announce a Wi-Fi device.
npm install https://github.com/FapLandPartyDev/funlink/releases/download/v0.1.0/funlink-0.1.0.tgz
cargo add funlink --git https://github.com/FapLandPartyDev/funlink --tag v0.1.0
Put Funlink.0.1.0.nupkg in a local package source (how), then:
dotnet add package Funlink --version 0.1.0
// Gradle, with funlink-0.1.0.jar in libs/
implementation(files("libs/funlink-0.1.0.jar"))
For Maven, install the jar and pom into your local repository first (how).
Download Funlink-arduino-0.1.0.zip from the release and add it with Sketch → Include Library → Add .ZIP Library, or list it in PlatformIO’s lib_deps (how).
Download funlink-godot-0.1.0.zip from the release and unpack it into your project, so that addons/funlink/ sits next to project.godot. Godot 4.2 or later; no plugin needs enabling. Godot .NET projects can use the C# library instead.
2. Announce
import { announce } from "funlink";
const funlink = announce({
id: "my-player", // fixed name of your app
name: "My Player",
version: "1.0.0",
services: [{ protocol: "ofs-ws", endpoint: "ws://127.0.0.1:8080/ofs" }],
});
// On exit:
await funlink.close();
#![allow(unused)]
fn main() {
use funlink::{Announcement, Protocol};
let peer = funlink::announce(
Announcement::new("my-player", "My Player")
.version("1.0.0")
.service(Protocol::OfsWs, "ws://127.0.0.1:8080/ofs"),
)?;
// Dropping `peer` says goodbye to every hub.
}
using Funlink;
await using var peer = FunlinkPeer.Announce(
new Announcement("my-player", "My Player",
[new Service(Protocol.OfsWs, "ws://127.0.0.1:8080/ofs")]) { Version = "1.0.0" });
// Disposing `peer` says goodbye to every hub.
import io.github.faplandpartydev.funlink.*;
var announcement = Announcement.of("my-player", "My Player",
Service.of(Protocol.OFS_WS, "ws://127.0.0.1:8080/ofs"))
.withVersion("1.0.0");
try (var funlink = Funlink.announce(announcement)) {
// Run your app. close() says goodbye to every hub.
}
#include <Funlink.h>
Funlink funlink;
void setup() {
// Connect to Wi-Fi first.
funlink.addService("tcode-udp", 8000); // udp://0.0.0.0:8000
if (!funlink.begin("sr6-a41c", "SR6", "1.0.0")) {
Serial.println(funlink_strerror(funlink.lastError()));
}
}
void loop() {
funlink.loop(); // call it often
}
A board has no hub on its own loopback, so the C library announces on the local network: give the port your device listens on, and hubs use the address the announcement came from. Announce a Wi-Fi device has a whole sketch.
# In an autoload, or any node that lives as long as the game.
var funlink := FunlinkPeer.new()
func _ready() -> void:
funlink.app_id = "my-game" # fixed name of your game
funlink.app_name = "My Game"
funlink.app_version = "1.0.0"
funlink.services = [{"protocol": "ofs-ws", "endpoint": "ws://127.0.0.1:8080/ofs"}]
add_child(funlink) # starts announcing
# The node says bye when it leaves the tree or the window closes.
You can also add a FunlinkPeer node in the editor and fill in its properties in the inspector.
That is all. A running RustyFunPlayer now shows a My Player card: 1.0.0 is running. Connect to follow its playback?
An invalid announcement fails at once (FunlinkError, funlink::Error, FunlinkException), so mistakes show up in development, not on users’ machines.
3. Pick good values
| Field | Rule | Tip |
|---|---|---|
id | Stable; 1–64 of A-Z a-z 0-9 . _ - | Use a fixed name for your app, such as my-game or org.example.player. Hubs remember “always connect” and “never ask” by id, and the OFS server derives its port from it. |
name | 1–64 characters | Shown on the card. Use your product name. |
version | Up to 32 characters, optional | Shown next to the name. |
icon | data:image/png;base64,…, square, ≤ 512 px, ≤ 64 KiB, optional | Shown on the card. 128 px is plenty. |
services | 1–8 services | Which protocol and loopback endpoint (127.0.0.1 or [::1]). |
ext | Optional object with reverse-domain keys | App-specific data, such as EDI game paths. |
The library adds the random per-launch session itself.
4. Keep it current
When a service starts, stops or moves to another port, replace the whole announcement; it is sent at once.
funlink.update({ id: "my-player", name: "My Player",
services: [{ protocol: "ofs-ws", endpoint: "ws://127.0.0.1:8081/ofs" }] });
#![allow(unused)]
fn main() {
peer.update(Announcement::new("my-player", "My Player")
.service(Protocol::OfsWs, "ws://127.0.0.1:8081/ofs"))?;
}
peer.Update(new Announcement("my-player", "My Player",
[new Service(Protocol.OfsWs, "ws://127.0.0.1:8081/ofs")]));
funlink.update(Announcement.of("my-player", "My Player",
Service.of(Protocol.OFS_WS, "ws://127.0.0.1:8081/ofs")));
funlink.addService("ofs-ws", 8080, "/ofs"); // announced at once while running
In plain C, call funlink_peer_configure(&peer, &record, now) with the new record; a running peer announces it at once.
funlink.services.append({"protocol": "buttplug-ws", "endpoint": "ws://127.0.0.1:12345"})
funlink.update()
Stop announcing (close or dispose) when you no longer offer any service. Hubs forget an app 15 seconds after its last announcement anyway, so a crash cleans itself up.
5. Optional: show “Connected to …”
Each hub answers with its name and whether it is connected to you. Use it to show status in your own UI.
const funlink = announce(announcement, {
onHubs: (hubs) => {
const connected = hubs.find((h) => h.state === "connected");
statusLabel.text = connected ? `Connected to ${connected.hub.name}` : "";
},
});
#![allow(unused)]
fn main() {
let peer = funlink::Announcer::builder(announcement)
.on_hubs(|hubs| {
for h in hubs {
println!("{}: {}", h.hub.name, h.state);
}
})
.start()?;
}
await using var peer = FunlinkPeer.Announce(announcement,
onHubs: hubs => Console.WriteLine(string.Join(", ", hubs.Select(h => $"{h.Hub.Name}: {h.State}"))));
try (var funlink = Funlink.announce(announcement,
hubs -> hubs.forEach(h -> System.out.println(h.hub().name() + ": " + h.state())))) {
// ...
}
void loop() {
funlink.loop();
if (const char *hub = funlink.connectedHub()) {
Serial.printf("Connected to %s\n", hub);
}
}
funlink.hub() returns the most relevant hub with its name, ID, address and state.
funlink.hubs_changed.connect(func(hubs: Array) -> void:
for hub in hubs:
if hub.state == "connected":
$Status.text = "Connected to " + hub.hub.name)
| State | Meaning |
|---|---|
available | The hub may offer you to its user. |
connected | The hub is connected to one of your services. |
dismissed | The user said “Not now”; you won’t be offered again until your app restarts. |
unsupported | The hub cannot use any of your services. |
Next: choose the right protocol, test it and add the badge to your app’s page.