OptionalbaseBase URL for the cloud service (overrides environment if provided)
Children components
OptionalcloudCloud token for browser-safe authentication.
The token includes a ct_ prefix and is short-lived (default 24h). Obtain this from your backend server's cloud-token endpoint.
const [cloudToken, setCloudToken] = useState<string>();
useEffect(() => {
fetch('/api/cloud-token', { method: 'POST' })
.then(res => res.json())
.then(data => setCloudToken(data.cloudToken));
}, []);
if (!cloudToken) return <Loading />;
return <CloudProvider cloudToken={cloudToken}>...</CloudProvider>;
OptionalenvironmentEnvironment to connect to (optional).
When omitted, auto-detected from the token response if generateCloudToken
returns { cloudToken, environment }.
OptionalgenerateFunction to generate cloud tokens (recommended for browser)
This function is called lazily on first request and automatically
when the token expires. The SDK passes { userId } so your callback
can forward it to the backend. Can return a plain string or
{ cloudToken, environment } for automatic environment detection.
async function generateCloudToken({ userId }: { userId: string }) {
const res = await fetch('/api/generate-cloud-token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ userId }),
});
const { cloudToken, environment } = await res.json();
return { cloudToken, environment };
}
<CloudProvider userId="user@example.com" generateCloudToken={generateCloudToken}>
<App />
</CloudProvider>
OptionaltimeoutRequest timeout in milliseconds (optional)
OptionaluserThe current user's email address.
When omitted, automatically resolved from HiyveProvider's store (set when the user creates/joins a room). Pass explicitly only if you need cloud tokens before joining a room.
Props for CloudProvider
Authentication can be provided in two ways (in order of preference):