Frontend App Bridge SDK
@fynncloud/app-bridge (v0.1.0) is the browser SDK for apps with a web UI running inside FynnCloud’s sandboxed opaque-origin <iframe>. It handles bidirectional window.postMessage RPCs, theme/locale synchronization, automatic token refresh and 401 retry, native host modals/pickers, real-time events, and cross-app requests.
Installation & Bootstrap
Section titled “Installation & Bootstrap”npm install @fynncloud/app-bridgeimport fynncloud from '@fynncloud/app-bridge';
fynncloud.on('init', (ctx) => { console.log('App:', ctx.appId, 'Theme:', ctx.theme, 'User:', ctx.user);});
// Signal readiness to the FynnCloud host (also reports current proxy subpath on popstate)fynncloud.init();fynncloud.init() automatically toggles .dark / .light classes on document.documentElement whenever init or themeChange arrives, and ignores postMessage frames whose event.source !== window.parent.
BridgeContext & BridgeUser Reference
Section titled “BridgeContext & BridgeUser Reference”Accessible via fynncloud.context and emitted on the 'init' event:
BridgeContext (All 17 Fields)
Section titled “BridgeContext (All 17 Fields)”| Property | Type | Default | Description |
|---|---|---|---|
appId |
string | null |
null |
Manifest ID of this app |
theme |
'dark' | 'light' |
'dark' |
Active host color scheme |
primaryColor |
string |
'#6366f1' |
Instance branding primary color |
locale |
string |
'en' |
Active UI locale (en, de, fr, it) |
token |
string | null |
null |
Current scoped AppAccessToken JWT |
apiBase |
string | null | undefined |
undefined |
FynnCloud Core API origin |
version |
string | null | undefined |
undefined |
Running FynnCloud Server version |
subroute |
string | undefined |
'' |
Active subpath inside the app (synced with host URL) |
sidebarMode |
'rail' | 'integrated' | undefined |
'integrated' |
Current host sidebar layout mode |
readOnly |
boolean | undefined |
false |
true when opened on a read-only file/share |
realtimeStream |
boolean | undefined |
true |
false when hidden/non-leader tab or over browser stream cap |
hostRealtime |
boolean | undefined |
false |
true when the host forwards POST /api/apps/realtime/publish events via onRealtime() (so your app needs no SSE/WS of its own) |
hostHidden |
boolean | undefined |
false |
Whether the host browser tab is currently hidden (document.hidden) |
user |
BridgeUser | null |
null |
Signed-in user info (see below; null on anonymous share links) |
integrations |
BridgeAppIntegration[] | undefined |
[] |
Resolved availability & compatibility status for every target app in compatibility.apps |
fileAction |
Record<string, any> | null |
null |
Active file-hook or new_file payload |
fileId / fileName |
string | null |
null |
Convenience file ID and filename for single-file hooks |
BridgeUser (Exact Fields)
Section titled “BridgeUser (Exact Fields)”export interface BridgeUser { id: string; username?: string; displayName?: string | null; avatarUpdatedAt?: string | null; status?: 'online' | 'busy' | 'dnd' | 'away' | 'offline'; presenceMode?: 'auto' | 'online' | 'busy' | 'dnd' | 'away' | 'offline'; statusMessage?: string | null; activity?: string | null; activityLabel?: string | null;}All 14 Host Broadcast Events
Section titled “All 14 Host Broadcast Events”Subscribe with const unsub = fynncloud.on('<event>', handler) (returns an unsubscribe function):
| Event Name | Payload Shape | When It Fires |
|---|---|---|
init |
BridgeContext |
Initial handshake after fynncloud.init() |
tokenRefresh |
string (new JWT) |
Host proactively refreshed the AppAccessToken |
tokenError |
{ reason: string } |
Host failed to renew the session token |
fileAction |
Record<string, any> |
User invoked a file hook or new_file action |
themeChange |
{ theme: 'dark' | 'light', primaryColor?: string } |
User toggled Light/Dark theme or branding color changed |
subrouteChange |
{ subroute: string } |
Host navigated to a new subpath inside your app |
localeChange |
{ locale: string } |
User switched workspace language |
sidebarModeChange |
{ sidebarMode: 'rail' | 'integrated' } |
Host sidebar layout changed |
sidebarAction |
{ actionId: string, itemId?: string, ... } |
User clicked an action button on a ui.sidebar item |
sessionAction |
{ actionId: string, ... } |
User clicked a button on the floating Active Session mini-bar |
notificationAction |
{ id: string, actionId: string, route?: string } |
User clicked an action button on a host persistent notification |
presenceUpdated |
BridgePresenceEntry |
A user’s presence/activity changed (also updates context.user when matching current user) |
lifecycle |
{ realtimeStream: boolean, hidden: boolean } |
Host tab visibility or realtime stream leadership changed |
realtime |
{ event: string, data: any } |
Backend published an event via POST /api/apps/realtime/publish (also reachable via onRealtime(cb)) |
realtimeReady |
{} |
Host SSE stream connected or reconnected—re-fetch missed state here (also reachable via onRealtimeReady(cb)) |
(Note: init, tokenRefresh, tokenError, fileAction, themeChange, subrouteChange, localeChange, sidebarModeChange, sidebarAction, sessionAction, notificationAction, presenceUpdated, lifecycle, realtime, and realtimeReady cover all 15 switch cases in handleMessage, with onRealtime / onRealtimeReady as typed wrappers.)
Complete SDK Methods Reference (All 24 Methods)
Section titled “Complete SDK Methods Reference (All 24 Methods)”Standard RPCs time out after 10 seconds; interactive UI RPCs (confirm, pickFiles) time out after 10 minutes.
Lifecycle, Auth & Networking
Section titled “Lifecycle, Auth & Networking”| Method | Signature | Behavior |
|---|---|---|
init() |
init(): this |
Reports current proxy subpath (fynncloud:ready) and starts receiving host events |
on() |
on<T>(event, handler): UnsubscribeFn |
Subscribe to any host broadcast event |
onRealtime() |
onRealtime<T>(handler: (event, data: T) => void): UnsubscribeFn |
Subscribe to backend events published via POST /api/apps/realtime/publish |
onRealtimeReady() |
onRealtimeReady(handler: () => void): UnsubscribeFn |
Fires whenever the host SSE stream connects/reconnects (resync point) |
fetch() |
fetch(input: string | URL, init?: RequestInit): Promise<Response> |
Injects Authorization: Bearer <token>, automatically retries once on 401 after calling getToken(true) (unless body is a ReadableStream), and resolves root-relative paths: /api/apps/*, /api/presence*, and /api/user/status route to context.apiBase; all other /... paths automatically prefix your app’s /api/apps/<id>/proxy path! |
fetchApp() |
fetchApp(targetAppId, path, init?): Promise<Response> |
Calls another app declared in compatibility.apps via /api/apps/<targetAppId>/proxy/<path> |
getIntegration() |
getIntegration(targetAppId): BridgeAppIntegration | null |
Synchronous lookup of a declared target app’s { installed, runnable, compatible, available, access, version } |
getToken() |
getToken(forceRefresh = false): Promise<{ token: string | null }> |
Fetch current or freshly minted AppAccessToken |
ping() |
ping(): Promise<{ pong: boolean, timestamp: number, version?: string }> |
Healthcheck host bridge connectivity |
Host UI, Navigation, Badges & Sessions
Section titled “Host UI, Navigation, Badges & Sessions”| Method | Signature | Behavior |
|---|---|---|
getTheme() |
getTheme(): Promise<{ theme, primaryColor }> |
Query current theme and branding color |
getFileAction() |
getFileAction(): Promise<any> |
Retrieve pending file-action payload |
navigate() |
navigate(path, options?: boolean | { external?, replaceState? }) |
Update host URL subroute or navigate externally (supports boolean legacy 2nd arg for external) |
close() |
close(): Promise<{ success: boolean }> |
Close an open modal file editor / overlay |
setSidebar() |
setSidebar(items: any[]) |
Dynamically replace items in FynnCloud’s native host sidebar |
setSidebarMode() |
setSidebarMode('rail' | 'integrated') |
Switch host sidebar layout dynamically |
openFilePreview() |
openFilePreview(fileId, fileName?, mimeType?) |
Launch FynnCloud’s native Image / Video / PDF / Audio viewer overlay |
setBadge() |
setBadge(badge: BridgeAppBadge | null) |
Set unread count, colored dot (emerald/amber/red/primary), pulse, and tooltip on the App Switcher rail icon (null clears) |
setActiveSession() |
setActiveSession(session: BridgeActiveSession | null) |
Render the floating bottom-center Active Session mini-bar (title, subtitle, status: 'live'|'playing'|'recording'|'active', startedAt live timer, returnPath, keepAlive [default true keeps iframe mounted while user browses Files!], actions[] emitting sessionAction) |
Modals, Pickers, Notifications & Presence
Section titled “Modals, Pickers, Notifications & Presence”| Method | Signature | Behavior |
|---|---|---|
confirm() |
confirm({ title, description?, confirmLabel?, cancelLabel?, variant?: 'primary'|'danger' }): Promise<boolean> |
Show a native FynnCloud confirmation dialog (10-min timeout) |
pickFiles() |
pickFiles({ multiple?, accept?, title? }): Promise<BridgePickedFile[] | null> |
Open FynnCloud’s native Drive file picker (null if cancelled); selected file IDs are also authorized on the app token for files:selected:read |
showToast() |
showToast(message, type = 'info', duration = 3000) |
Display an ephemeral toast banner (info, success, warning, error) |
notify() |
notify(options: BridgeNotificationOptions) |
Display a rich or persistent top-right notification card (id, title, body, avatarText/avatarUrl, route, actions[], persistent, expiresAt, sound: 'none'|'chime'|'loop', tag, desktop) |
dismissNotification() |
dismissNotification(id: string) |
Dismiss an active host notification by its app-scoped id |
getPresence() |
getPresence(userIds?: string[]): Promise<{ users: BridgePresenceEntry[] }> |
Fetch live presence & activity (requires user:read) |
setStatus() |
setStatus({ presenceMode?, statusMessage?, clearStatusMessage?, expiresInMinutes? }): Promise<BridgePresenceEntry> |
Update the signed-in user’s Core presence mode or status note (requires presence:write) |
Per-Browser Scoped Key-Value Storage (fynncloud.storage)
Section titled “Per-Browser Scoped Key-Value Storage (fynncloud.storage)”fynncloud.storage.get<T>(key)/.set(key, value)/.delete(key)- Limits enforced by the host: valid key regex, maximum 64 KB per value, maximum 50 keys per app.
Host Media Capture Relay (media:capture)
Section titled “Host Media Capture Relay (media:capture)”Because opaque-origin (sandbox without allow-same-origin) iframes cannot invoke navigator.mediaDevices.getUserMedia() or getDisplayMedia() reliably across browsers (Safari/Firefox reject opaque origins), FynnCloud provides a host WebRTC loopback media relay for apps declaring media:capture:
- The app sends a
postMessagehandshake with aMessageChanneldirectPortusingfynncloud:media:*messages (requestingaudio,video, ordisplaycapture, device enumeration, or track toggle/stop). - The FynnCloud host acquires the real hardware microphone, camera, or screen share stream in the trusted top-level origin (so the browser permission prompt displays your FynnCloud instance domain cleanly).
- The host bridges the
MediaStreamTracks into the sandboxed iframe over a local in-browserRTCPeerConnectionloopback negotiated over theMessageChannelport, allowing your app to attach the receivedMediaStreamstraight into LiveKit or P2P WebRTC with sub-millisecond local latency.