DingRTCClient
The DingRTCClient provides core features for audio/video calls, such as joining a channel and publishing and subscribing to audio/video tracks. You can create a Client object by calling createClient. A Client object represents a local client.
Attribute list
Parameter | Type | Description | Minimum version |
channelName | string | The name of the channel. This property is undefined if the local user has not joined a channel. | 0.7.0 |
connectionState | The connection state of the SDK instance to the server. | 0.7.0 | |
remoteUsers
| A list of remote users in the channel, including each user's ID and tracks. This list is empty if the local user has not joined a channel. | 0.7.0 | |
userId | string | The user ID of the local user. This property is undefined if the local user has not joined a channel. | 0.7.0 |
API list
API | Description | Minimum version |
Joins a channel, allowing users within it to communicate with each other. Joining a channel triggers the "connection-state-change" callback locally. After a local user joins the channel, remote users receive the "user-joined" callback. | 0.7.0 | |
Leaves a channel, which ends the call. Leaving a channel triggers the "connection-state-change" callback locally. Remote users receive the "user-left" callback. | 0.7.0 | |
Publishes local audio and video tracks to the channel. After the local user publishes the tracks, remote users receive the "user-published" callback. | 0.7.0 | |
Unpublishes local audio and video tracks. After the local user unpublishes the tracks, remote users receive the "user-unpublished" callback. | 0.7.0 | |
Subscribes to a remote user's audio and video tracks. | 0.7.0 | |
Unsubscribes from a remote user's audio and video tracks. | 0.7.0 | |
Removes the listener for a specified event. | 0.7.0 | |
Listens for a specified event and sets a callback function. | 0.7.0 | |
Listens for a specified event once; the listener is removed after the callback triggers. | 0.7.0 | |
Removes all listeners for a specified event or for all events on the object. | 0.7.0 | |
Reports the network status of the <live-pusher> pusher component. | 0.7.0 | |
Reports the state change of the <live-pusher> pusher component. | 0.7.0 | |
Reports the network status of the <live-player> player component. | 0.7.0 | |
Reports the state change of the <live-player> player component. | 0.7.0 |
Event list
Event | Parameters | Description | Minimum version |
(curState:ConnectionState, prevState:ConnectionState, reason?:DisconnectedReason) => void | Occurs when the connection state between the SDK and the server changes. | 0.7.0 | |
(uid: string, msg: 'mute-audio' | 'mute-video' | 'unmute-audio' | 'unmute-video') => void | Indicates a change in a remote user's status. The SDK handles these status changes automatically, so you do not need to track them manually. | 0.7.0 | |
(user:RemoteUser) => void | Occurs when a remote user or host joins the channel. | 0.7.0 | |
(user:RemoteUser) => void | Occurs when a remote user or host leaves the channel. | 0.7.0 | |
(user:RemoteUser, mediaType:TrackMediaType, auxiliary?: boolean) => void | Occurs when a remote user publishes an audio or video track. You can subscribe to and play the track in this callback. | 0.7.0 | |
(user:RemoteUser, mediaType:TrackMediaType, auxiliary?: boolean) => void | Occurs when a remote user unpublishes an audio or video track. | 0.7.0 | |
( ) => void | Fired when the media publishing reconnect starts. | 0.7.0 | |
(newRtmpUrl: string) => void | Fired when the media publishing reconnect succeeds. This event provides the new publish URL. | 0.7.0 | |
() => void | Fired when the media publishing reconnect fails. | 0.7.0 | |
(subParam: SubscribeParam) => void | Fired when the media subscription reconnect starts. | 0.7.0 | |
(subParam: SubscribeParam, newRtmpUrl: string) => void | Fired when the media subscription reconnect succeeds. This event provides the new playback URL. | 0.7.0 | |
(subParam: SubscribeParam) => void | Fired when the media subscription reconnect fails. | 0.7.0 |
API
join()
Users in the same channel can talk to each other.
Calling this method to join a channel triggers the "connection-state-change" callback locally.
When a local client joins the channel, remote clients receive the user-joined callback.
Type signature
join(joinInfo: JoinParam): Promise<{
remoteUsers: RemoteUser[];
timeLeft: number;
}>;
Parameters:
Parameter | Type | Description |
joinInfo | Parameters for joining a channel. |
Returns:
Parameter | Type | Description | Version |
remoteUsers | A list of remote users. | 3.0.0 | |
timeLeft | number | The time left in the channel. | 3.1.0 |
Returns
Promise<{ remoteUsers: RemoteUser[]; timeLeft: number }>
Leave()
Leaving the channel means hanging up or ending the call.
Calling this method to leave a channel locally triggers the "connection-state-change" callback.
The remote end triggers the "user-left" callback.
Type Signature
leave(): void;
Back
void
publish()
Publishes local audio and video tracks to the channel.
Publishing an audio and video track triggers the user-published callback on the remote end.
Type signature
publish(): Promise<PublishResult>;
return
Promise<PublishResult>
subscribe()
Subscribes to a remote user's audio and video tracks.
Type signature
subscribe(uid: string, mediaType: TrackMediaType, auxiliary?: boolean): Promise<RemoteTrack>;
Parameter | Type | Description |
uid | string | The remote user ID. |
mediaType | The media type of the track to unsubscribe from. | |
auxiliary | boolean | (Optional) Set to |
Back
Promise<RemoteTrack>
unpublish()
Stops publishing the local audio and video tracks.
Unpublishing an audio or video track triggers the user-unpublished callback for remote users.
Type signature
unpublish(): Promise<void>;
Back
Promise<void>
unsubscribe()
Unsubscribes from a remote user's audio and video tracks.
Type signature
unsubscribe(uid: string, mediaType?: TrackMediaType, auxiliary?: boolean): Promise<void>;
Parameter | Type | Description |
uid | string | The remote user ID. |
mediaType | The media type of the track to unsubscribe from. | |
auxiliary | boolean | (Optional) Specifies whether the video track is the screen sharing video stream. |
Back
Promise<void>
on()
Listens for a specified event and registers a callback function.
Type signature
on(event: string, fn: Function): void;
Parameters
Parameter | Type | Description |
event | string | The event to listen for. |
fn | Function | The callback function to execute when the event is triggered. |
Back
void
off()
Removes a listener for a specific event.
Type Signature
off(event: string, fn: Function): void;
Parameters
Parameter | Type | Description |
event | string | The event to listen for. |
fn | function | The callback function invoked when the event triggers. |
Back
void
once()
Adds a one-time listener for a specified event, which is removed after the callback function is invoked.
Type signature
once(event: string, fn: Function): void;
Parameters
Parameter | Type | Description |
event | string | The event to listen for. |
fn | callback function | The callback function called when the event is triggered. |
Back
void
removeAllListeners()
Removes all listeners for a specified event or for all events from the object.
type signature
removeAllListeners(event?: string): void;
Parameters
Parameter | Type | Description |
event | string | (Optional) Specifies the event whose listener callback functions will be removed. If this parameter is omitted, all listener callback functions are removed from the object. |
Back
void
reportPusherNetStatus()
Reports the network status of the <live-pusher> component.
Type signature
reportPusherNetStatus(detail: LivePusherNetStatusDetail): void;
Parameters
Parameter | Type | Description |
detail | Object | Details from the <live-pusher> component's |
Example
// WXML: <live-pusher bindnetstatus="onPusherNetStatusEvent" ... />
onPusherNetStatusEvent(event) {
client.reportPusherNetStatus(event.detail);
}Back
void
reportPusherStateChange()
Reports state changes in the <live-pusher> component.
type signature
reportPusherStateChange(detail: LivePusherStateChangeDetail): void;
Parameter
Parameter | Type | Description |
detail | Object | Details from the |
Example
// In WXML: <live-pusher bindstatechange="onPusherStateChangeEvent" ... />
onPusherStateChangeEvent(event) {
client.reportPusherStateChange(event.detail);
}Back
void
reportPlayerNetStatus()
Reports the network status of the live-player component.
Type signature
reportPlayerNetStatus(subParam: SubscribeParam, detail: LivePlayerNetStatusDetail): void;
Parameters
Parameter | Type | Description |
subParam | SubscribeParam | Subscription parameters, including uid, mediaType, and auxiliary. |
detail | Object | Details from the bindnetstatus callback of the <live-player> component. |
Example
// WXML: <live-player data-user-id="{{userId}}" bindnetstatus="onVideoPlayerNetStatus" ... />
onVideoPlayerNetStatus(event) {
const userId = event.currentTarget.dataset.userId;
const subParam = { uid: userId, mediaType: 'video', auxiliary: false };
client.reportPlayerNetStatus(subParam, event.detail);
}Back
void
reportPlayerStateChange()
Reports state changes for the <live-player> component.
Type signature
reportPlayerStateChange(subParam: SubscribeParam, detail: LivePlayerStateChangeDetail): void;
Parameter
Parameter | Type | Description |
subParam | SubscribeParam | The subscription parameter, including uid, mediaType, and auxiliary. |
detail | Object | Callback details for the bindstatechange event from <live-player>. |
Example
// WXML: <live-pusher bindstatechange="onPusherStateChangeEvent" ... />
onPusherStateChangeEvent(event) {
client.reportPusherStateChange(event.detail);
}Back
void
Event
connection-state-change
Triggered when the connection status between the SDK and the server changes.
type signature
'connection-state-change': (curState: ConnectionState, prevState: ConnectionState, reason?: DisconnectedReason) => void;user-info-updated
This callback signals a change in user status.
In most cases, you only need to listen for the user-published and user-unpublished events to subscribe, unsubscribe, and display the status of a remote user's camera and microphone. You don't need to manually track the underlying user state changes, as the SDK handles them automatically.
Type signature
'user-info-updated': (uid: string, msg: 'mute-audio' | 'mute-video' | 'unmute-audio' | 'unmute-video') => void;"user-joined"
Occurs when a remote user joins the channel.
Type signature
'user-joined': (user: RemoteUser) => void;
user-left
A remote user leaves the channel.
Type signature
'user-left': (user: RemoteUser) => void;
User-published
This callback is triggered when a remote user publishes a new audio or video track.
Use this callback to subscribe to and play the remote user's audio and video tracks.
Type signature
'user-published': (user: RemoteUser, mediaType: TrackMediaType, auxiliary?: boolean) => void;
user-unpublished
This callback is triggered when a remote user unpublishes an audio or video track.
type signature
'user-unpublished': (user: RemoteUser, mediaType: TrackMediaType, auxiliary?: boolean) => void;
pub-media-reconnect-started
Push reconnection started.
type signature
'pub-media-reconnect-started': () => void;
pub-media-reconnect-started
The push stream reconnection has started.
Type Signature
'pub-media-reconnect-started': () => void;
pub-media-reconnect-succeeded
The push stream has reconnected successfully, and a new push URL has been returned.
type signature
'pub-media-reconnect-succeeded': (newRtmpUrl: string) => void;
"pub-media-reconnect-failed"
Failed to reconnect the publishing stream.
Type signature
'pub-media-reconnect-failed': () => void;sub-media-reconnect-started
The subscription is reconnecting.
Type Signature
'sub-media-reconnect-started': (subParam: SubscribeParam) => void;
sub-media-reconnect-succeeded
A successful subscription reconnection returns a new streaming URL.
Type signature
'sub-media-reconnect-succeeded': (subParam: SubscribeParam, newRtmpUrl: string) => void;
sub-media-reconnect-failed
Subscription reconnection failed.
Type signature
'sub-media-reconnect-failed': (subParam: SubscribeParam) => void;