Skip to content
Cloudflare Docs

Build using Core SDK

Initialize Core SDK

To integrate the Core SDK, you will need to initialize it with a participant's auth token, and then use the provided SDK APIs to control the peer in the session.

Initialization might differ slightly based on your tech stack. Please choose your preferred tech stack below.

Install the client SDK

Terminal window
npm i @cloudflare/realtimekit-react

Use the useRealtimeKitClient hook to initialise the SDK.

App.tsx
import { useEffect } from 'react';
import { useRealtimeKitClient } from '@cloudflare/realtimekit-react';
export default function App() {
const [meeting, initMeeting] = useRealtimeKitClient();
useEffect(() => {
const meetingDefaultOptions = {
audio: true,
video: true,
};
initMeeting({
authToken: "<auth-token>",
defaults: meetingDefaultOptions, // optional
});
}, []);
useEffect(() => {
// next - if (meeting) meeting.join();
}, [meeting])
return <div></div>;
}

Use the Create Participant API to fetch the authToken.

Advanced Options

You can optionally configure meeting defaults, media quality, screen share preferences, simulcast settings, ice connection behavior, logging, and error handling while initializing the SDK.

TypeScript
init({
authToken: "<auth_token>",
defaults: {
video: true,
audio: true,
mediaConfiguration: {
// Configure custom video quality (e.g., 1080p). Disable simulcast using `simulcastConfig` override for single-layer streaming.
video: {
width: { ideal: 1920 },
height: { ideal: 1080 },
frameRate: { ideal: 15 },
},
screenshare: {
frameRate: { ideal: 15, max: 30 }, // Default 5
displaySurface: "monitor", // Given surface is suggested to the end user
},
},
},
overrides: {
simulcastConfig: {
// If you want to disable simulcast
disable: false,
// If you want to pass custom simulcast encodings
encodings: [
{
rid: "f", // full / highest quality
scaleResolutionDownBy: 1.0,
maxBitrate: 2500000, // ~2.5 Mbps
},
{
rid: "h", // half
scaleResolutionDownBy: 2.0,
maxBitrate: 900000, // ~0.9 Mbps
},
{
rid: "q", // quarter
scaleResolutionDownBy: 4.0,
maxBitrate: 250000, // ~0.25 Mbps
},
],
},
forceRelay: false, // forceRelay, if true, TURN will be preferred over STUN
},
modules: {
devTools: {
logs: true, // Prints SDK logs to console, Useful in initial integration phase
},
},
onError: (error) => {
console.error(error); // SDK errors, Useful in detecting common issues
},
});

You can pass the following options as defaults to alter default behavior.

OptionDescriptionTypeRequired
videoShould video be enabled by defaultbooleanfalse
audioShould audio be enabled by defaultbooleanfalse
mediaConfigurationAllows you to pass custom media quality constraintsMediaConfigurationfalse
autoSwitchAudioDeviceAutomatically switch to a newly plugged microphone or speakerbooleanfalse
isNonPreferredDeviceAllows you to set specific devices as "not preferred"(device: MediaDeviceInfo) => booleanfalse
recordingAllows you to configure recording settingsRecordingConfigfalse

By default, audio and video are auto enabled, as per preset permissions. SDK uses 640x480 quality as default for group calls, which can be overridden with mediaConfiguration. By default, the SDK automatically switches to the best available device and marks virtual devices as not preferred.

Reference for the types:

TypeScript
interface AudioQualityConstraints {
echoCancellation?: boolean;
noiseSupression?: boolean;
autoGainControl?: boolean;
enableStereo?: boolean;
enableHighBitrate?: boolean;
}
interface VideoQualityConstraints {
width: { ideal: number };
height: { ideal: number };
frameRate?: { ideal: number };
}
interface ScreenshareQualityConstraints {
width?: { max: number };
height?: { max: number };
frameRate?: {
ideal: number;
max: number;
};
displaySurface?: "window" | "monitor" | "browser";
selfBrowserSurface?: "include" | "exclude";
}
interface MediaConfiguration {
video?: VideoQualityConstraints;
audio?: AudioQualityConstraints;
screenshare?: ScreenshareQualityConstraints;
}
interface RecordingConfig {
fileNamePrefix?: string;
videoConfig?: {
height?: number;
width?: number;
codec?: string;
};
}
interface DefaultOptions {
video?: boolean;
audio?: boolean;
mediaConfiguration?: MediaConfiguration;
isNonPreferredDevice?: (device: MediaDeviceInfo) => boolean;
autoSwitchAudioDevice?: boolean;
recording?: RecordingConfig;
}
interface Overrides {
simulcastConfig?: {
disable?: boolean;
encodings?: RTCRtpEncodingParameters[];
};
forceRelay?: boolean;
}