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

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

#  QNRTCClient

最近更新时间: 2022-03-02 11:52:22

RTC 核心类

Hierarchy

  * QNCore 
    * QNRTCClient 

Index

Event

  * CONNECTION_STATE_CHANGED
  * MESSAGE_RECEIVED
  * USER_JOINED
  * USER_LEFT
  * USER_PUBLISHED
  * USER_UNPUBLISHED

Method

  * join
  * leave
  * publish
  * removeTranscodingLiveStreamingTracks
  * sendMessage
  * setTranscodingLiveStreamingTracks
  * startDirectLiveStreaming
  * startTranscodingLiveStreaming
  * stopDirectLiveStreaming
  * stopTranscodingLiveStreaming
  * subscribe

Event

Static CONNECTION_STATE_CHANGED

  * on("connection-state-changed",(connectionState: [QNConnectionState](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10955/WXAppQNConnectionState), info: [QNConnectionDisconnectedInfo](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10943/WXAppQNConnectionDisconnectedInfo)) => void)
  * 连接状态改变

Parameters

    * connectionState: [QNConnectionState](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10955/WXAppQNConnectionState)

连接状态

    * info: [QNConnectionDisconnectedInfo](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10943/WXAppQNConnectionDisconnectedInfo)

连接信息

Static MESSAGE_RECEIVED

  * on("message-received",(message: [QNCustomMessage](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10960/WXAppQNCustomMessage)) => void)
  * 信息接收

Parameters

    * message: [QNCustomMessage](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10960/WXAppQNCustomMessage)

自定义消息内容

Static USER_JOINED

  * on("user-joined",(remoteUserID: string, userData: string) => void)
  * 用户加入房间

Parameters

    * remoteUserID: string 

远端用户ID

    * userData: string 

用户自定义信息

Static USER_LEFT

  * on("user-left",(remoteUserID: string) => void)
  * 用户离开房间

Parameters

    * remoteUserID: string 

远端用户ID

Static USER_PUBLISHED

  * on("user-published",(userID: string, track: [QNRemoteTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10948/WXAppQNRemoteTrack) | [QNRemoteTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10948/WXAppQNRemoteTrack)[]) => void)
  * 用户添加媒体轨

Parameters

    * userID: string 

    * track: [QNRemoteTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10948/WXAppQNRemoteTrack) | [QNRemoteTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10948/WXAppQNRemoteTrack)[] 

远端发布轨

Static USER_UNPUBLISHED

  * on("user-unpublished",(userID: string, track: [QNRemoteTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10948/WXAppQNRemoteTrack) | [QNRemoteTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10948/WXAppQNRemoteTrack)[]) => void)
  * 用户移除媒体轨

Parameters

    * userID: string 

    * track: [QNRemoteTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10948/WXAppQNRemoteTrack) | [QNRemoteTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10948/WXAppQNRemoteTrack)[] 

远端取消发布轨

Method

join

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

Parameters

    * token: string 

房间token

    * userData: string 

用户自定义信息

Returns Promise<void>

leave

  * leave(): Promise<void>
  * 离开房间

Returns Promise<void>

publish

  * publish(callback: [QNPublishCallback](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10941/WXAppQNPublishCallback)): Promise<void>
  * 发布流

Parameters

    * callback: [QNPublishCallback](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10941/WXAppQNPublishCallback)

发布后回调

Returns Promise<void>

removeTranscodingLiveStreamingTracks

  * removeTranscodingLiveStreamingTracks(streamID: string, transcodingTracks: [QNTranscodingLiveStreamingTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10961/WXAppQNTranscodingLiveStreamingTrack)[]): Promise<void>
  * 移除合流转推的布局

Parameters

    * streamID: string 

合流转推streamID

    * transcodingTracks: [QNTranscodingLiveStreamingTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10961/WXAppQNTranscodingLiveStreamingTrack)[] 

合流布局

Returns Promise<void>

sendMessage

  * sendMessage(messageID: string, message: string, users: [QNRemoteUser](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/11004/WXAppQNRemoteUser)[]): Promise<void>
  * 发送自定义消息

Parameters

    * messageID: string 

自定义消息 ID

    * message: string 

自定义消息内容

    * users: [QNRemoteUser](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/11004/WXAppQNRemoteUser)[] 

默认群发，接收消息用户，传入值若为非数组或空数组，则会采用默认行为进行群发

Returns Promise<void>

setTranscodingLiveStreamingTracks

  * setTranscodingLiveStreamingTracks(streamID: string, transcodingTracks: [QNTranscodingLiveStreamingTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10961/WXAppQNTranscodingLiveStreamingTrack)[]): Promise<void>
  * 新增、更新合流转推的布局

Parameters

    * streamID: string 

合流转推streamID

    * transcodingTracks: [QNTranscodingLiveStreamingTrack](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10961/WXAppQNTranscodingLiveStreamingTrack)[] 

合流布局

Returns Promise<void>

startDirectLiveStreaming

  * startDirectLiveStreaming(config: [QNDirectLiveStreamingConfig](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10945/WXAppQNDirectLiveStreamingConfig)): Promise<void>
  * 开启单路转推

Parameters

    * config: [QNDirectLiveStreamingConfig](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10945/WXAppQNDirectLiveStreamingConfig)

CDN转推参数

Returns Promise<void>

startTranscodingLiveStreaming

  * startTranscodingLiveStreaming(config: [QNTranscodingLiveStreamingConfig](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10959/WXAppQNTranscodingLiveStreamingConfig)): Promise<void>
  * 开启合流转推

Parameters

    * config: [QNTranscodingLiveStreamingConfig](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10959/WXAppQNTranscodingLiveStreamingConfig)

合流转推参数

Returns Promise<void>

stopDirectLiveStreaming

  * stopDirectLiveStreaming(streamID: string): Promise<void>
  * 停止单路转推

Parameters

    * streamID: string 

CDN转推streamID

Returns Promise<void>

stopTranscodingLiveStreaming

  * stopTranscodingLiveStreaming(streamID: string): Promise<void>
  * 停止合流转推

Parameters

    * streamID: string 

合流转推streamID

Returns Promise<void>

subscribe

  * subscribe(tracks: [QNSubscribeConfig](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10956/WXAppQNSubscribeConfig)): Promise<string>
  * 订阅流

Parameters

    * tracks: [QNSubscribeConfig](https://developer.qiniu.com/rtc/10950/WXAppQNRTCClient/10956/WXAppQNSubscribeConfig)

需要订阅的轨

Returns Promise<string>

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