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(() => {
initMeeting({ authToken: "<auth-token>" });
}, []);
useEffect(() => {
// next - if (meeting) meeting.join();
}, [meeting])
return <div></div>;
}

Use the Create Participant API to fetch the authToken.

Advanced Options

The Core SDK provides additional configuration options for advanced use cases. These options can be passed during initialization to customize the behavior of the RealtimeKit client.

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

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;
}