logo
On this page

Setting Callbacks


Warning

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

Module Description

Express Electron SDK manages callbacks across multiple modules. Modules and their instance acquisition methods 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} Specified screen ID or window ID
    // sourceType  {ZegoScreenCaptureSourceType} Specified screen source type.
    const zgScreenCaptureSource = zgEngine.createScreenCaptureSource(sourceId, sourceType);

Register Callbacks

ZegoExpressEngine

onDebugError

Usage example:

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

onEngineStateUpdate

Usage example:

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

onRecvExperimentalAPI

Usage example:

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

onRoomStateUpdate

Usage example:

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

onRoomStateChanged

Usage example:

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

onRoomUserUpdate

Usage example:

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

onRoomOnlineUserCountUpdate

Usage example:

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

onRoomStreamUpdate

Usage example:

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

onRoomStreamExtraInfoUpdate

Usage example:

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

onRoomExtraInfoUpdate

Usage example:

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

onRoomTokenWillExpire

Usage example:

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

onPublisherStateUpdate

Usage example:

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

onPublisherQualityUpdate

Usage example:

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

onPublisherCapturedAudioFirstFrame

Usage example:

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

onPublisherCapturedVideoFirstFrame

Usage example:

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

onPublisherSendAudioFirstFrame

Usage example:

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

onPublisherSendVideoFirstFrame

Usage example:

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

onPublisherVideoSizeChanged

Usage example:

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

onPublisherRelayCDNStateUpdate

Usage example:

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

onVideoObjectSegmentationStateChanged

Usage example:

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

onPlayerStateUpdate

Usage example:

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

onPlayerQualityUpdate

Usage example:

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

onPlayerMediaEvent

Usage example:

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

onPlayerRecvAudioFirstFrame

Usage example:

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

onPlayerRecvVideoFirstFrame

Usage example:

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

onPlayerRenderVideoFirstFrame

Usage example:

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

onPlayerVideoSizeChanged

Usage example:

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

onPlayerRecvSEI

Usage example:

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

onPlayerSyncRecvSEI

Usage example:

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

onAudioDeviceStateChanged

Usage example:

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

onAudioDeviceVolumeChanged

Usage example:

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

onVideoDeviceStateChanged

Usage example:

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

onCapturedSoundLevelUpdate

Usage example:

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

onCapturedSoundLevelInfoUpdate

Usage example:

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

onRemoteSoundLevelUpdate

Usage example:

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

onLocalCaptureVideoData

Usage example:

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

onRemotePlayVideoData

Usage example:

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

onRemoteSoundLevelInfoUpdate

Usage example:

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

onCapturedAudioSpectrumUpdate

Usage example:

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

onRemoteAudioSpectrumUpdate

Usage example:

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

onLocalDeviceExceptionOccurred

Usage example:

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

onRemoteCameraStateUpdate

Usage example:

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

onRemoteMicStateUpdate

Usage example:

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

onRemoteSpeakerStateUpdate

Usage example:

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

onAudioVADStateUpdate

Usage example:

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

onIMRecvBroadcastMessage

Usage example:

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

onIMRecvBarrageMessage

Usage example:

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

onIMRecvCustomCommand

Usage example:

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

onCapturedDataRecordStateUpdate

Usage example:

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

onCapturedDataRecordProgressUpdate

Usage example:

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

onNetworkModeChanged

Usage example:

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

onNetworkSpeedTestError

Usage example:

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

onNetworkSpeedTestQualityUpdate

Usage example:

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

onDownloadProgressUpdate

Usage example:

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

onCurrentPitchValueUpdate

Usage example:

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

ZegoExpressMediaPlayer

onMediaPlayerStateUpdate

Usage example:

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

onMediaPlayerNetworkEvent

Usage example:

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

onMediaPlayerPlayingProgress

Usage example:

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

onMediaPlayerRenderingProgress

Usage example:

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

onMediaPlayerVideoSizeChanged

Usage example:

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

onMediaPlayerLoadResource

Usage example:

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

onMediaPlayerVideoData

Usage example:

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

onMediaPlayerRecvSEI

Usage example:

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

onMediaPlayerSoundLevelUpdate

Usage example:

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

onMediaPlayerFrequencySpectrumUpdate

Usage example:

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

onMediaPlayerFirstFrameEvent

Usage example:

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

onMediaPlayerLocalCache

Usage example:

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

ZegoExpressAudioEffectPlayer

onAudioEffectPlayStateUpdate

Usage example:

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

ZegoExpressScreenCaptureSource

onExceptionOccurred

Usage example:

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

onWindowStateChanged

Note
  • Supported version: 3.4.0 and above.
  • Note: This callback takes effect only after calling the interface [on] to set it. To cancel the callback, please refer to Cancel Callbacks
  • Usage limitation: Only applicable to Windows/macOS
  • Usage example:

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

  • Parameter information:

ParameterTypeDescription
sourceZegoAudioSourceTypeScreen capture source instance of the callback.
windowStateZegoScreenCaptureWindowStateState of the captured window
windowRectZegoRectCaptured window rectangle
Note

ZegoScreenCaptureWindowState Screen capture source window state

Properties:

  • ZegoScreenCaptureWindowStateOnScreen:

    ZegoScreenCaptureWindowStateOnScreen = (0) Window is on the current screen, coordinate area changes.

  • ZegoScreenCaptureWindowStateOffScreen:

    ZegoScreenCaptureWindowStateOffScreen = (1) Window leaves the current screen, pause capture.

  • ZegoScreenCaptureWindowStateDestroy:

    ZegoScreenCaptureWindowStateDestroy = (2) Window is destroyed.

onRectChanged

Note
  • Supported version: 3.7.0 and above.
  • Note: This callback takes effect only after calling the interface [on] to set it. To cancel the callback, please refer to Cancel Callbacks
  • Usage limitation: Only applicable to Windows/macOS
  • Usage example:

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

  • Parameter information:

ParameterTypeDescription
sourceZegoAudioSourceTypeScreen capture source instance of the callback.
captureRectZegoRectCaptured area rectangle

Cancel Callbacks

To cancel registered callbacks, you can use the off and removeAllListeners methods to cancel registered callbacks.

MethodParametersDescription
offeventName,listenerCancel registered callbacks for specified events
removeAllListenerseventNameCancel all registered callbacks for specified events
Warning

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

Cancel Callback Example

The following uses zgEngine's onDebugError event as an example,

Use the off method to cancel the Listener callback registered with "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 callbacks registered with "onDebugError".

zgEngine.removeAllListeners("onDebugError")

Previous

Scenario-based Audio and Video Configuration

Next

Using Token Authentication

On this page

Back to top