Documentation
ExpressAudioSDK Voice Call
Documentation
Demo APP
SDK Center
API Center
FAQ
Code Market
Console
Sign Up
Log In
中文站 English
  • Documentation
  • Voice Call
  • Develop your app
  • Setting callback

Setting callback

Last updated:2024-12-23 18:22

This document is only for explaining the callback setting method and parameter usage on the Electron platform. For detailed function introduction and parameter description, please refer to the specific API documentation.

Module Description

The callbacks of the Express Electron SDK are managed across multiple modules. The modules and how to obtain their instances are as follows:

  1. ZegoExpressEngine

    Create SDK instance zegoEngine

    // Create SDK instance 
    const zgEngine = window.require('zego-express-engine-electron/ZegoExpressEngine');
  2. ZegoExpressMediaPlayer

    createMediaPlayer --- Create media player instance zgMediaPlayer

    // Create media player instance
    const zgMediaPlayer = zgEngine.createMediaPlayer();
  3. ZegoExpressAudioEffectPlayer

    createAudioEffectPlayer --- Create audio effect player instance zgAudioEffectPlayer

    // Create audio effect player instance
    const zgAudioEffectPlayer = zgEngine.createAudioEffectPlayer();
  4. ZegoExpressScreenCaptureSource

    createScreenCaptureSource --- Create screen capture source instance zgScreenCaptureSource

    // Create screen capture source instance
    // sourceId  {number} The specified screen ID or window ID
    // sourceType  {ZegoScreenCaptureSourceType} The specified screen source type.
    const zgScreenCaptureSource = zgEngine.createScreenCaptureSource(sourceId, sourceType);

Register Callback

ZegoExpressEngine

onDebugError

Example:

zgEngine.on("onDebugError",(errorCode,funcName,info)=>{
  console.log(`onDebugError: ${errorCode},${funcName},${info}`)
})

onEngineStateUpdate

Example:

zgEngine.on("onEngineStateUpdate",(state)=>{
  console.log(`onEngineStateUpdate: ${state}`)
})

onRecvExperimentalAPI

Example:

zgEngine.on("onRecvExperimentalAPI",(content)=>{
  console.log(`onRecvExperimentalAPI: ${content}`)
})

onRoomStateUpdate

Example:

zgEngine.on("onRoomStateUpdate",(roomID,state,errorCode,extendedData)=>{
  console.log(`onRoomStateUpdate: ${roomID},${state},${errorCode},${extendedData}`)
})

onRoomStateChanged

Example:

zgEngine.on("onRoomStateChanged",(roomID,reason,errorCode,extendedData)=>{
  console.log(`onRoomStateChanged: ${roomID},${reason},${errorCode},${extendedData}`)
})

onRoomUserUpdate

Example:

zgEngine.on("onRoomUserUpdate",(roomID,updateType,userList)=>{
  console.log(`onRoomUserUpdate: ${roomID},${updateType},${userList}`)
})

onRoomOnlineUserCountUpdate

Example:

zgEngine.on("onRoomOnlineUserCountUpdate",(roomID,count)=>{
  console.log(`onRoomOnlineUserCountUpdate: ${roomID},${count}`)
})

onRoomStreamUpdate

Example:

zgEngine.on("onRoomStreamUpdate",(roomID,updateType,streamList,extendedData)=>{
  console.log(`onRoomStreamUpdate: ${roomID},${updateType},${streamList},${extendedData}`)
})

onRoomStreamExtraInfoUpdate

Example:

zgEngine.on("onRoomStreamExtraInfoUpdate",(roomID,streamList)=>{
  console.log(`onRoomStreamExtraInfoUpdate: ${roomID},${streamList}`)
})

onRoomExtraInfoUpdate

Example:

zgEngine.on("onRoomExtraInfoUpdate",(roomID,roomExtraInfoList)=>{
  console.log(`onRoomExtraInfoUpdate: ${roomID},${roomExtraInfoList}`)
})

onRoomTokenWillExpire

Example:

zgEngine.on("onRoomTokenWillExpire",(roomID,remainTimeInSecond)=>{
  console.log(`onRoomTokenWillExpire: ${roomID},${remainTimeInSecond}`)
})

onPublisherStateUpdate

Example:

zgEngine.on("onPublisherStateUpdate",(streamID,state,errorCode,extendedData)=>{
  console.log(`onPublisherStateUpdate: ${streamID},${state},${errorCode},${extendedData}`)
})

onPublisherQualityUpdate

Example:

zgEngine.on("onPublisherQualityUpdate",(streamID,quality)=>{
  console.log(`onPublisherQualityUpdate: ${streamID},${quality}`)
})

onPublisherCapturedAudioFirstFrame

Example:

zgEngine.on("onPublisherCapturedAudioFirstFrame",()=>{
  console.log(`onPublisherCapturedAudioFirstFrame: `)
})

onPublisherCapturedVideoFirstFrame

Example:

zgEngine.on("onPublisherCapturedVideoFirstFrame",(channel)=>{
  console.log(`onPublisherCapturedVideoFirstFrame: ${channel}`)
})

onPublisherSendAudioFirstFrame

Example:

zgEngine.on("onPublisherSendAudioFirstFrame",(channel)=>{
  console.log(`onPublisherSendAudioFirstFrame: ${channel}`)
})

onPublisherSendVideoFirstFrame

Example:

zgEngine.on("onPublisherSendVideoFirstFrame",(channel)=>{
  console.log(`onPublisherSendVideoFirstFrame: ${channel}`)
})

onPublisherVideoSizeChanged

Example:

zgEngine.on("onPublisherVideoSizeChanged",(width,height,channel)=>{
  console.log(`onPublisherVideoSizeChanged: ${width},${height},${channel}`)
})

onPublisherRelayCDNStateUpdate

Example:

zgEngine.on("onPublisherRelayCDNStateUpdate",(streamID,infoList)=>{
  console.log(`onPublisherRelayCDNStateUpdate: ${streamID},${infoList}`)
})

onVideoObjectSegmentationStateChanged

Example:

zgEngine.on("onVideoObjectSegmentationStateChanged",(state,channel,errorCode)=>{
  console.log(`onVideoObjectSegmentationStateChanged: ${state},${channel},${errorCode}`)
})

onPlayerStateUpdate

Example:

zgEngine.on("onPlayerStateUpdate",(streamID,state,errorCode,extendedData)=>{
  console.log(`onPlayerStateUpdate: ${streamID},${state},${errorCode},${extendedData}`)
})

onPlayerQualityUpdate

Example:

zgEngine.on("onPlayerQualityUpdate",(streamID,quality)=>{
  console.log(`onPlayerQualityUpdate: ${streamID},${quality}`)
})

onPlayerMediaEvent

Example:

zgEngine.on("onPlayerMediaEvent",(streamID,event)=>{
  console.log(`onPlayerMediaEvent: ${streamID},${event}`)
})

onPlayerRecvAudioFirstFrame

Example:

zgEngine.on("onPlayerRecvAudioFirstFrame",(streamID)=>{
  console.log(`onPlayerRecvAudioFirstFrame: ${streamID}`)
})

onPlayerRecvVideoFirstFrame

Example:

zgEngine.on("onPlayerRecvVideoFirstFrame",(streamID)=>{
  console.log(`onPlayerRecvVideoFirstFrame: ${streamID}`)
})

onPlayerRenderVideoFirstFrame

Example:

zgEngine.on("onPlayerRenderVideoFirstFrame",(streamID)=>{
  console.log(`onPlayerRenderVideoFirstFrame: ${streamID}`)
})

onPlayerVideoSizeChanged

Example:

zgEngine.on("onPlayerVideoSizeChanged",(streamID,width,height)=>{
  console.log(`onPlayerVideoSizeChanged: ${streamID},${width},${height}`)
})

onPlayerRecvSEI

Example:

zgEngine.on("onPlayerRecvSEI",(streamID,data)=>{
  console.log(`onPlayerRecvSEI: ${streamID},${data}`)
})

onPlayerSyncRecvSEI

Example:

zgEngine.on("onPlayerSyncRecvSEI",(streamID,data)=>{
  console.log(`onPlayerSyncRecvSEI: ${streamID},${data}`)
})

onAudioDeviceStateChanged

Example:

zgEngine.on("onAudioDeviceStateChanged",(updateType,deviceType,deviceInfo)=>{
  console.log(`onAudioDeviceStateChanged: ${updateType},${deviceType},${deviceInfo}`)
})

onAudioDeviceVolumeChanged

Example:

zgEngine.on("onAudioDeviceVolumeChanged",(deviceType,deviceID,volume)=>{
  console.log(`onAudioDeviceVolumeChanged: ${deviceType},${deviceID},${volume}`)
})

onVideoDeviceStateChanged

Example:

zgEngine.on("onVideoDeviceStateChanged",(updateType,deviceInfo)=>{
  console.log(`onVideoDeviceStateChanged: ${updateType},${deviceInfo}`)
})

onCapturedSoundLevelUpdate

Example:

zgEngine.on("onCapturedSoundLevelUpdate",(soundLevel)=>{
  console.log(`onCapturedSoundLevelUpdate: ${soundLevel}`)
})

onCapturedSoundLevelInfoUpdate

Example:

zgEngine.on("onCapturedSoundLevelInfoUpdate",(soundLevelInfo)=>{
  console.log(`onCapturedSoundLevelInfoUpdate: ${soundLevelInfo}`)
})

onRemoteSoundLevelUpdate

Example:

zgEngine.on("onRemoteSoundLevelUpdate",(soundLevels)=>{
  console.log(`onRemoteSoundLevelUpdate: ${soundLevels}`)
})

onLocalCaptureVideoData

Example:

zgEngine.on("onLocalCaptureVideoData",(videoParam)=>{
  console.log(`onLocalCaptureVideoData: ${videoParam}`)
})

onRemotePlayVideoData

Example:

zgEngine.on("onRemotePlayVideoData",(videoParam)=>{
  console.log(`onRemotePlayVideoData: ${videoParam}`)
})

onRemoteSoundLevelInfoUpdate

Example:

zgEngine.on("onRemoteSoundLevelInfoUpdate",(soundLevelInfos)=>{
  console.log(`onRemoteSoundLevelInfoUpdate: ${soundLevelInfos}`)
})

onCapturedAudioSpectrumUpdate

Example:

zgEngine.on("onCapturedAudioSpectrumUpdate",(audioSpectrum)=>{
  console.log(`onCapturedAudioSpectrumUpdate: ${audioSpectrum}`)
})

onRemoteAudioSpectrumUpdate

Example:

zgEngine.on("onRemoteAudioSpectrumUpdate",(audioSpectrums)=>{
  console.log(`onRemoteAudioSpectrumUpdate: ${audioSpectrums}`)
})

onLocalDeviceExceptionOccurred

Example:

zgEngine.on("onLocalDeviceExceptionOccurred",(exceptionType,deviceType,deviceID)=>{
  console.log(`onLocalDeviceExceptionOccurred: ${exceptionType},${deviceType},${deviceID}`)
})

onRemoteCameraStateUpdate

Example:

zgEngine.on("onRemoteCameraStateUpdate",(streamID,state)=>{
  console.log(`onRemoteCameraStateUpdate: ${streamID},${state}`)
})

onRemoteMicStateUpdate

Example:

zgEngine.on("onRemoteMicStateUpdate",(streamID,state)=>{
  console.log(`onRemoteMicStateUpdate: ${streamID},${state}`)
})

onRemoteSpeakerStateUpdate

Example:

zgEngine.on("onRemoteSpeakerStateUpdate",(streamID,state)=>{
  console.log(`onRemoteSpeakerStateUpdate: ${streamID},${state}`)
})

onAudioVADStateUpdate

Example:

zgEngine.on("onAudioVADStateUpdate",(type,state)=>{
  console.log(`onAudioVADStateUpdate: ${type},${state}`)
})

onIMRecvBroadcastMessage

Example:

zgEngine.on("onIMRecvBroadcastMessage",(roomID,messageList)=>{
  console.log(`onIMRecvBroadcastMessage: ${roomID},${messageList}`)
})

onIMRecvBarrageMessage

Example:

zgEngine.on("onIMRecvBarrageMessage",(roomID,messageList)=>{
  console.log(`onIMRecvBarrageMessage: ${roomID},${messageList}`)
})

onIMRecvCustomCommand

Example:

zgEngine.on("onIMRecvCustomCommand",(roomID,fromUser,command)=>{
  console.log(`onIMRecvCustomCommand: ${roomID},${fromUser},${command}`)
})

onCapturedDataRecordStateUpdate

Example:

zgEngine.on("onCapturedDataRecordStateUpdate",(state,errorCode,config,channel)=>{
  console.log(`onCapturedDataRecordStateUpdate: ${state},${errorCode},${config},${channel}`)
})

onCapturedDataRecordProgressUpdate

Example:

zgEngine.on("onCapturedDataRecordProgressUpdate",(progress,config,channel)=>{
  console.log(`onCapturedDataRecordProgressUpdate: ${progress},${config},${channel}`)
})

onNetworkModeChanged

Example:

zgEngine.on("onNetworkModeChanged",(mode)=>{
  console.log(`onNetworkModeChanged: ${mode}`)
})

onNetworkSpeedTestError

Example:

zgEngine.on("onNetworkSpeedTestError",(errorCode,type)=>{
  console.log(`onNetworkSpeedTestError: ${errorCode},${type}`)
})

onNetworkSpeedTestQualityUpdate

Example:

zgEngine.on("onNetworkSpeedTestQualityUpdate",(quality,type)=>{
  console.log(`onNetworkSpeedTestQualityUpdate: ${quality},${type}`)
})

onDownloadProgressUpdate

Example:

zgEngine.on("onDownloadProgressUpdate",(resourceID,progressRate)=>{
  console.log(`onDownloadProgressUpdate: ${resourceID},${progressRate}`)
})

onCurrentPitchValueUpdate

Example:

zgEngine.on("onCurrentPitchValueUpdate",(resourceID,currentDuration,pitchValue)=>{
  console.log(`onCurrentPitchValueUpdate: ${resourceID},${currentDuration},${pitchValue}`)
})

ZegoExpressMediaPlayer

onMediaPlayerStateUpdate

Example:

zgMediaPlayer.on("onMediaPlayerStateUpdate",(state,errorCode)=>{
  console.log(`onMediaPlayerStateUpdate: ${state},${errorCode}`)
})

onMediaPlayerNetworkEvent

Example:

zgMediaPlayer.on("onMediaPlayerNetworkEvent",(networkEvent)=>{
  console.log(`onMediaPlayerNetworkEvent: ${networkEvent}`)
})

onMediaPlayerPlayingProgress

Example:

zgMediaPlayer.on("onMediaPlayerPlayingProgress",(millisecond)=>{
  console.log(`onMediaPlayerPlayingProgress: ${millisecond}`)
})

onMediaPlayerRenderingProgress

Example:

zgMediaPlayer.on("onMediaPlayerRenderingProgress",(millisecond)=>{
  console.log(`onMediaPlayerRenderingProgress: ${millisecond}`)
})

onMediaPlayerVideoSizeChanged

Example:

zgMediaPlayer.on("onMediaPlayerVideoSizeChanged",(width,height)=>{
  console.log(`onMediaPlayerVideoSizeChanged: ${width},${height}`)
})

onMediaPlayerLoadResource

Example:

zgMediaPlayer.on("onMediaPlayerLoadResource",(errorCode,seq)=>{
  console.log(`onMediaPlayerLoadResource: ${errorCode},${seq}`)
})

onMediaPlayerVideoData

Example:

zgMediaPlayer.on("onMediaPlayerVideoData",(videoParam)=>{
  console.log(`onMediaPlayerVideoData: ${videoParam}`)
})

onMediaPlayerRecvSEI

Example:

zgMediaPlayer.on("onMediaPlayerRecvSEI",(data)=>{
  console.log(`onMediaPlayerRecvSEI: ${data}`)
})

onMediaPlayerSoundLevelUpdate

Example:

zgMediaPlayer.on("onMediaPlayerSoundLevelUpdate",(soundLevel)=>{
  console.log(`onMediaPlayerSoundLevelUpdate: ${soundLevel}`)
})

onMediaPlayerFrequencySpectrumUpdate

Example:

zgMediaPlayer.on("onMediaPlayerFrequencySpectrumUpdate",(spectrumList)=>{
  console.log(`onMediaPlayerFrequencySpectrumUpdate: ${spectrumList}`)
})

onMediaPlayerFirstFrameEvent

Example:

zgMediaPlayer.on("onMediaPlayerFirstFrameEvent",(event)=>{
  console.log(`onMediaPlayerFirstFrameEvent: ${event}`)
})

onMediaPlayerLocalCache

Example:

zgMediaPlayer.on("onMediaPlayerLocalCache",(errorCode,resource,cachedFile)=>{
  console.log(`onMediaPlayerLocalCache: ${errorCode},${resource},${cachedFile}`)
})

ZegoExpressAudioEffectPlayer

onAudioEffectPlayStateUpdate

Example:

zgAudioEffectPlayer.on("onAudioEffectPlayStateUpdate",(audioEffectID,state,errorCode)=>{
  console.log(`onAudioEffectPlayStateUpdate: ${audioEffectID},${state},${errorCode}`)
})

ZegoExpressScreenCaptureSource

onExceptionOccurred

Example:

zgScreenCaptureSource.on("onExceptionOccurred",(exceptionType)=>{
  console.log(`onExceptionOccurred: ${exceptionType}`)
})

onWindowStateChanged

  • Supported Version: 3.4.0 and above.
  • Note: This callback takes effect after setting the [on] interface. To cancel the callback, please refer to Cancel Callback.
  • Usage Restriction: Only applicable to Windows/macOS.
  • Example:

    zgScreenCaptureSource.on("onWindowStateChanged",(source,windowState,windowRect)=>{
      console.log(`onWindowStateChanged: ${source},${windowState},${windowRect}`)
    })
  • Callback Trigger Timing: The state of the target window being captured changes.

  • Parameter Information:

Parameter Type Description
source ZegoAudioSourceType The screen capture source instance for the callback.
windowState ZegoScreenCaptureWindowState The state of the captured window.
windowRect ZegoRect The rectangle of the captured window.

ZegoScreenCaptureWindowState Screen Capture Source Window State

Properties:

  • ZegoScreenCaptureWindowStateOnScreen:

    ZegoScreenCaptureWindowStateOnScreen = (0)
    The window is on the current screen, and the coordinate area changes.

  • ZegoScreenCaptureWindowStateOffScreen:

    ZegoScreenCaptureWindowStateOffScreen = (1)
    The window leaves the current screen, pausing capture.

  • ZegoScreenCaptureWindowStateDestroy:

    ZegoScreenCaptureWindowStateDestroy = (2)
    The window is destroyed.

onRectChanged

  • Supported Version: 3.7.0 and above.
  • Note: This callback takes effect after setting the [on] interface. To cancel the callback, please refer to Cancel Callback.
  • Usage Restriction: Only applicable to Windows/macOS.
  • Example:

    zgScreenCaptureSource.on("onRectChanged",(source,captureRect)=>{
      console.log(`onRectChanged: ${source},${captureRect}`)
    })
  • Callback Trigger Timing: The capture area changes.

  • Parameter Information:

Parameter Type Description
source ZegoAudioSourceType The screen capture source instance for the callback.
captureRect ZegoRect The rectangle of the capture area.

Cancel Callback

To unregister a callback, you can use the off and removeAllListeners methods to cancel the registered callback.

Method Parameter Description
off eventName,listener Cancel the registered callback for the specified event
removeAllListeners eventName Cancel all registered callbacks for the specified event

The on method can register multiple callbacks for the same event. When using an anonymous function callback registered with on, you can only use the removeAllListeners method to cancel all callbacks.

Cancel Callback Example

The following uses the zgEngine's onDebugError event as an example.

Use the off method to cancel the Listener callback registered for "onDebugError".

const Listener = (errorCode,funcName,info)=>{
  console.log(`onDebugError: ${errorCode},${funcName},${info}`)
}

zgEngine.on("onDebugError",Listener)

zgEngine.off("onDebugError",Listener)

Use the removeAllListeners method to cancel all registered callbacks for "onDebugError".

zgEngine.removeAllListeners("onDebugError")
Page Directory
  • Free trial
  • 提交工单
    咨询集成、功能及报价等问题
    电话咨询
    400 1006 604
    Get Consulting
    Scan Wechat QR code