Help Center/ SparkRTC/ SDK Reference/ Web SDK/ API Reference/ Client Event Notification (ClientEvent)
Updated on 2023-11-01 GMT+08:00

Client Event Notification (ClientEvent)

This section describes the ClientEvent events of the Web SDK.

Table 1 ClientEvent events

API

Description

peer-join

A remote user joins a room.

peer-leave

A remote user leaves a room.

stream-added

A remote stream is added.

stream-removed

A remote stream is deleted.

stream-updated

A remote stream is updated.

stream-subscribed

A remote stream is successfully subscribed to.

client-banned

A user is banned from a room.

Error

An error occurs on the client.

connection-state-changed

The client connection status changes.

mute-audio

The audio of a remote stream is disabled.

unmute-audio

The audio of a remote stream is enabled.

mute-video

The video of a remote stream is disabled.

unmute-video

The video of a remote stream is enabled.

log-upload-result

Log upload result.

signature-expired

A signature has expired. This event is added in version 2.0.8.

camera-changed

A camera is changed.

recording-device-changed

A recording device is changed.

playback-device-changed

A playback device is changed.

network-quality

Network uplink and downlink quality.

stream-interrupted

A remote stream is interrupted. This event is added in version 1.4.0.

stream-recovered

A remote stream is recovered. This event is added in version 1.4.0.

volume-indicator

A user speaks loudest in the top-N-audio mode (top three loudest participants). This event is added in version 1.5.0.

remote-user-name-changed

The nickname of a remote user is changed. This event is added in version 1.5.0.

rtc-stats

Audio and video stream data statistics event. This event is added in version 2.0.3.

Registration listening must be canceled when the service ends. Otherwise, memory leakage may occur when there are a certain number of registration listening events.

peer-join

[Event Description]

This event is triggered when a remote user joins a room.

[Callback Parameters]

peerJoinEvent: (mandatory) user information. The type is PeerJoin.

PeerJoin is defined as: {

  • userId: (mandatory) user ID. The type is string[64].
  • userName: (optional) user nickname. The type is string[256].

}

peer-leave

[Event Description]

This event is triggered when a remote user leaves a room.

[Callback Parameters]

peerLeaveEvent: (mandatory) user leaving information. The type is PeerLeaveInfo.

PeerLeaveInfo is defined as: {

  • userId: (mandatory) user ID. The type is string[64].
  • userName: (optional) user nickname. The type is string[256].
  • reason: (optional) The type is HRTCLeaveReason.

}

HRTCLeaveReason is defined as: {

  • code: enumeration of reasons for leaving the room. The type is number. Table 2 lists the values.
  • msg: reason description. The type is string.
}
Table 2 Reasons for leaving a room

Value

Description

0

The user exits the room.

1

A server exception occurs.

2

The SFU service is faulty.

3

The service is unavailable (503).

4

An internal error occurs.

5

The user is banned from the room.

6

The signature has expired.

7

Reconnection times out.

8

Network check. No error code is required for the UI.

9

The user is removed.

10

The room is dismissed.

stream-added

[Event Description]

This event is triggered when a remote user successfully sends a stream.

[Callback Parameters]

stream: (mandatory) remote stream object. The type is RemoteStream.

stream-removed

[Event Description]

This event is triggered when a remote user stops sending streams or exits the room.

[Callback Parameters]

stream: (mandatory) remote stream object. The type is RemoteStream.

stream-updated

[Event Description]

This event is triggered when the stream of a remote user changes. For example, audio and video tracks are added or removed, or the video track specifications change.

[Callback Parameters]

stream: (mandatory) remote stream object. The type is RemoteStream.

stream-subscribed

[Event Description]

This event is triggered when a remote stream is successfully subscribed to.

[Callback Parameters]

stream: (mandatory) remote stream object. The type is RemoteStream.

client-banned

[Event Description]

This event is triggered when a user is banned. When a user joins the same room on another client using the same user ID, the client on which the user is banned receives a notification.

[Callback Parameters]

clientBannedEvent: (mandatory) The type is ClientBanInfo.

ClientBanInfo is defined as: {
  • userId: (mandatory) ID of a banned user. The type is string[64].
  • reason: (mandatory) reason description. The type is string.

}

Error

[Event Description]

This event is triggered when an unrecoverable client error occurs.

[Callback Parameters]

errorInfo: (mandatory) error information. The type is ErrorInfo.

ErrorInfo is defined as: {
  • errorCode: (mandatory) error code. The type is string.
  • errorMsg: (mandatory) error description. The type is string.

}

connection-state-changed

[Event Description]

This event is triggered when the client connection status changes.

[Callback Parameters]

  • ConnectionStateInfoEvent: {
    • prevState: (mandatory) previous state. The type is ConnectionState.
    • curState: (mandatory) current state. The type is ConnectionState.

}

The options of ConnectionState are as follows:
  • CONNECTING
  • CONNECTED
  • RECONNECTING
  • DISCONNECTED

mute-audio

[Event Description]

This event is triggered when a remote user mutes the audio.

[Callback Parameters]

mediaStatus: (mandatory) The type is MediaStatusNotifyInfo.

MediaStatusNotifyInfo has the following attributes.

  • roomId: (mandatory) string[64] type.
  • userId: (mandatory) string[64] type.
  • status: (mandatory) MediaStatusAction type. The values of MediaStatusAction are as follows:
    • 1: Media assets are available.
    • 2: Media assets are unavailable.
  • reason: (mandatory) MediaStatusReason type. The values of MediaStatusReason are as follows:
    • 0: The media is offline.
    • 1: The media is muted.
    • 2: The media is not muted.

unmute-audio

[Event Description]

This event is triggered when a remote user unmutes the audio.

[Callback Parameters]

mediaStatus: (mandatory) The type is MediaStatusNotifyInfo.

mute-video

[Event Description]

This event is triggered when a remote user disables the video.

[Callback Parameters]

mediaStatus: (mandatory) The type is MediaStatusNotifyInfo.

unmute-video

[Event Description]

This event is triggered when a remote user enables the video.

[Callback Parameters]

mediaStatus: (mandatory) The type is MediaStatusNotifyInfo.

log-upload-result

[Event Description]

Log upload result.

[Callback Parameters]

status: (mandatory) log upload result. The type is number. 200 indicates that the log is successfully uploaded. Other values indicate that the log fails to be uploaded.

signature-expired

[Event Description]

This event is triggered when a signature has expired.

[Callback Parameters]

errorInfo: error information. (Mandatory) ErrorInfo type.

ErrorInfo is defined as: {
  • errorCode: error code. (Mandatory) string type.
  • errorMsg: (Mandatory) string type. The values are shown in the following example.

}

The values are shown in the following example.

  • Signature expired: {

    errorCode: '90100030'

    errorMsg: 'signature expired'

    }

  • Invalid signature: {

    errorCode: '90100031'

    errorMsg: 'signature invalid'

    }

After a signature expiration event is detected, the error code can be used to determine whether the signature is invalid or expired. After the signature expires, the renewSignature API can be called to update the signature.

camera-changed

[Event Description]

This event is triggered when the local camera is connected or disconnected.

[Callback Parameters]

DeviceChangedEvent: (mandatory) device change details. The type is DeviceChangedInfo.

DeviceChangedInfo is defined as: {
  • deviceId: (mandatory) device ID. The type is string.
  • state: (mandatory) The type is DeviceChangeMode. The values are as follows:
    • ADD: A device is connected.
    • REMOVE: A device is disconnected.

}

After a video capture device is removed and inserted, certain operations need to be performed at the application layer. For example, determine whether to use another video capture device for data collection when a camera is removed, and whether to use the newly inserted camera for data collection.

recording-device-changed

[Event Description]

This event is triggered when a local recording device is changed.

[Callback Parameters]

DeviceChangedEvent: (mandatory) device change details. The type is DeviceChangedInfo. For details about the definition of DeviceChangedInfo, see camera-changed.

After an audio capture device is removed and inserted, certain operations need to be performed at the application layer. For example, determine whether to use another audio capture device for data collection when a microphone is removed, and whether to use the newly inserted microphone for data collection.

playback-device-changed

[Event Description]

This event is triggered when a local audio playback device is changed.

[Callback Parameters]

DeviceChangedEvent: (mandatory) device change details. The type is DeviceChangedInfo. For details about the definition of DeviceChangedInfo, see camera-changed.

network-quality

[Event Description]

This event is triggered when the network quality changes after a user joins a room to report the uplink and downlink quality of the user's local network.

[Callback Parameters]

NetworkQualityEvent: (mandatory) uplink and downlink network quality details. The type is NetworkQualityInfo.

NetworkQualityInfo is defined as: {
  • uplinkNetworkQuality: (mandatory) uplink network quality. The type is number. The values are as follows:
    • 0: unknown.
    • 1: excellent.
    • 2: User experience is almost the same as that of value 1, but the bit rate may be slightly lower.
    • 3: User experience is unsatisfactory, but communication is smooth.
    • 4: Communication is barely smooth.
    • 5: The network quality is very poor, and communication is almost impossible.
    • 6: The network is disconnected, and communication fails.
  • downlinkNetworkQuality: (mandatory) downlink network quality. The type is number. The values are as follows:
    • 0: unknown.
    • 1: excellent.
    • 2: User experience is almost the same as that of value 1, but the bit rate may be slightly lower.
    • 3: User experience is unsatisfactory, but communication is smooth.
    • 4: Communication is barely smooth.
    • 5: The network quality is very poor, and communication is almost impossible.
    • 6: The network is disconnected, and communication fails.

}

stream-interrupted

[Event Description]

This event is triggered when a remote stream is interrupted. The interrupt indicates that no valid video frame is received within the statistical period specified by the interval parameter of the enableStreamStateDetection API. This event is added in version 1.4.0.

[Callback Parameters]

streamInterruptedEvent: (mandatory) list of remote users who are subscribed to by the local user but have no video stream. The type is UserList[].

UserList is defined as: {
  • userId: (mandatory) user ID. The type is string.
  • isScreen: (mandatory) The type is Boolean. true indicates the user's presentation stream; false indicates the user's video stream captured by cameras.

}

stream-recovered

[Event Description]

This event is triggered when a remote stream is recovered.

[Callback Parameters]

streamRecoveredEvent: (mandatory) list of remote users who are subscribed to by the local user and the video streams of the remote users have been recovered. The type is UserList[]. For details about UserList, see stream-interrupted. This event is added in version 1.4.0.

volume-indicator

[Event Description]

This event is triggered when a user speaks loudest in the room in top-N-audio mode.

[Callback Parameters]

userVolumeInfos: (mandatory) The type is UserVolumeInfo[].

UserVolumeInfo is defined as: {
  • user_id: (mandatory) user ID. The type is string.
  • volume: (optional) The type is number. Value range: [0,100].

}

This event takes effect only in the top-N-audio mode and is added in version 1.5.0.

remote-user-name-changed

[Event Description]

This event is triggered when the nickname of a remote user is changed. This event is added in version 1.5.0.

[Callback Parameters]

userNameChangedEvent: (mandatory) UserNameInfo type.

UserNameInfo is defined as: {
  • roomId: (mandatory) room ID. The type is string[64].
  • userId: (mandatory) user ID. The type is string[64].
  • userName: (mandatory) new nickname of the user. The type is string[256].

}

rtc-stats

[Event Description]

Audio and video stream data statistics event. This event is added in version 2.0.3.

[Callback Parameters]

rtcStatsInfo: (mandatory) rtcStatsInfo[] type.

rtcStatsInfo is defined as: {
  • userName: (mandatory) user nickname. The type is string.
  • isRemote: (mandatory) whether a stream is a remote stream. The type is Boolean. The value true indicates a remote stream, and the value false indicates a local stream.
  • streamType: (mandatory) stream type. The type is ContentType. The enumerated values of ContentType are as follows: {
    • main: video stream. The type is string.
    • middle1: video stream. The type is string. The code streams from middle1 to middle4 are in descending order.
    • middle2: video stream. The type is string. The code streams from middle1 to middle4 are in descending order.
    • middle3: video stream. The type is string. The code streams from middle1 to middle4 are in descending order.
    • middle4: video stream. The type is string. The code streams from middle1 to middle4 are in descending order.
    • slides: video stream with the minimum resolution. The type is string.
    • desktop: presentation stream. The type is string.

      }

  • mediaType: (mandatory) media type, which can be audio or video. The type is MediaType.
  • bitrate: (mandatory) bitrate of an audio or video stream, in kbit/s. The type is number.
  • frameRate: (mandatory) video frame rate, in fps. The type is number.
  • rtt: (mandatory) round-trip time (RTT) from the SDK to the edge server, in milliseconds. The type is number. Only local streams have the RTT.
  • jitter: (mandatory) jitter of the audio and video stream. The type is number.
  • pktLossRate: (mandatory) packet loss rate of the audio and video stream. The type is number.

}