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

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

#  QNRTCClientDelegate

最近更新时间: 2023-11-20 11:12:51

QNRTCClient 事件回调接口，用于回调 RTC 房间相关的事件，如房间状态改变等。可以在 QNRTCClient 的初始化后遵守并实现该代理。

Index

Core Methods

  * didConnectionStateChanged
  * didJoinOfUserID
  * didLeaveOfUserID
  * didSubscribedRemoteVideoTracks
  * didUserPublishTracks
  * didUserUnpublishTracks
  * didReconnectingOfUserID
  * didReconnectedOfUserID
  * didStartLiveStreaming
  * didStopLiveStreaming
  * didTranscodingTracksUpdated
  * didErrorLiveStreaming
  * didReceiveMessage
  * firstVideoDidDecodeOfTrack
  * didDetachRenderTrack
  * didMediaRelayStateChanged
  * remoteTrackMixedDidGetAudioBuffer
  * didNetworkQualityNotified
  * didUserVolumeIndication

Core Methods

didConnectionStateChanged

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didConnectionStateChanged:([QNConnectionState](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/9254))state disconnectedInfo:([QNConnectionDisconnectedInfo](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8866/QNConnectionDisconnectedInfo-iOS) *)info;
  * 房间状态变更会触发此回调

> 当状态变为 QNConnectionStateReconnecting 时，SDK 会为您自动重连，重连过程中，如果希望退出，直接调用 leave
> 即可。重连成功后的状态将变为 QNConnectionStateReconnected。

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * state: [QNConnectionState](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/9254)

房间状态

    * info: [QNConnectionDisconnectedInfo](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8866/QNConnectionDisconnectedInfo-iOS)

房间失去连接的具体信息

didJoinOfUserID

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didJoinOfUserID:(NSString *)userID userData:(NSString *)userData;
  * 远端用户加入房间会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * userID: NSString 

用户 ID

    * userData: NSString 

用户信息

didLeaveOfUserID

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didLeaveOfUserID:(NSString *)userID;
  * 远端用户离开房会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * userID: NSString 

用户 ID

didSubscribedRemoteVideoTracks

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didSubscribedRemoteVideoTracks:(NSArray<[QNRemoteVideoTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8858/QNRemoteVideoTrack-iOS) *> *)videoTracks audioTracks:(NSArray<[QNRemoteAudioTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8859/QNRemoteAudioTrack-iOS) *> *)audioTracks ofUserID:(NSString *)userID;
  * 订阅远端用户成功会触发此回调

> 无论手动订阅还是自动订阅都会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * videoTracks: NSArray<[QNRemoteVideoTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8858/QNRemoteVideoTrack-iOS)>

远端视频 Tracks

    * audioTracks: NSArray<[QNRemoteAudioTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8859/QNRemoteAudioTrack-iOS)>

远端音频 Tracks

    * userID: NSString 

用户 ID

didUserPublishTracks

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didUserPublishTracks:(NSArray<[QNRemoteTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8857/QNRemoteTrack-iOS) *> *)tracks ofUserID:(NSString *)userID;
  * 远端用户发布音/视频会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * tracks: NSArray<[QNRemoteTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8857/QNRemoteTrack-iOS)>

远端 Tracks

    * userID: NSString 

用户 ID

didUserUnpublishTracks

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didUserUnpublishTracks:(NSArray<[QNRemoteTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8857/QNRemoteTrack-iOS) *> *)tracks ofUserID:(NSString *)userID;
  * 远端用户取消发布音/视频会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * tracks: NSArray<[QNRemoteTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8857/QNRemoteTrack-iOS)>

远端 Tracks

    * userID: NSString 

用户 ID

didReconnectingOfUserID

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didReconnectingOfUserID:(NSString *)userID;
  * 远端用户发生重连会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * userID: NSString 

用户 ID

didReconnectedOfUserID

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didReconnectedOfUserID:(NSString *)userID;
  * 远端用户重连成功会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * userID: NSString 

用户 ID

didStartLiveStreaming

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didStartLiveStreaming:(NSString *)streamID;
  * 成功创建转推/合流转推任务会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * streamID: NSString 

流 ID

didStopLiveStreaming

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didStopLiveStreaming:(NSString *)streamID;
  * 停止转推/合流转推任务会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * streamID: NSString 

流 ID

didTranscodingTracksUpdated

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didTranscodingTracksUpdated:(BOOL)success withStreamID:(NSString *)streamID;
  * 更新合流布局会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * success: BOOL 

是否成功

    * streamID: NSString 

流 ID

didErrorLiveStreaming

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didErrorLiveStreaming:(NSString *)streamID errorInfo:([QNLiveStreamingErrorInfo](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8864/QNLiveStreamingErrorInfo-iOS) *)errorInfo;
  * 单路转推或合流转推出错会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * streamID: NSString 

流 ID

    * errorInfo: [QNLiveStreamingErrorInfo](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8864/QNLiveStreamingErrorInfo-iOS)

错误信息

didReceiveMessage

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didReceiveMessage:([QNMessageInfo](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/9264/QNMessageInfo) *)message;
  * 收到远端用户发送给自己的消息时会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * message: [QNMessageInfo](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/9264/QNMessageInfo)

消息信息对象

firstVideoDidDecodeOfTrack

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client firstVideoDidDecodeOfTrack:([QNRemoteVideoTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8858/QNRemoteVideoTrack-iOS) *)videoTrack remoteUserID:(NSString *)userID;
  * 远端用户视频数据首帧渲染会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * videoTrack: [QNRemoteVideoTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8858/QNRemoteVideoTrack-iOS)

远端视频 Track

    * userID: NSString 

用户 ID

didDetachRenderTrack

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didDetachRenderTrack:([QNRemoteVideoTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8858/QNRemoteVideoTrack-iOS) *)videoTrack remoteUserID:(NSString *)userID;
  * 取消渲染远端用户视频数据会触发此回调

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * videoTrack: [QNRemoteVideoTrack](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8858/QNRemoteVideoTrack-iOS)

远端视频 Track

    * userID: NSString 

用户 ID

didMediaRelayStateChanged

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didMediaRelayStateChanged:(NSString *)relayRoom state:([QNMediaRelayState](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/9254))state;
  * 跨房媒体转发状态变更的回调

> 非主动调用触发，由目标房间状态变化引起此通知。目前仅当目标房间关闭
> [QNMediaRelayStateRoomClosed](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/9254)
> 时，会触发此通知。

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * relayRoom: NSString 

目标房间名称

    * state: [QNMediaRelayState](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/9254)

目标房间媒体转发状态

remoteTrackMixedDidGetAudioBuffer

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client remoteTrackMixedDidGetAudioBuffer:(AudioBuffer *)audioBuffer;
  * 远端音频 track mix 数据的回调。

> 该回调在 AU Remote IO 线程，请不要做过于耗时的操作，否则可能阻塞该线程影响音频输出或其他未知问题。

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * audioBuffer: AudioBuffer 

音频数据 buffer

didNetworkQualityNotified

  * \- (void)RTCClient:([QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS) *)client didNetworkQualityNotified:([QNNetworkQuality](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8869/QNNetworkQuality-iOS) *)quality;
  * 本地网络质量信息的回调。

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * quality: [QNNetworkQuality](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8869/QNNetworkQuality-iOS)

上下行的网络质量

didUserVolumeIndication

  * \- (void)RTCClient:(QNRTCClient *)client didUserVolumeIndication:(NSArray<[QNAudioVolumeInfo](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/12589/qnaudiovolumeinfo) *>*)userVolumeList;
  * 用户音量提示回调，本地远端一起回调，本地 user id 为空。

Parameters

    * client: [QNRTCClient](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/8836/QNRTCClient-iOS)

QNRTCClient 实例

    * userVolumeList: NSArray<[QNAudioVolumeInfo](https://developer.qiniu.com/rtc/9248/QNRTCClientDelegate/12589/qnaudiovolumeinfo) *>* 

用户音量信息，按音量由高到低排序

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