Skip to main content
Quick Reference for AI Agents & Developers
// Configure virtual background
const virtualBackground = new CometChatCalls.VirtualBackground();
virtualBackground.allowBackgroundBlur(true);
virtualBackground.allowUserImages(true);
virtualBackground.setImages(["https://example.com/bg1.jpg"]);
virtualBackground.enforceBackgroundBlur(50);  // Start with blur (1-99)

// Apply to call settings
const callSettings = new CometChatCalls.CallSettingsBuilder()
  .showVirtualBackgroundSetting(true)
  .setVirtualBackground(virtualBackground)
  .build();

// Programmatic control during call
const controller = CometChatCalls.CallController.getInstance();
controller.setBackgroundBlur(50);
controller.setBackgroundImage("https://example.com/bg.jpg");
Available via: SDK | UI Kits
Enhance video calls with virtual backgrounds, allowing users to blur their surroundings or display custom images behind them.

Prerequisites

Before implementing virtual backgrounds, ensure you have:
  1. Completed the Calls SDK Setup
  2. Implemented either Ringing or Call Session calling

Quick Start

Enable virtual background settings in your call configuration:
const callSettings = new CometChatCalls.CallSettingsBuilder()
  .enableDefaultLayout(true)
  .showVirtualBackgroundSetting(true)  // Show VB button in UI
  .setCallListener(callListener)
  .build();

Call Settings Options

MethodDescriptionDefault
showVirtualBackgroundSetting(boolean)Show/hide virtual background button in menutrue
setVirtualBackground(VirtualBackground)Configure virtual background options-

Virtual Background Configuration

Use the VirtualBackground class to customize available options:
const virtualBackground = new CometChatCalls.VirtualBackground();

// Allow background blur
virtualBackground.allowBackgroundBlur(true);

// Allow users to upload custom images
virtualBackground.allowUserImages(true);

// Show default background images
virtualBackground.showDefaultImages(true);

// Add custom background images
virtualBackground.setImages([
  "https://example.com/bg1.jpg",
  "https://example.com/bg2.jpg",
  "https://example.com/bg3.jpg"
]);

// Apply to call settings
const callSettings = new CometChatCalls.CallSettingsBuilder()
  .enableDefaultLayout(true)
  .setVirtualBackground(virtualBackground)
  .setCallListener(callListener)
  .build();

Configuration Options

MethodDescriptionDefault
allowBackgroundBlur(boolean)Allow users to blur their backgroundtrue
allowUserImages(boolean)Allow users to upload custom imagestrue
showDefaultImages(boolean)Show CometChat’s default background imagestrue
setImages(string[])Add custom background images (URLs)[]
enforceBackgroundBlur(number)Start call with blur enabled (1-99 intensity)0 (disabled)
enforceBackgroundImage(string)Start call with specific background image-

Enforce Settings

Force specific virtual background settings when the call starts:
const virtualBackground = new CometChatCalls.VirtualBackground();

// Start call with medium blur (1-99)
virtualBackground.enforceBackgroundBlur(50);

const callSettings = new CometChatCalls.CallSettingsBuilder()
  .enableDefaultLayout(true)
  .setVirtualBackground(virtualBackground)
  .build();

Programmatic Control

For custom UI implementations, control virtual backgrounds programmatically:

Open Settings Dialog

const callController = CometChatCalls.CallController.getInstance();
callController.openVirtualBackground();

Set Background Blur

Apply blur with intensity from 1 (light) to 99 (heavy):
const callController = CometChatCalls.CallController.getInstance();

// Light blur
callController.setBackgroundBlur(20);

// Medium blur
callController.setBackgroundBlur(50);

// Heavy blur
callController.setBackgroundBlur(80);

Set Background Image

Apply a custom background image:
const callController = CometChatCalls.CallController.getInstance();
callController.setBackgroundImage("https://example.com/background.jpg");

Complete Example

// Configure virtual background options
const virtualBackground = new CometChatCalls.VirtualBackground();
virtualBackground.allowBackgroundBlur(true);
virtualBackground.allowUserImages(true);
virtualBackground.showDefaultImages(true);
virtualBackground.setImages([
  "https://example.com/office.jpg",
  "https://example.com/nature.jpg",
  "https://example.com/abstract.jpg"
]);

// Optional: Start with blur enabled
virtualBackground.enforceBackgroundBlur(30);

// Build call settings
const callSettings = new CometChatCalls.CallSettingsBuilder()
  .enableDefaultLayout(true)
  .showVirtualBackgroundSetting(true)
  .setVirtualBackground(virtualBackground)
  .setCallListener(callListener)
  .build();

// Start the call
const htmlElement = document.getElementById("call-container");
CometChatCalls.startSession(callToken, callSettings, htmlElement);

Next Steps