session-react
React components and hooks for embedding a live Aperture session, with or without the built-in UI.
npm install @aperture-browser/session-react effect react react-domThe package has two entry points:
@aperture-browser/session-react: the session with its UI: tab strip, toolbar and menus.@aperture-browser/session-react/headless: the session alone, with no UI kit or stylesheet, for apps that build their own controls.
Both use a SessionAccess connection: direct Aperture access or a same-origin backend relay. The relay authenticates the app user and keeps Aperture credentials on the backend. Direct cross-origin access requires embed_allowed_origins.
Full UI
import { useMemo } from "react";
import { ApertureSession, shareSessionAccess } from "@aperture-browser/session-react";
import "@aperture-browser/session-react/styles.css";
export function SharedBrowser({ token }: { token: string }) {
const access = useMemo(() => shareSessionAccess(token, "https://aperture.example"), [token]);
return (
<div style={{ height: 600 }}>
<ApertureSession access={access} />
</div>
);
}Prop
Type
Consumer-authenticated relay
const access = { kind: "relay", baseUrl: "/aperture", sessionId: "your-session-id" } as const;
<ApertureSession access={access} />;No token or role is supplied by the browser. The consumer backend authenticates its own login cookie and selects an upstream viewer/editor capability. Relative mount prefixes are preserved for status and both WebSockets. WebRTC video and data channels still connect directly to Aperture.
Features
features turns parts of the UI off, e.g. { tabs: false, menus: false }. Each switch defaults to on. navigation is the back, forward and reload buttons, presence shows who else is connected, and menus holds the stream, viewport, recording and input settings. Turn toaster off if your app renders its own sonner toaster.
Prop
Type
Styles
styles.css styles everything inside the component's .aperture-root element: theme colors and a scoped reset. It does not touch your page's html, body or :root, and menus and tooltips render inside the root. Its utility classes carry an aperture: prefix, and its keyframes, cascade layers and registered custom properties are namespaced with aperture-, so they do not clash with your page's own Tailwind. Your own unlayered CSS can still override them. Dark mode follows the root's theme, not a dark class on your page. For full isolation, use session-element, which renders into Shadow DOM.
Classes supplied through className are preserved, but your page's Tailwind utilities do not replace Aperture's prefixed defaults; precedence depends on cascade layer order. Use an unlayered CSS class for overrides, or set the size on an outer wrapper.
The component uses your page's font. To pick others, set --aperture-font-sans and --aperture-font-mono (used for URLs) on it or any ancestor, e.g. --aperture-font-sans: "Inter", sans-serif.
Headless
import {
ApertureProvider,
SessionViewport,
useSession,
type SessionAccess,
} from "@aperture-browser/session-react/headless";
function Browser({ access }: { access: SessionAccess }) {
const { status, control } = useSession({ access, onNotice: console.warn });
if (status !== "ready") return <p>{status}</p>;
return (
<>
{control.targets.map((tab) => (
<button key={tab.id} onClick={() => control.activateTarget(tab.id)}>
{tab.title}
</button>
))}
<button onClick={() => control.historyBack()}>Back</button>
<SessionViewport control={control} style={{ height: 600 }} />
</>
);
}
const access: SessionAccess = { kind: "relay", baseUrl: "/aperture", sessionId: "your-session-id" };
export const App = () => (
<ApertureProvider>
<Browser access={access} />
</ApertureProvider>
);ApertureProvider creates the Effect runtime the hooks run on. Session routes use access.baseUrl; the provider's optional baseUrl configures account/management API calls only. Keep the access object stable across renders, for example with useMemo.
useSession
Loads session status and connects. status is loading, ready, invalid, denied, expired or unavailable. ready means bootstrap succeeded; inspect control.phase for the live connection. The server snapshot supplies control.collaboration.role; controls remain restricted until connected. onNotice receives the errors and confirmations the full UI shows as toasts.
Prop
Type
Prop
Type
control lists the tabs (targets, activeTargetId) and has fire-and-forget actions such as navigate, historyBack, createTarget and activateTarget. control.commands has the same actions as Effects that succeed once Aperture has carried them out and fail with a LiveSessionError otherwise:
yield * control.commands.navigate("https://example.com");
const tabId = yield * control.commands.createTarget();Prop
Type
SessionViewport
Shows the active tab and forwards keyboard, pointer and clipboard input to it. It is styled inline and fills its container. renderOverlay receives the connection status, a placeholder reason while there is no picture yet, and cursor hints, so you can draw your own overlays.
Prop
Type
Prop
Type
Lower-level pieces
Session is the full view without its own root, runtime and toaster, for apps that compose them. ApertureUIRoot renders the .aperture-root element with its theme, keeps menus and tooltips inside it, and provides tooltips; ApertureProvider (or RuntimeProvider with makeApertureRuntime) supplies the runtime:
import { ApertureProvider, ApertureUIRoot, Session } from "@aperture-browser/session-react";
import "@aperture-browser/session-react/styles.css";
<ApertureUIRoot theme="dark">
<ApertureProvider baseUrl={access.baseUrl}>
<Session access={access} />
</ApertureProvider>
</ApertureUIRoot>;theme defaults to system; className applies to the root element. This is a light-DOM root, not a CSS isolation boundary: the stylesheet is namespaced, but your page's CSS still reaches inside it.
Prop
Type
Errors and confirmations appear as toasts only when your app renders a Sonner Toaster. useBrowserControl and BrowserControlPane drive and render a session for other credentials, inside the same root. These are what the Aperture web app is built from.
Requires effect 4 and React 19.