MediaSFU ReactJS
    Preparing search index...

    Variable BackgroundModalConst

    BackgroundModal: React.FC<BackgroundModalOptions> = ...

    BackgroundModal - Advanced virtual background and blur management interface

    A sophisticated modal for configuring virtual backgrounds using MediaPipe Selfie Segmentation. Supports image uploads, preset backgrounds, real-time preview, blur effects, and seamless video transport integration. Perfect for professional meetings, virtual events, and privacy enhancement during video calls.

    Features:

    • Virtual background image selection from presets
    • Custom background image upload
    • Real-time background segmentation (MediaPipe)
    • Video preview before applying
    • Background blur effects
    • Seamless video stream replacement
    • Canvas-based image processing
    • Recording-compatible backgrounds
    • Automatic video transport handling
    • Memory-efficient stream management
    • Extensive HTML attributes customization
    • Custom render hooks for UI flexibility

    Configuration options

    Modal visibility state

    Callback when modal is closed

    Background processing parameters

    Custom uploaded image URL

    Currently selected background

    Video stream for segmentation

    MediaPipe instance

    Segmentation pause state

    Processed output stream

    Persist background state

    Background change flag

    Virtual background stream

    Canvas for processing

    Previous keep state

    Applied state flag

    Video active state

    Audio-only mode flag

    User permission level

    Recording active

    Recording resumed

    Recording paused

    Recording stopped

    Recording config

    Browser MediaDevices API

    Alert display function

    Local video stream

    Video constraints

    Target frame rate

    Target resolution

    Update custom image

    Update selection

    Update segment stream

    Update segmentation

    Update pause state

    Update processed stream

    Update persistence

    Update change flag

    Update virtual stream

    Update prev state

    Update applied flag

    MediaSoup video producer

    Transport creation state

    Video producer params

    Update producer params

    Auto-apply on select

    Update auto-apply

    Create transport handler

    Connect video handler

    Disconnect handler

    Screen change handler

    Async delay utility

    Retrieve latest params

    Modal screen position

    Modal background color

    Modal title

    HTML attributes for overlay

    HTML attributes for content container

    HTML attributes for header

    HTML attributes for title

    HTML attributes for close button

    Custom close icon

    HTML attributes for divider

    HTML attributes for body

    HTML attributes for image grid

    HTML attributes for upload wrapper

    HTML attributes for upload label

    Custom upload label

    HTML attributes for file input

    HTML attributes for main canvas

    HTML attributes for bg canvas

    HTML attributes for capture video

    HTML attributes for preview video

    HTML attributes for loading overlay

    Custom loading spinner

    HTML attributes for buttons wrapper

    HTML attributes for apply button

    HTML attributes for save button

    Custom apply button text

    Custom applied button text

    Custom save button text

    Custom header renderer

    Custom buttons renderer

    Custom body renderer

    Custom content renderer

    Rendered background modal or null if not visible

    // Basic virtual background selector

    import React, { useState } from 'react';
    import { BackgroundModal } from 'mediasfu-reactjs';

    function BackgroundControl({ parameters }) {
    const [isVisible, setIsVisible] = useState(false);

    return (
    <>
    <button onClick={() => setIsVisible(true)}>
    Virtual Background {parameters.appliedBackground ? '✓' : ''}
    </button>
    <BackgroundModal
    isVisible={isVisible}
    onClose={() => setIsVisible(false)}
    parameters={parameters}
    position="topRight"
    backgroundColor="#0f172a"
    />
    </>
    );
    }

    // Custom styled with preview status

    import { BackgroundModal } from 'mediasfu-reactjs';

    function BrandedBackground({ isVisible, onClose, parameters }) {
    return (
    <BackgroundModal
    isVisible={isVisible}
    onClose={onClose}
    parameters={parameters}
    backgroundColor="#1e3a8a"
    position="topLeft"
    contentProps={{
    style: {
    maxHeight: '90vh',
    borderRadius: 20,
    border: '2px solid #3b82f6',
    },
    }}
    applyButtonProps={{
    style: {
    background: 'linear-gradient(135deg, #3b82f6 0%, #1e40af 100%)',
    color: 'white',
    padding: '12px 28px',
    borderRadius: 12,
    fontWeight: 600,
    },
    }}
    saveButtonProps={{
    style: {
    background: 'linear-gradient(135deg, #22c55e 0%, #14532d 100%)',
    color: 'white',
    padding: '12px 28px',
    borderRadius: 12,
    fontWeight: 600,
    },
    }}
    title={
    <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
    <span>Virtual Background</span>
    {parameters.appliedBackground && (
    <span style={{ fontSize: 14, color: '#22c55e' }}>● Active</span>
    )}
    </div>
    }
    />
    );
    }

    // Analytics tracking for background changes

    import { BackgroundModal } from 'mediasfu-reactjs';

    function AnalyticsBackground({ isVisible, onClose, parameters }) {
    return (
    <BackgroundModal
    isVisible={isVisible}
    onClose={onClose}
    parameters={{
    ...parameters,
    updateAppliedBackground: (applied) => {
    if (applied) {
    analytics.track('virtual_background_applied', {
    backgroundType: parameters.selectedImage === 'none' ? 'none' :
    parameters.selectedImage === 'blur' ? 'blur' : 'image',
    customImage: !!parameters.customImage,
    });
    }
    parameters.updateAppliedBackground(applied);
    },
    }}
    renderBody={({ defaultBody }) => {
    return (
    <div>
    <div style={{
    padding: 12,
    background: '#f8fafc',
    borderRadius: 8,
    marginBottom: 16,
    }}>
    <div style={{ fontWeight: 600, marginBottom: 4 }}>
    Background Status
    </div>
    <div style={{ fontSize: 14 }}>
    {parameters.appliedBackground
    ? `Active: ${parameters.selectedImage}`
    : 'No background applied'}
    </div>
    </div>
    {defaultBody}
    </div>
    );
    }}
    />
    );
    }

    // Override with MediasfuGeneric uiOverrides

    import { MediasfuGeneric, BackgroundModal } from 'mediasfu-reactjs';

    const uiOverrides = {
    backgroundModal: {
    component: (props) => (
    <BackgroundModal
    {...props}
    backgroundColor="#0f172a"
    position="topRight"
    applyButtonProps={{
    style: {
    background: '#3b82f6',
    borderRadius: 12,
    padding: '12px 28px',
    fontWeight: 600,
    },
    }}
    saveButtonProps={{
    style: {
    background: '#22c55e',
    borderRadius: 12,
    padding: '12px 28px',
    fontWeight: 600,
    },
    }}
    />
    ),
    },
    };

    <MediasfuGeneric uiOverrides={uiOverrides} />;