Skip to main content

Quickstart

Broadcast and view your first livestream

In this tutorial you install the Native Frame client and build two small apps: a broadcaster that streams your camera, and a viewer that watches it. By the end you will have a livestream playing in your own page. Set your framework once in the sidebar — the samples in every step follow it, and the three steps are the same either way.

Prerequisites​

Before you start, you need a Native Frame account and three values from it:

CredentialWhat it looks likeFrom
Authentication token (JWT)A signed token string.Generate an API token
Stream keyIdentifies the stream you publish to.Get your RTMP URL and stream key
Backend endpointhttps://your-subdomain.nativeframe.comCopy your backend endpoint

If you do not have these yet, follow Create an account and get credentials first, then come back here.

Want to see a stream working first?

You do not need any of this to watch a stream play. Create an account and get credentials opens with a no-code path: create a stream in the dashboard, publish to it from software like OBS, and play it back — no token, no install. Come here when you want to build it into your own app.

You paste those values in by hand below, which is fine for a local run. Before you ship anything, read Token setup: in production your backend mints a short-lived token per session instead.

Already have a backend?

Instead of pasting values in, fetch backendEndpoints, streamKey, and the token from your own endpoint when the page loads. Configure from your server shows the request, the validation, and which values are safe in the browser.

Steps​

Step 1: Install the client​

Install the Native Frame client if you have not already — Installation covers npm, yarn, and the CDN, and is the one place install is taught:

npm install @video/video-client-react

Building the vanilla JavaScript version instead? Installation's CDN tab has the import map to use; there is nothing to install for that path.

Step 2: Build your first broadcaster​

Create a broadcaster that streams your camera to viewers. In order, the code below authenticates with your token, initialises the camera and shows a local preview, configures the call with your stream key and backend endpoint, and wires up the start and stop controls.

Do not ship a token in client-side code

The token literals in the code below are for a local tutorial run only. Anything you put in front-end JavaScript is readable by anyone who loads the page. In production your backend mints a short-lived token per session — see Token setup.

Declare the camera and microphone permissions first. On iOS, add NSCameraUsageDescription and NSMicrophoneUsageDescription to ios/<your app>/Info.plist:

<key>NSCameraUsageDescription</key>
<string>This app needs camera access for video streaming</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs microphone access for audio streaming</string>

On Android, add CAMERA, RECORD_AUDIO, and INTERNET to android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />

Then build the broadcaster. getSession holds your backend endpoint and the stream name, and <Encoder />, whose only prop is that session, renders a live camera preview with a one-tap broadcast control, front camera first:

import React from 'react';
import { View } from 'react-native';
import { Encoder, getSession } from '@video/react-native-sdk';

export default function Broadcaster() {
const session = getSession({
backendEndpoint: 'https://your-subdomain.nativeframe.com',
displayName: 'Quickstart broadcaster',
streamName: 'quickstart',
});

return (
<View style={{ flex: 1 }}>
<Encoder session={session} />
</View>
);
}

You now have a broadcaster with a camera preview and a broadcast button. The stream it publishes is identified by its streamName, and the viewer in Step 3 plays it by manifest URL rather than by call ID. For a complete app, see the react-native-native-frame-demo repository: nativeframe is the shared GitHub organization that hosts the demo, not a different product, and you install the SDK it uses from the shared @video registry.

Step 3: Build your first viewer​

Create a viewer that plays the broadcast. The viewer connects by call ID — the ID of the call your broadcaster created in Step 2 — so get that value first. The React and vanilla JavaScript tabs take the same one; the React Native tab takes a manifest URL instead, and says so.

Verify the loop end to end (React and vanilla JavaScript): run your broadcaster, take the call ID it gives you (the React version renders it on the page, the vanilla version logs it to the console), and pass it to the viewer as callId. When the viewer shows your camera, the broadcast-to-playback loop works. React Native has its own verify step in its tab below.

import React, { useState } from 'react';
import { useAuthClient } from '@video/video-client-react/hooks';
import { PlayerAPIProvider } from '@video/video-client-react/context';
import { Video } from '@video/video-client-react/components';
import { createPlayer } from '@video/video-client-react';

function Viewer({ callId }) {
const [player, setPlayer] = useState(null);

const authClient = useAuthClient('your-viewer-token');

React.useEffect(() => {
let created;
let cancelled = false;

createPlayer({
callId: callId,
streamName: 'default',
backendEndpoints: ['https://your-subdomain.nativeframe.com'],
auth: authClient
}).then((next) => {
created = next;
// If the component unmounted while createPlayer was still resolving,
// dispose immediately rather than storing a player nobody will clean up.
if (cancelled) next.dispose();
else setPlayer(next);
});

return () => {
cancelled = true;
created?.dispose();
};
}, [callId, authClient]);

if (!player) return <div>Loading stream...</div>;

return (
<PlayerAPIProvider player={player}>
<div>
<h1>Watching Livestream</h1>
<Video />
</div>
</PlayerAPIProvider>
);
}

export default Viewer;

// Render it with the call ID your broadcaster printed on the page in Step 2.
// Hard-coding it is fine while you are following this guide; in a real app the
// broadcaster would hand this to the viewer over your own backend.
//
// <Viewer callId="call-id-from-broadcaster" />

Open the broadcaster and click Start Broadcasting, then load the viewer with that callId. Your camera should appear in the viewer's player.

Next steps​

Now that the basics work, go deeper: