mediasfu-reactjs
Version:
MediaSFU Prebuilt ReactJS SDK - Compatible with React 18 & 19, TypeScript & JavaScript
47 lines • 1.87 kB
TypeScript
/**
* SelfieSegmentationService - Singleton service for managing the MediaPipe SelfieSegmentation model
*
* This service ensures only ONE instance of the WASM-based SelfieSegmentation model exists
* across the entire application, preventing "Module.arguments has been replaced" and
* "memory access out of bounds" errors that occur when multiple instances are created.
*/
import { SelfieSegmentation } from "@mediapipe/selfie_segmentation";
declare class SelfieSegmentationService {
private static instance;
private model;
private isInitializing;
private initPromise;
private isDestroyed;
private constructor();
static getInstance(): SelfieSegmentationService;
/**
* Get or initialize the SelfieSegmentation model.
* Returns the existing model if already initialized, or initializes a new one.
* Thread-safe - multiple calls during initialization will wait for the same promise.
*/
getModel(): Promise<SelfieSegmentation | null>;
private initializeModel;
/**
* Check if the model is currently available (initialized and not destroyed)
*/
isModelAvailable(): boolean;
/**
* Get the model reference directly (may be null)
* Use this for synchronous checks, but prefer getModel() for actual usage
*/
getModelSync(): SelfieSegmentation | null;
/**
* Destroy the model and release resources.
* Should only be called when the entire app is shutting down,
* NOT when individual components unmount.
*/
destroy(): void;
/**
* Reset the service state without destroying the model.
* Use this to clear any pending state after errors.
*/
reset(): void;
}
export declare const selfieSegmentationService: SelfieSegmentationService;
export type { SelfieSegmentation };
//# sourceMappingURL=SelfieSegmentationService.d.ts.map