HMSSDK now provides support for Virtual Background using @100mslive/react-native-video-plugin. It allows users to change their background during a call. Users can choose from a variety of backgrounds or upload their own custom background. It also provides
npm install @100mslive/react-native-video-plugin










Integrate virtual backgrounds, blur backgrounds effects in your React Native app with the 100ms Video Plugin. 100ms video plugin enabled adding virtual backgrounds, blur backgrounds, and other video filters to your 100ms video conferencing app. The plugin is built on top of the 100ms React Native SDK.
š Read the Complete Documentation here: https://www.100ms.live/docs/react-native/v2/quickstart/quickstart
š² Download the Example iOS app here: https://testflight.apple.com/join/v4bSIPad
š¤ Download the Example Android app here: https://appdistribution.firebase.dev/i/7b7ab3b30e627c35
Virtual Background plugin helps in customising one's background that replacing the background with a static image or blurring the background.
This guide provides an overview of usage of the Virtual Background plugin of 100ms.
| Package | Version |
| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| @100mslive/react-native-room-kit |  |
| @100mslive/react-native-hms |  |
| @100mslive/react-native-video-plugin |  |
- Minimum @100mslive/react-native-hms SDK version is ^1.10.6
iOS 15Install @100mslive/react-native-video-plugin library
``bash`
npm install @100mslive/react-native-video-plugin
`js@100mslive/react-native-video-plugin
// Import from library
import { HMSVirtualBackgroundPlugin } from '@100mslive/react-native-video-plugin';
...
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
`
`js
let videoSettings = new HMSVideoTrackSettings({
initialState: HMSTrackSettingsInitState.MUTED
// The virtual background plugin to use for the video track. @type {HMSVirtualBackgroundPlugin}
videoPlugin: virtualBackgroundPlugin,
});
let trackSettings = new HMSTrackSettings({
video: videoSettings,
});
`
`js`
const hmsInstance = await HMSSDK.build({
trackSettings,
});
Hold on to a reference to the instance of HMSVirtualBackgroundPlugin and use enable and disable methods on it to enable/disable the virtual background.
`js
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
...
let isVBEnabled = false;
// Enable VB
await virtualBackgroundPlugin.enable();
isVBEnabled = true;
// Disable VB
await virtualBackgroundPlugin.disable();
isVBEnabled = false;
`
> Always call enable method after ON_JOIN and ON_PREVIEW event
> Enabling Virtual Background and applying effect can take some time, you should add a loader in UI.
Enable the blur background using the setBlur method. You should pass blur percentage ranging from 0-100
`js
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
...
// state for tracking if VB is enabled
let isVBEnabled = false;
// If VB is disabled, first enable it before calling setBlur method
if (isVBEnabled === false) {
await virtualBackgroundPlugin.enable();
isVBEnabled = true;
}
await virtualBackgroundPlugin.setBlur(100);
`
> You should only call setBlur method only after enabling the virtual background
Enable the background image using the setBackground method. It accepts image source (either a object with height, width and uri properties or a static image file).
Here is how to use a static image file -
`js
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
...
// state for tracking if VB is enabled
let isVBEnabled = false;
// If VB is disabled, first enable it before calling setBlur method
if (isVBEnabled === false) {
await virtualBackgroundPlugin.enable();
isVBEnabled = true;
}
const image = require('
await virtualBackgroundPlugin.setBackground(image);
`
Here is how to use remote image file, setBackground method accepts object of following type -
`js
export interface ImageURISource {
width: number;
height: number;
/**
* uri is a string representing the resource identifier for the image, whichrequire('./path/to/image.png')
* could be an http address, a local file path, or the name of a static image
* resource (which should be wrapped in the
* function).
*/
uri:
}
...
await virtualBackgroundPlugin.setBackground({
width,
height,
uri: 'file://...', // path of image stored in device
});
`
Using library like react-native-image-picker -
`js
import { launchImageLibrary } from 'react-native-image-picker';
...
// You can use result from library like react-native-image-picker to use images from photo library
const result = await launchImageLibrary({ mediaType: 'photo', selectionLimit: 1 });
// getting first image
const imageObject = response.assets?.[0];
// If image is selected, use it as background
if (imageObject) {
await virtualBackgroundPlugin.setBackground(imageObject);
}
`
> You should only call setBackground` method only after enabling the virtual background