Skip to content

Plugins (games and mini apps)

A plugin is a small web bundle that runs inside the app and talks to the other can over the string. Two-player games are the obvious first use: noughts and crosses, a daily word duel, twenty questions, a countdown to the holiday. Because the relay is already opaque, plugin state rides the same encrypted envelope as chat, and the plugin never sees a key or the network.

  • Message kinds are open. Add app alongside chat, list, plan, sealed. Body: { appId, version, state }, encrypted like everything else.
  • The relay does not care. It stores ciphertext tagged with a kind; an app message is just another row.
  • Lists and plans already work this way. They are sent whole on every change with last-write-wins. A turn-based game is the same pattern with a rule about whose turn it is.
+------------------------------ Filocan app ------------------------------+
| Host (React Native) |
| crypto (@filocan/shared) store relay |
| ^ | |
| | send(state)| onState(state) |
| +------+------------v-----------------------------------------------+ |
| | WebView sandbox (no network, strict CSP, postMessage bridge only) | |
| | plugin bundle: index.html + app.js, talking to window.filocan | |
| +--------------------------------------------------------------------+ |
+-------------------------------------------------------------------------+

The host owns encryption, identity and the relay. The plugin owns rendering and rules. The only bridge is postMessage.

interface FilocanPluginSDK {
me: { name: string; id: string }; // ids are per-pair, not global
them: { name: string; id: string };
pairId: string; // opaque, for keying local storage
send(state: unknown): Promise<void>; // encrypted, delivered to both cans
onState(cb: (state: unknown, from: string, ts: number) => void): () => void;
history(limit?: number): Promise<{ state: unknown; from: string; ts: number }[]>;
storage: { get(k: string): Promise<string | null>; set(k: string, v: string): Promise<void> }; // local, per pair, per plugin
haptic(kind: 'light' | 'success' | 'error'): void;
close(): void;
theme: { ink: string; cream: string; coral: string; teal: string };
}

Deliberately absent: fetch, timers beyond the page’s own, access to other plugins’ state, the phone number, any global user id. A plugin can only talk to the other can, through the host, encrypted.

{
"id": "com.filocan.noughts",
"name": "Noughts & Crosses",
"version": "1.0.0",
"entry": "index.html",
"icon": "icon.svg",
"players": 2,
"sha256": "…of the bundle tarball…",
"author": "Filocan",
"sourceUrl": "https://github.com/vacodi/filocan-plugins"
}

Bundles are hosted by Filocan (Cloudflare R2 behind a CDN), pinned by hash, and cached on the device after first install. The app refuses a bundle whose hash does not match the catalogue entry.

  • react-native-webview with originWhitelist=['about:blank'], source loaded from the local cached bundle, javaScriptEnabled, allowFileAccess=false, and injectedJavaScriptBeforeContentLoaded installing the bridge.
  • CSP: default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; No connect-src, so fetch and WebSocket fail.
  • On web, an <iframe sandbox="allow-scripts"> with the same CSP and a postMessage bridge; the iframe is a null origin.
  • Message size cap (say 16 KB per send) and rate limit (a few per second) enforced by the host, so a runaway plugin cannot flood the string.
  • The host shows the plugin’s name and author above the WebView at all times; a plugin cannot draw over that chrome.

Keep the first version dumb: every send carries the whole state, the host encrypts it as an app message, and both cans render the latest by ts. Turn-based games need nothing more. Plugins that want real-time feel (a shared drawing pad) can send deltas with a sequence number and reconcile locally; the SDK does not need to know.

Per-pair state is the unit. A plugin installed on one string is not visible on another (see Many strings). Per-account plugins, if ever wanted, are a small layer on top: the catalogue remembers what you installed, and each string still holds its own state.

Start curated: a catalogue of plugins built by Filocan, listed in the app’s Plugins tab, hash-pinned. Then open the SDK and accept community plugins by pull request to a public filocan-plugins repository, reviewed and built by CI so the published hash always matches reviewed source. A permissionless upload path is not planned: a plugin cannot reach the network, but it can still mislead the person in front of it, and Filocan’s whole pitch is trust.

  1. Noughts & Crosses: nine cells, a turn, a winner. Proves the loop.
  2. Word duel: both pick a five-letter word for the other; sealed until both have chosen (reuse seal), then a Wordle-style guess race.
  3. Countdown: a shared date and a photo, counting down to the plan. Proves non-game utility and reuses plan data.

Two to four weeks: a week for the WebView bridge, SDK and sandbox on all three platforms; a week for the catalogue, install flow and hash pinning; one to two weeks for the three plugins and the Plugins tab. Store review needs a note that plugins are sandboxed web content with no network access, which Apple accepts when the content is hosted and reviewed by the developer (guideline 4.7).

  • Should a plugin be able to post into the chat (‘Andrew won at noughts and crosses’)? Useful and fun; implement as a host-side option the plugin requests, so it cannot spam.
  • Do plugins get haptics and notifications? Haptics yes; notifications only via the host’s normal ‘new message’ path, never their own.