MultipeerPeerLinkFactory

expect class MultipeerPeerLinkFactory(displayName: String, serviceType: String) : Loom

Loom backed by Apple's MultipeerConnectivity framework.

Common API only — implementations live in the platform-specific source sets. appleMain provides the real implementation against platform.MultipeerConnectivity.*; jvmMain wraps a libkuilt.dylib over JNA so macOS desktop builds can talk to iPhones.

The factory is stateful — it owns the underlying MCPeerID/MCSession instances and the in-flight discovery map that gives MultipeerAdvertisement.handle its meaning. Construct one per device, share it via DI, and rely on Loom.open / Loom.join to spin up a session.

Parameters

displayName

Local display name surfaced to remote peers as the MCPeerID.displayName. Keep it short and recognisable (device name is the conventional choice).

serviceType

MultipeerConnectivity service-type string. Must be 1–15 ASCII letters, digits, or hyphens (same rules as Bonjour _service._tcp. minus underscores). Callers supply their own value; kuilt does not provide a default.

Constructors

Link copied to clipboard
expect constructor(displayName: String, serviceType: String)

Properties

Link copied to clipboard
expect val visiblePeers: StateFlow<Set<MultipeerAdvertisement>>

Snapshot of advertisements visible to this factory's current browse session. Updated reactively by the browse delegate on both foundPeer and lostPeer events, so the lobby's peer list reflects current reality (a host that stops advertising drops out of the set, even on the same device). Emitted as a StateFlow so the UI can collectAsState.

Functions

Link copied to clipboard
Link copied to clipboard
expect fun close()

Stops advertising / browsing / disconnects any active session. Safe to call multiple times. The factory remains usable: a fresh open / join call re-creates the session.

Link copied to clipboard
open suspend fun host(pattern: Pattern): Seam
Link copied to clipboard
open suspend fun join(tag: Tag): Seam
Link copied to clipboard
expect open suspend override fun weave(rendezvous: Rendezvous): Seam