human: 如何处理七牛云的实时音视频QNRTCClient

gpt: [实时音视频](https://developer.qiniu.com/rtc) > API 文档 > Uniapp >QNRTCClient

#  QNRTCClient

最近更新时间: 2023-12-11 15:56:09

Index

Method

  * getConnectionState
  * getLocalAudioTrackStats
  * getLocalVideoTrackStats
  * getPublishedTracks
  * getRemoteAudioTrackStats
  * getRemoteUsers
  * getRemoteVideoTrackStats
  * getSubscribedTracks
  * getUserNetworkQuality
  * join
  * leave
  * off
  * on
  * publish
  * removeTranscodingLiveStreamingTracks
  * sendMessage
  * setAutoSubscribe
  * setClientRole
  * setTranscodingLiveStreamingTracks
  * startLiveStreamingWithDirect
  * startLiveStreamingWithTranscoding
  * startMediaRelay
  * stopLiveStreamingWithDirect
  * stopLiveStreamingWithTranscoding
  * stopMediaRelay
  * subscribe
  * unpublish
  * unsubscribe
  * updateMediaRelay

Method

getConnectionState

  * getConnectionState(): [QNConnectionState](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11407/UniappQNConnectionState)
  * 获取 RTC client 的房间状态

Returns
[QNConnectionState](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11407/UniappQNConnectionState)

getLocalAudioTrackStats

  * getLocalAudioTrackStats(): Record<string,[QNLocalAudioTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11420/UniappQNLocalAudioTrackStats)>
  * 获取已发布的近端音频轨道统计信息

> 返回以 trackID 为
> key，[QNLocalAudioTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11420/UniappQNLocalAudioTrackStats)
> 为 value 的对象

Returns
Record<string,[QNLocalAudioTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11420/UniappQNLocalAudioTrackStats)>

getLocalVideoTrackStats

  * getLocalVideoTrackStats(): Record<string,[QNLocalVideoTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11389/UniappQNLocalVideoTrackStats)[]>
  * 获取已发布的近端视频轨道统计信息

> 返回以 trackID 为
> [QNLocalVideoTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11389/UniappQNLocalVideoTrackStats)[]
> 为 value 的对象，数组表示包括各个大小流信息

Returns
Record<string,[QNLocalVideoTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11389/UniappQNLocalVideoTrackStats)[]>

getPublishedTracks

  * getPublishedTracks(): [QNLocalTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11386/UniappQNLocalTrack)[]
  * 获取已发布 Track 列表

Returns
[QNLocalTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11386/UniappQNLocalTrack)[]

getRemoteAudioTrackStats

  * getRemoteAudioTrackStats(): Record<string,[QNRemoteAudioTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11384/UniappQNRemoteAudioTrackStats)>
  * 获取已订阅的远端音频轨道统计信息

> 返回以 trackID 为
> key，[QNLocalAudioTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11420/UniappQNLocalAudioTrackStats)
> 为 value 的对象

Returns
Record<string,[QNRemoteAudioTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11384/UniappQNRemoteAudioTrackStats)>

getRemoteUsers

  * getRemoteUsers(): [QNRemoteUser](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11422/UniappQNRemoteUser)[]
  * 获取对应 ID 的远端用户

> 获取房间内所有的远端用户

Returns
[QNRemoteUser](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11422/UniappQNRemoteUser)[]

getRemoteVideoTrackStats

  * getRemoteVideoTrackStats(): Record<string,[QNRemoteVideoTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11428/UniappQNRemoteVideoTrackStats)>
  * 获取已订阅的远端视频轨道统计信息

> 返回以 trackID 为
> [QNRemoteVideoTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11428/UniappQNRemoteVideoTrackStats)
> 为 value 的对象

Returns
Record<string,[QNRemoteVideoTrackStats](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11428/UniappQNRemoteVideoTrackStats)>

getSubscribedTracks

  * getSubscribedTracks(userID: string): ([QNRemoteVideoTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11380/UniappQNRemoteVideoTrack) | [QNRemoteAudioTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11412/UniappQNRemoteAudioTrack))[]
  * 获取指定用户已被自己订阅的 Tracks

Parameters

    * userID: string 

用户 ID

Returns ([QNRemoteVideoTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11380/UniappQNRemoteVideoTrack) | [QNRemoteAudioTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11412/UniappQNRemoteAudioTrack))[]

getUserNetworkQuality

  * getUserNetworkQuality(userID: string): [QNNetworkQuality](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11408/UniappQNNetworkQuality)
  * 获取当前订阅的远端用户网络质量

> 获取当前订阅的远端用户网络质量

Parameters

    * userID: string 

用户 ID

Returns
[QNNetworkQuality](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11408/UniappQNNetworkQuality)

join

  * join(token: string, userData: string): void
  * 加入房间

Parameters

    * token: string 

房间 Token

    * userData: string 

用户信息

Returns void

leave

  * leave(): void
  * 离开房间

Returns void

off

  * off(name: event, listener: [QNRTCClinetEvent](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11404/UniappQNRTCClinetEvent)[event]): void
  * 取消监听对应的事件

> 取消监听对应的事件

Parameters

    * name: event 

事件名

    * listener: [QNRTCClinetEvent](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11404/UniappQNRTCClinetEvent)[event] 

事件句柄

Returns void

on

  * on(name: event, listener: [QNRTCClinetEvent](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11404/UniappQNRTCClinetEvent)[event]): void
  * 监听对应的事件

> 支持多次调用同一事件

Parameters

    * name: event 

事件名

    * listener: [QNRTCClinetEvent](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11404/UniappQNRTCClinetEvent)[event] 

事件句柄

Returns void

publish

  * publish(tracks: [QNLocalTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11386/UniappQNLocalTrack)[], callback: [QNPublishResultCallback](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11557/UniappQNPublishResultCallback)): void
  * 发布本地 Track 列表

Parameters

    * tracks: [QNLocalTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11386/UniappQNLocalTrack)[] 

要发布的本地 Track 列表

    * callback: [QNPublishResultCallback](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11557/UniappQNPublishResultCallback)

发布结果回调

Returns void

removeTranscodingLiveStreamingTracks

  * removeTranscodingLiveStreamingTracks(streamID: string, transcodingTracks: [QNTranscodingLiveStreamingTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11425/UniappQNTranscodingLiveStreamingTrack)[]): void
  * 移除合流转推布局配置

> 更新成功会触发 RTCClinetEvent.onUpdatedLiveStreaming 回调

Parameters

    * streamID: string 

合流 ID

    * transcodingTracks: [QNTranscodingLiveStreamingTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11425/UniappQNTranscodingLiveStreamingTrack)[] 

待移除合流转推布局配置

Returns void

sendMessage

  * sendMessage(message: string, users: string[], messageId: string): void
  * 发送自定义消息到指定用户群

Parameters

    * message: string 

自定义消息内容

    * users: string[] 

用户 ID 列表

    * messageId: string 

自定义消息 ID

Returns void

setAutoSubscribe

  * setAutoSubscribe(autoSubscribe: boolean): void
  * 设置是否自动订阅

> 默认开启自动订阅

Parameters

    * autoSubscribe: boolean 

是否自动订阅

Returns void

setClientRole

  * setClientRole(clientRole: [QNClientRole](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12605/UniappQNClientRole), callback: [QNClientRoleResultCallback](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12604/UniappQNClientRoleResultCallback)): void
  * 设置互动直播场景下的用户角色

> 该方法在加入频道前后均可调用，该方法仅适用于直播场景

Parameters

    * clientRole: [QNClientRole](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12605/UniappQNClientRole)

    * callback: [QNClientRoleResultCallback](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12604/UniappQNClientRoleResultCallback)

Returns void

setTranscodingLiveStreamingTracks

  * setTranscodingLiveStreamingTracks(streamID: string, transcodingTracks: [QNTranscodingLiveStreamingTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11425/UniappQNTranscodingLiveStreamingTrack)[]): void
  * 新增、更新合流转推布局配置

> 更新成功会触发 RTCClinetEvent.onUpdatedLiveStreaming 回调 新增 Track 布局以及对已有的 Track
> 的合流布局进行更新均可通过该接口实现，只需修改 transcodingTracks 对应的 Track 内容即可

Parameters

    * streamID: string 

合流 ID

    * transcodingTracks: [QNTranscodingLiveStreamingTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11425/UniappQNTranscodingLiveStreamingTrack)[] 

待新增、更新的合流转推布局配置

Returns void

startLiveStreamingWithDirect

  * startLiveStreamingWithDirect(config: [QNDirectLiveStreamingConfig](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11391/UniappQNDirectLiveStreamingConfig)): void
  * 开始单路 CDN 转推

> 转推成功会触发 RTCClinetEvent.onStartLiveStreaming 回调

Parameters

    * config: [QNDirectLiveStreamingConfig](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11391/UniappQNDirectLiveStreamingConfig)

单路转推配置

Returns void

startLiveStreamingWithTranscoding

  * startLiveStreamingWithTranscoding(config: [QNTranscodingLiveStreamingConfig](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11416/UniappQNTranscodingLiveStreamingConfig)): void
  * 开始合流转码 CDN 转推

> 转推成功会触发 RTCClinetEvent.onStartLiveStreaming 回调

Parameters

    * config: [QNTranscodingLiveStreamingConfig](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11416/UniappQNTranscodingLiveStreamingConfig)

合流转推配置

Returns void

startMediaRelay

  * startMediaRelay(configuration: [QNMediaRelayConfiguration](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12599/UniappQNMediaRelayConfiguration), callback: [QNMediaRelayResultCallback](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12598/UniappQNMediaRelayResultCallback)): void
  * 开启跨房媒体转发

> 如果已经开启，则调用失败 当所有目标房间跨房媒体转发都失败，则本次跨房媒体转发请求视为失败，使用跨房媒体转发功能需要再次调用此方法
> 当有任意一个目标或多个目标房间媒体转发成功，则本次跨房媒体转发请求视为成功，具体每个房间的状态参考回调结果
> 注意：该方法仅适用于互动直播场景中角色类型为主播的用户

Parameters

    * configuration: [QNMediaRelayConfiguration](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12599/UniappQNMediaRelayConfiguration)

跨房媒体转发配置

    * callback: [QNMediaRelayResultCallback](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12598/UniappQNMediaRelayResultCallback)

跨房媒体转发回调接口

Returns void

stopLiveStreamingWithDirect

  * stopLiveStreamingWithDirect(config: [QNDirectLiveStreamingConfig](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11391/UniappQNDirectLiveStreamingConfig)): void
  * 停止单路 CDN 转推

> 停止成功会触发 RTCClinetEvent.onStoppedLiveStreaming 回调

Parameters

    * config: [QNDirectLiveStreamingConfig](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11391/UniappQNDirectLiveStreamingConfig)

单路转推配置

Returns void

stopLiveStreamingWithTranscoding

  * stopLiveStreamingWithTranscoding(config: [QNTranscodingLiveStreamingConfig](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11416/UniappQNTranscodingLiveStreamingConfig)): void
  * 停止合流转码 CDN 转推

> 停止成功会触发 RTCClinetEvent.onStoppedLiveStreaming 回调

Parameters

    * config: [QNTranscodingLiveStreamingConfig](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11416/UniappQNTranscodingLiveStreamingConfig)

合流转推配置

Returns void

stopMediaRelay

  * stopMediaRelay(callback: [QNMediaRelayResultCallback](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12598/UniappQNMediaRelayResultCallback)): void
  * 停止跨房媒体转发

> 如果未开启，则调用失败 注意：此方法会停止在所有目标房间中的媒体转发；该方法仅适用互动直播场景中角色类型为主播的用户

Parameters

    * callback: [QNMediaRelayResultCallback](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12598/UniappQNMediaRelayResultCallback)

回调接口

Returns void

subscribe

  * subscribe(tracks: ([QNRemoteVideoTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11380/UniappQNRemoteVideoTrack) | [QNRemoteAudioTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11412/UniappQNRemoteAudioTrack))[]): void
  * 订阅远端 Track

Parameters

    * tracks: ([QNRemoteVideoTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11380/UniappQNRemoteVideoTrack) | [QNRemoteAudioTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11412/UniappQNRemoteAudioTrack))[] 

要订阅的远端 Track

Returns void

unpublish

  * unpublish(tracks: [QNLocalTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11386/UniappQNLocalTrack)[]): void
  * 取消发布本地 Track

Parameters

    * tracks: [QNLocalTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11386/UniappQNLocalTrack)[] 

要取消的本地 Track 列表

Returns void

unsubscribe

  * unsubscribe(tracks: ([QNRemoteVideoTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11380/UniappQNRemoteVideoTrack) | [QNRemoteAudioTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11412/UniappQNRemoteAudioTrack))[]): void
  * 取消订阅远端 Track

Parameters

    * tracks: ([QNRemoteVideoTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11380/UniappQNRemoteVideoTrack) | [QNRemoteAudioTrack](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/11412/UniappQNRemoteAudioTrack))[] 

要取消订阅的远端 Track

Returns void

updateMediaRelay

  * updateMediaRelay(configuration: [QNMediaRelayConfiguration](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12599/UniappQNMediaRelayConfiguration), callback: [QNMediaRelayResultCallback](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12598/UniappQNMediaRelayResultCallback)): void
  * 更新跨房媒体转发

> 成功开启跨房媒体转发后，如果您希望将流转发到多个目标房间，或退出当前正在转发的房间，可以调用该方法 此方法为全量更新，正在跨房媒体转发中却未被包含在参数
> configuration 中的房间，将停止媒体转发
> 注意：调用此方法前必须确保已经成功开启跨房媒体转发，否则将调用失败；该方法仅适用互动直播场景中角色类型为主播的用户

Parameters

    * configuration: [QNMediaRelayConfiguration](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12599/UniappQNMediaRelayConfiguration)

跨房媒体转发配置

    * callback: [QNMediaRelayResultCallback](https://developer.qiniu.com/rtc/11402/UniappQNRTCClient/12598/UniappQNMediaRelayResultCallback)

回调接口

Returns void

以上内容是否对您有帮助？