• Console

›Identity Verification Premium

FaceID service introduction

  • FaceID
  • FaceID-Pro

Identity Verification Basic

  • App-GetBizToken
  • App-Verify
  • App-Authentication
  • H5-Raw-UploadVideo
  • H5-Raw-Verify

Identity Verification Premium

  • APP_Pro-Access-Guide
  • APP_Pro-Authentication
  • APP_Pro-Encrption-Guide
  • APP_Pro-GetBiztoken
  • APP_Pro-Liveness
  • APP_Pro-Verify
  • H5-Lite_Pro-Access-Guide
  • H5-Lite_Pro-GetToken
  • H5-Lite_Pro-Redirect-To-Liveness-URL
  • H5-Lite_Pro-Callbacks
  • H5-Lite_Pro-GetResult
  • H5-Lite_Pro-UsinginAnApp
  • H5-Lite_Pro-UI-Customization
  • H5-Lite_Pro-RTC-Compatibility
  • H5-RAW_Pro-JS-SDK
  • H5-RAW_Pro-GetToken
  • H5-RAW_Pro-GetResult
  • H5-RAW_Pro-CommonProblem

OCR

  • Indonesian_ID_Card
H5-Lite_RAW-JS-SDK

JS-SDK Documentation

Download Link

raw-jssdk-v2.0.3

Description of the file directory structure after download:

├─ demo   // Main directory
 │  ├─html-demo   // Demo using native HTML/JS approach to integrate the SDK
 │  │  ├─index.html // Business code
 │  │  ├─index.js  // Business code
 │  ├─react-demo  // React demo
 │  
 ├─ dist   
    ├─rtcsdk.min.js  // Raw RTC SDK, packaged using the UMD format, compatible with script tags, import/require
    ├─esm
      ├─rtcsdk.js // Packaged using the ESM format, only supports import

I. Integration Methods

Script Tag Reference

rtcsdk.min.js is packaged using UMD

<script type='text/javascript' src="rtcsdk.min.js"></script>

Import or Require Method

esm/rtcsdk.js is packaged using ESM

II. API

Instantiation

Initialization parameters

let rtcVideo = new RctVideo({
    videoWrapper: 'videoWrapper', // Container element for video insertion (requires ID attribute)
    host: 'wss://rtc-sgp.megvii.com', // Service address (wss protocol)
    width: '100%', // Video width (px, rem, em). Video scales proportionally to longest side
    height: 'auto', // Video height (px, rem, em)
    token: 'xxxxxxx', // Token from server-side getToken request (NEVER call from frontend)
    videoPermsTimeout: '6000', // Camera permission timeout (ms, optional)
    webSocketTimeout: '6000', // WebSocket timeout (ms, optional)
    WebRTCTimeout: '6000', // WebRTC connection timeout (ms, optional)
    colorListener: (color, status, index, sum)=>{}, // Color change callback
    tipListener: (tipCode, tipTxt)=>{}, // Tip message callback
    statusListener: (statusCode)=>{}, // Status change callback
    resultCallback: (isSuccess, resultCode, resultMessage)=>{}, // Result callback
    autoplayFailCallback: (play)=>{}, // Callback when auto-play fails
})
rtcVideo.start()

Callback Parameter Descriptions

  • colorListener(color, status, index, sum)
ParameterDescription
colorColor in HEX format (e.g. "#00FFFF")
statusRESET/DONE/COLORING
RESET: Mirror stage failed
DONE: Coloring complete
COLORING: Coloring in progress
indexCurrent coloring progress (e.g. 1)
sumTotal colors (matches Raw-GetToken color_number)
  • tipListener: (tipCode, tipTxt)
ParameterDescription
tipCodeTip code identifier
tipTxtDefault tip text

Tip content may change with service updates. Only handle FaceOK errors.

tipCodetipTxt
NoFaceFoundNo face detected
InvalidFaceYawFace camera directly
InvalidFacePitchFace camera directly
InvalidFaceEyeOcclusionKeep eyes visible
InvalidFaceMouthKeep mouth visible
TooFarAwayFromCameraMove closer to camera
TooCloseFromCameraMove farther from camera
InvalidFaceOutOfImageFace camera directly
InvalidFaceBrightnessAdjust lighting
FaceOKHold still
  • statusListener = (statusCode)
statusCodeDescription
INIT_LOADINGInitial configuration loading
INIT_LOADING_OVERInitial configuration complete
LOOK_MIRRORMirror stage (face adjustment)
SHOW_COLORColoring stage
RESULT_LOADINGProcessing results (loading)
RESULT_LOADING_OVERResults processing complete
DISCONNECTEDWebRTC disconnected (refresh required)
  • resultCallback = (isSuccess, resultCode, resultMessage)
isSuccessDescription
trueProcess completed normally
falseError occurred during process
resultCoderesultMessageDescription
1000SUCCESSProcess completed normally
2000DISCONNECTEDWebRTC disconnected
3000TIMEOUT30s timeout from connection establishment
4000SUPPORT_ERRORDevice not supported (WebRTC unavailable)
4000PERMISSIONS_ERRORCamera permission denied/timeout
4000NETWORK_ERRORNo data transmission within 6s of connection
5000TOKEN_EXPIREDToken expired/invalid/used
5000TOKEN_TIMES_EXCEEDEDToken usage limit exceeded
5000ILLEGAL_PARAMETER:{params}Invalid initialization parameters
  • autoplayFailCallback = (play) play is the playback method.

start()

Starts verification (activates camera). Inserts video element into videoWrapper container.

rtcVideo.start()

destroy()

Manually terminates process (closes WebRTC). Remove video element manually.

rtcVideo.destroy()

version()

Gets SDK version

rtcVideo.version()

III. Workflow

Main flow follows statusListener changes:

  1. LOOK_MIRROR Stage: Detects face position/lighting. Triggers tipListener for user adjustments
  2. SHOW_COLOR Stage: Triggers colorListener for background color changes. Maximize screen coverage
  3. RESULT_LOADING: Processes results. Upon completion triggers resultCallback
  4. DISCONNECTED: Network issues - requires page refresh

IV. Common Issues & Solutions

  1. Requires HTTPS
  2. WebView Adaptation:
    • Android: https://blog.csdn.net/weixin_37939704/article/details/88554967
    • iOS: https://www.jianshu.com/p/e4452707e33a

Directory Structure

├─ demo
 │ ├─html-demo       // HTML/JS implementation
 │ │ ├─index.html
 │ │ ├─index.js
 │ ├─react-demo      // React implementation
 
├─ dist
   ├─rtcsdk.min.js    // SDK (supports both script tags and modules)

V. Changelog

v2.0.3 August 22, 2025

  • Added host configuration (no default)
  • Added regional service support

v2.0.2 October 11, 2024

  • Updated WebSocket ICE message structure

v2.0.1 May 6, 2024

  • Added ESM module format

v2.0.0 December 7, 2021

  • Fixed class name (RctVideo → RtcVideo)
  • Merged callbacks into resultCallback
  • Added statusListener updates
  • Added autoplayFailCallback
  • Added version() method

v1.1.2 August 3, 2021

  • Fixed destroy() exception on legacy devices

v1.1.1 June 25, 2021

  • Fixed tipCode parameter error

v1.1.0 June 10, 2021

  • Added destroy() method
  • Improved network handling
  • Fixed INIT_LOADING_OVER trigger logic

© 2012-2021 北京旷视科技有限公司 版权所有 | 京ICP备12036813号-6

京公网安备 11010802025957号