import { Image, NativeModules, Platform } from 'react-native'; const resolveAssetSourceFunc = Image.resolveAssetSource; // excluding array of images and only allow one image type ImageSourceType = Exclude< Parameters[0], Array >; const LINKING_ERROR = `The package '@stream-io/video-filters-react-native' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; const VideoFiltersReactNative = NativeModules.VideoFiltersReactNative ? NativeModules.VideoFiltersReactNative : new Proxy( {}, { get() { throw new Error(LINKING_ERROR); }, }, ); /** * Registers the background blur video filters. * The name of the background filters are 'BackgroundBlurLight', 'BackgroundBlurMedium' and 'BackgroundBlurHeavy'. */ export async function registerBackgroundBlurVideoFilters(): Promise { return await VideoFiltersReactNative.registerBackgroundBlurVideoFilters(); } /** * Registers a virtual background filter with the given image. * Note: it uses Image.resolveAssetSource to resolve the URI of the given image source. * * @param imageSource Source of the image to use as the background. It can be either remote or local image * @returns the URI of the image that was registered as the virtual background */ export async function registerVirtualBackgroundFilter( imageSource: ImageSourceType, ): Promise { const source = resolveAssetSourceFunc(imageSource); const imageUri = source.uri; await VideoFiltersReactNative.registerVirtualBackgroundFilter(imageUri); return imageUri; } /** * Registers the blur video filters. * The name of the blur filters are 'BlurLight', 'BlurMedium' and 'BlurHeavy'. */ export async function registerBlurVideoFilters(): Promise { return await VideoFiltersReactNative.registerBlurVideoFilters(); } /** * Unregisters all filters that were previously registered via this module, * allowing the native processor instances to be released. Safe to call even * if no filters were registered. */ export async function unregisterAllFilters(): Promise { return await VideoFiltersReactNative.unregisterAllFilters(); }