Skip to content
azraellong edited this page Sep 27, 2024 · 2 revisions

zego-effects-reactnativeDocs


zego-effects-reactnative

Zego Effects SDK for React Native.

Getting started

$ yarn add zego-effects-reactnative

Usage

Download and Import Resources into the Project

Download the latest version of the Effects SDK from the SDK download site (iOS download link: https://doc-zh.zego.im/article/15898, Android download link: https://doc-zh.zego.im/article/15899). After extracting it, import the Resources and Models folders into your project.

Note: You only need to add the resources and models to your project; zego-effects-reactnative will automatically download the SDK itself.

  • iOS: Add the Resources and Models folders to your Xcode project and choose the Create folders option in the Group settings. Assuming your project name is example and you place all resources in the Assets folder, your project directory structure should look like this after importing:
# ios
├── example
│   ├── AppDelegate.h
│   ├── AppDelegate.mm
│   ├── Images.xcassets
├── Assets
│   ├── Models
│   │   ├── FaceDetectionModel.model
│   │   └── SegmentationModel.model
│   └── Resources
│       ├── ColorfulStyleResources
│       ├── CommonResources.bundle
│       ├── FaceWhiteningResources.bundle
│       ├── MakeupResources
│       ├── PendantResources.bundle
│       ├── RosyResources.bundle
│       └── TeethWhiteningResources.bundle
│
  • Android: Add the Resources and Models folders to the assets directory in your Android project. Typically, the resources should be placed in the android/app/src/main/assets directory, so your project directory structure should look like this after importing:
# android/app/src/main
├── AndroidManifest.xml
├── assets
│   ├── Models
│   │   ├── FaceDetectionModel.model
│   │   └── SegmentationModel.model
│   └── Resources
│       ├── ColorfulStyleResources
│       ├── CommonResources.bundle
│       ├── FaceWhiteningResources.bundle
│       ├── MakeupResources
│       ├── PendantResources.bundle
│       ├── RosyResources.bundle
│       └── TeethWhiteningResources.bundle
├── java
└── res

Code Invocation

import ZegoEffects from 'zego-effects-reactnative';

/**
 * Initializes the beauty effects SDK.
 * This method should be called after the Express instance is created.
 */
async function initEffects() {
  // Enable custom video processing for Express and Effects
  // engine is an instance of ExpressEngine
  await engine.enableCustomVideoProcessing(true, {}, ZegoPublishChannel.Main);

  // Log the version of the Effects SDK
  console.log(`Effects version=${await ZegoEffects.getVersion()}`);

  // Retrieve authentication information from the SDK
  const authInfo: string = await ZegoEffects.getAuthInfo(appSign);

  // Fetch the license from the Zego server, see: https://doc-zh.zego.im/article/12199
  const license: string = await getLicenseFromZegoServer(appID, authInfo);

  // Create an Effects instance with the fetched license
  const effects = new ZegoEffects(license);

  // Listen for error events and handle them
  effects.on('error', (errorCode: number, desc: string) => {
    // Log the error message for debugging purposes
    console.error(`Error code: ${errorCode}, Description: ${desc}`);
  });

  // Enable custom handler for Express and image processing for Effects
  effects.enableImageProcessing(true);

  // Enable and configure the smoothing effect for better beautification
  effects.enableSmooth(true);
  effects.setSmoothParam({ intensity: 100 });

  // Enable the face-lifting effect to create a smaller face appearance
  effects.enableFaceLifting(true);
  effects.setFaceLiftingParam({ intensity: 100 });

  // Additional steps can be added here for other effects or configurations
  // For example:
  // effects.enableWhitening(true);
  // effects.setWhiteningParam({ intensity: 50 });

  // Ensure that all effects are properly enabled and configured
  console.log('Beauty effects initialized successfully.');
}
Clone this wiki locally