@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 Requirements
Limitations
Android
- Has poor FPS on older Android phones
iOS
- Minimum iOS version required to support Virtual Background plugin is
iOS 15
- Virtual background plugin is in beta stage and may have performance issues on iPhone X, 8, 7, 6 and other older devices. We recommend that you use this feature on a high performance device for smooth experience.
Usage
Step 1: Add required dependency
Install @100mslive/react-native-video-plugin
library
npm install @100mslive/react-native-video-plugin
Step 2: Create instance of HMSVirtualBackgroundPlugin
import { HMSVirtualBackgroundPlugin } from '@100mslive/react-native-video-plugin';
...
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
Step 3: Create instance of HMSVideoTrackSettings
let videoSettings = new HMSVideoTrackSettings({
initialState: HMSTrackSettingsInitState.MUTED
videoPlugin: virtualBackgroundPlugin,
});
let trackSettings = new HMSTrackSettings({
video: videoSettings,
});
Step 4: Pass the Track Settings to the HMSSDK
const hmsInstance = await HMSSDK.build({
trackSettings,
});
Step 5: How to enable and disable virtual background
Hold on to a reference to the instance of HMSVirtualBackgroundPlugin and use enable
and disable
methods on it to enable/disable the virtual background.
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
...
let isVBEnabled = false;
await virtualBackgroundPlugin.enable();
isVBEnabled = true;
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.
Step 6: How to apply Blur as virtual background
Enable the blur background using the setBlur
method. You should pass blur percentage ranging from 0-100
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
...
let isVBEnabled = false;
if (isVBEnabled === false) {
await virtualBackgroundPlugin.enable();
isVBEnabled = true;
}
await virtualBackgroundPlugin.setBlur(100);
You should only call setBlur
method only after enabling the virtual background
Step 7: How to apply Image as 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 -
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
...
let isVBEnabled = false;
if (isVBEnabled === false) {
await virtualBackgroundPlugin.enable();
isVBEnabled = true;
}
const image = require('<PATH_TO_IMAGE_HERE>');
await virtualBackgroundPlugin.setBackground(image);
Here is how to use remote image file, setBackground
method accepts object of following type -
export interface ImageURISource {
width: number;
height: number;
uri:
}
...
await virtualBackgroundPlugin.setBackground({
width,
height,
uri: 'file://...',
});
Using library like react-native-image-picker -
import { launchImageLibrary } from 'react-native-image-picker';
...
const result = await launchImageLibrary({ mediaType: 'photo', selectionLimit: 1 });
const imageObject = response.assets?.[0];
if (imageObject) {
await virtualBackgroundPlugin.setBackground(imageObject);
}
You should only call setBackground
method only after enabling the virtual background