Configure from your server
Fetch backendEndpoints, streamKey, and a token from your own endpoint instead of hardcoding them
To move past the Quickstart's pasted-in values, have your page ask your own backend for the Native Frame connection values — backendEndpoints, streamKey, and a user token — check that each one arrived, and only then hand them to the SDK.
Prerequisites
- A server that follows Create Streams Server-Side: it holds the service-account JWT, creates streams, and mints a short-lived user JWT per session.
- A finished Quickstart, so you know where
backendEndpoints,streamKey, andauthgo increateCallandrequestPlayer. - A config endpoint on that server. This guide uses
GET /api/stream-config, answering with JSON in this shape:
{
"backendEndpoints": ["https://your-subdomain.example.com"],
"streamKey": "your-stream-key",
"manifestUrl": "https://.../<streamId>.json",
"token": "<short-lived user JWT>"
}
manifestUrl only applies to a viewer page; a broadcaster page can ignore it. Treat it as opaque and pass it to the playback SDK verbatim — see Manifests.
Which values belong in the browser
| Value | Browser-safe? | Why |
|---|---|---|
backendEndpoints | Yes | Public host names the SDK connects to. |
streamKey | Yes, on the broadcaster's page | Names the stream to publish to; the token is what authorizes publishing. |
manifestUrl | Yes, on the viewer's page | Complete URL the viewer's player polls; opaque, never construct or modify it. |
User JWT (token) | Yes | Short-lived and scoped to one user and one role, such as broadcaster or viewer. |
| Service-account JWT | No | Long-lived, with broad permissions. It stays on the server and only mints user JWTs — see Service Account JWTs vs User JWTs. |
Procedure
- Fetch the configuration before you touch the SDK. Send the user's session cookie or header so your server can mint a token for that user.
async function loadStreamConfig() {
const response = await fetch('/api/stream-config', { credentials: 'include' });
if (!response.ok) {
throw new Error(`Config request failed with HTTP ${response.status}`);
}
return response.json();
}
- Validate each value. Destructure the response and stop at the first missing field, naming it, so an empty
{}response reads as "missing backendEndpoints" instead of a stack trace from inside the SDK.
function validateStreamConfig(config) {
const { backendEndpoints, streamKey, manifestUrl, token } = config ?? {};
if (!Array.isArray(backendEndpoints) || backendEndpoints.length === 0) {
throw new Error('Stream config is missing backendEndpoints');
}
if (typeof streamKey !== 'string' || streamKey === '') {
throw new Error('Stream config is missing streamKey');
}
if (manifestUrl != null && (typeof manifestUrl !== 'string' || manifestUrl === '')) {
throw new Error('Stream config has an invalid manifestUrl');
}
if (typeof token !== 'string' || token === '') {
throw new Error('Stream config is missing token');
}
return { backendEndpoints, streamKey, manifestUrl, token };
}
- Show the error where the reader can see it. Render the message into the page rather than leaving it in the console.
function showConfigError(error) {
const box = document.getElementById('config-error');
box.textContent = error.message;
box.hidden = false;
}
- Pass the validated values to the SDK. Only now create the auth client and then the call or the player.
import { createCall, requestPlayer, BaseAuthClient } from 'vdc-cdn';
let config;
try {
config = validateStreamConfig(await loadStreamConfig());
} catch (error) {
showConfigError(error);
throw error;
}
const authClient = new BaseAuthClient(config.token);
// Broadcaster page
const call = await createCall({
streamKey: config.streamKey,
backendEndpoints: config.backendEndpoints,
auth: authClient,
user: { userId: 'user-123', displayName: 'Broadcaster' },
});
// Viewer page: your server can return the manifest URL the same way.
// Pass the same auth client when the stream is private.
const player = await requestPlayer(config.manifestUrl, { auth: authClient, autoPlay: true });
Result
The page loads with no pasted-in values. With a complete response, the broadcaster starts a call, or the viewer's player attaches, exactly as in the Quickstart. With an incomplete response such as {}, the page shows Stream config is missing backendEndpoints before any SDK call runs, and nothing else happens.
Troubleshooting
The page shows "Stream config is missing token"
Your endpoint answered, but without a user JWT. Check that the server mints a token for the signed-in user on this request and that the JSON key is spelled token. The service-account JWT is not a substitute; it must never reach the browser.
The SDK reports a permission error after the config loads
The token arrived but carries the wrong scope for the page: a viewer token cannot broadcast, and a public-stream viewer token cannot open a private stream. Mint the scope the page needs — see Token Setup.
Related
- Create Streams Server-Side — the server that answers this request.
- Token Setup — scopes, refresh, and security for the token you fetch.
- Tokens and scopes — what each scope group grants.
- Quickstart — the pasted-in version this guide replaces.