An override is a setting that your app passes to the Core SDK. The SDK uses your value instead of the value that RealtimeKit normally uses.
Normally, two things control how the Core SDK works for a participant:
- The preset: You create the preset on the server and assign it to a participant. For example, the preset turns simulcast on or off.
- The SDK defaults: The Core SDK chooses these values automatically. For example, the SDK chooses the network path.
An override changes one of these values for one participant on one device.
Use a preset when the same setting applies to every participant with the same role. Use an override when your app must choose a setting for one participant when that participant joins.
For example, the preset for your hosts turns simulcast on, because most of their meetings are large. Your app also has 1:1 calls. Simulcast does not help much in a 1:1 call. Your app can pass an override that turns off simulcast for 1:1 calls only. The preset does not change.
An override has a limited effect:
- It changes the behavior for one participant only. It does not change anything for other participants.
- It works for one meeting object only. The SDK reads the overrides one time, when you initialize the SDK.
- You set it in your app code. It does not change the preset.
Most apps do not need overrides. If you are not sure that you need an override, do not use it.
Put all overrides in one object named overrides. Each override is one key in this object.
Pass the overrides object in the options of initMeeting. You get initMeeting from the useRealtimeKitClient hook.
import { useEffect } from "react";
import { useRealtimeKitClient } from "@cloudflare/realtimekit-react";
const overrides = {
forceRelay: true,
};
export default function App() {
const [meeting, initMeeting] = useRealtimeKitClient();
useEffect(() => {
initMeeting({
authToken: "<auth-token>",
overrides,
});
}, []);
return <div>Your meeting component comes here</div>;
}Pass the overrides object in the options of RealtimeKitClient.init().
const overrides = {
forceRelay: true,
};
const meeting = await RealtimeKitClient.init({
authToken: "<auth-token>",
overrides,
});Pass the overrides object in the options of RealtimeKitClient.init().
import { Component, OnInit } from "@angular/core";
import RealtimeKitClient from "@cloudflare/realtimekit";
const overrides = {
forceRelay: true,
};
@Component({
selector: "app-meeting",
template: `<div>Your meeting component comes here</div>`,
})
export class MeetingComponent implements OnInit {
meeting: RealtimeKitClient;
async ngOnInit() {
this.meeting = await RealtimeKitClient.init({
authToken: "<auth-token>",
overrides,
});
}
}The following rules apply to every override:
- Every override is optional. If you do not set an override, the SDK uses its normal behavior for that setting.
- You can use more than one override. Add each override as a separate key in the same object.
- You cannot change the overrides after initialization. To use different values, initialize the SDK again.
The following table lists the overrides that the Core SDK supports:
| Override | Area | Type | Description |
|---|---|---|---|
simulcastConfig |
Media | object |
Turns off simulcast, or changes the video layers. |
forceRelay |
Network | boolean |
Sends and receives all media through a TURN relay server. |
The overrides object has the following type:
interface Overrides {
simulcastConfig?: {
disable?: boolean;
encodings?: RTCRtpEncodingParameters[];
};
forceRelay?: boolean;
}Use simulcastConfig to change simulcast for the camera video that the participant sends.
With simulcast, the SDK sends the camera video in several qualities at the same time. Each quality is called a layer. For each viewer, the media server chooses the layer that works best with the viewer's network and screen layout.
The participant's preset turns simulcast on or off. When simulcast is on, the SDK chooses the layers. With this override, you can turn simulcast off, or you can choose your own layers.
The following table lists the fields of simulcastConfig:
| Field | Type | Default | Description |
|---|---|---|---|
disable |
boolean |
false |
Sends camera video as a single layer. |
encodings |
RTCRtpEncodingParameters[] |
Based on the camera video width | The layers to send. Your list replaces the default layers. |
This override has the following limits:
- It changes camera video only. It does not change screen share or audio.
- It cannot turn simulcast on. If simulcast is off in the preset, the SDK sends one layer and ignores
simulcastConfig.
To decide whether you need simulcast, refer to Video resolution and simulcast.
To send the camera video as one layer, set disable to true.
Do this when more layers do not help. For example, a 1:1 call has only one viewer. More layers only give more work to the sender's device.
const overrides = {
simulcastConfig: {
disable: true,
},
};To choose your own layers, set encodings to a list. Each item in the list describes one layer. Use the browser RTCRtpEncodingParameters ↗︎ format for each item.
Do this when the default layers are not right for your app. For example, you can set a maximum bitrate for each layer. This limits the upload bandwidth that a participant uses.
The following example sends three layers: full resolution, half resolution, and quarter resolution. Each layer has its own maximum bitrate:
const overrides = {
simulcastConfig: {
encodings: [
{
rid: "f", // Full resolution
scaleResolutionDownBy: 1,
maxBitrate: 2500000, // About 2.5 Mbps
},
{
rid: "h", // Half resolution
scaleResolutionDownBy: 2,
maxBitrate: 900000, // About 0.9 Mbps
},
{
rid: "q", // Quarter resolution
scaleResolutionDownBy: 4,
maxBitrate: 250000, // About 0.25 Mbps
},
],
},
};The SDK ignores your list in the following cases:
- The list is empty.
disableistrue.- Simulcast is turned off in the participant's preset.
If you do not pass a list, the SDK chooses the layers based on the camera video resolution. The following table shows the layers for common resolutions:
| Camera video resolution (width × height) | Layers that the SDK sends |
|---|---|
| 320 × 240 | Full (f) and half (h) resolution |
| 640 × 480 | Full (f) and half (h) resolution |
| 1280 × 720 | Full (f), half (h), and quarter (q) resolution |
| 1920 × 1080 | Full (f), half (h), and quarter (q) resolution |
| 3840 × 2160 | Full (f), half (h), and quarter (q) resolution |
For other resolutions, the SDK looks only at the width. It uses the row with the nearest width.
Use forceRelay to send and receive all the participant's media through a Traversal Using Relays around NAT (TURN) server.
| Type | Default |
|---|---|
boolean |
false |
The participant's browser exchanges media with the Cloudflare media server. The browser can connect to the media server in two ways:
- Direct path: The browser sends media directly to the media server. To create this path, the browser uses Session Traversal Utilities for NAT (STUN) to find its public address.
- Relay path: The browser sends media to a TURN server. The TURN server forwards the media to the media server.
By default, the SDK allows both paths, and the browser chooses the best path that works. If you set forceRelay to true, the browser uses only the relay path.
const overrides = {
forceRelay: true,
};Use forceRelay in the following situations:
- You know that the direct path does not work for your participants. For example, their country, region, or office network blocks STUN or direct media traffic. With
forceRelay, the SDK does not try a direct path that fails. - Your participants use networks where the direct path connects first, but then disconnects again and again.
With a TURN server, the media passes through one more server. Use this override only for the participants who need it.
You do not need this override for connection problems that happen only sometimes. If the connection fails several times in a row, the SDK switches to TURN automatically.
The participant's network must allow TURN traffic. For the list of hosts and ports, refer to Network allowlist.