
# 事件回调(IHRTCConnectionEventHandler)
本章节介绍了Android SDK的回调接口IHRTCConnectionEventHandler的详情。
表1回调接口 
| 接口                                                                      | 描述                |
|:---|:---|
| [onError]                           | 错误回调              |
| [onJoinRoomSuccess]                | 加入房间成功回调          |
| [onJoinRoomFailure]                  | 加入房间失败回调          |
| [onRejoinRoomSuccess]               | 重新加入房间回调          |
| [onLeaveRoom]                        | 离开房间回调            |
| [onRemoteUserOnline]               | 用户加入房间回调          |
| [onRemoteUserOffline]                | 用户离开房间回调          |
| [onConnectionChangedNotify]         | 网络连接状态改变回调        |
| [onRemoteVideoStateChangedNotify]    | 远端视频流状态变化回调       |
| [onRemoteAudioStateChangedNotify]  | 远端音频流状态变化回调       |
| [onUserRoleChangedNotify]           | 用户角色改变回调          |
| [onUserVolumeStatsNotify]           | 提示频道远端用户以及自己的音量回调 |
| [onUserAuxiliaryStreamAvailable]    | 辅流加入房间回调          |
| [onVideoStatsNotify]                | 视频流详情，2s触发一次回调    |
| [onAudioStatsNotify]                | 音频流详情，2s触发一次回调    |
| [onAuxiliaryStreamStatsNotify]       | 辅流详情，2s触发一次回调     |
| [onFirstRemoteVideoDecoded]        | 远端用户第一帧解码成功通知     |
| [onFirstRemoteAuxiliaryStreamDecoded] | 远端用户辅流第一帧解码成功通知   |
| [onRemoteUserNameChangedNotify]      | 远端用户昵称变更通知        |
| [onUserNameChangedNotify]           | 本端修改昵称结果通知        |
| [onAuthorizationExpired]           | 签名过期回调            |
| [onMediaConnectStateChangedNotify]  | 媒体连接状态变化通知        |
| [onRenderSuccessNotify]             | 用户视频流渲染成功通知回调     |
| [onMediaStreamRecvPktNotify]         | 订阅的用户视频流收包信息回调    |
| [onNetworkQualityNotify]           | 加入房间后的网络质量状态回调    |
| [onRemoteVideoStatsNotify]           | 远端视频统计回调          |
| [onRemoteAudioStatsNotify]          | 远端音频统计回调          |
| [onVideoResolutionChangedNotify]    | 远端视频大小流改变回调       |
| [onStatsNotify]                     | 当前会话统计回调          |
| [onStartPublishStream]             | 开始旁路（RTMP）推流回调    |
| [onUpdateTransCoding]                 | 更新旁路（RTMP）推流消息    |
| [onStopPublishStream]              | 停止旁路（RTMP）推流消息    |
| [onStreamPublishStateChange]         | RTMP推流状态回调        |
| [onTopActiveSpeaker]                | 远端音频最活跃用户回调       |
| [onRemoteMicrophoneStateChanged]     | 远端麦克风设备状态变更通知     |
   
 #### onError
```
void onError(HRTCConnection conn, int error, String msg);
```
【**功能说明**】
错误回调。
【**回调参数** 】
- conn：回调对应的HRTCConnection实例。
- error：错误码，具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0035.html)。
- msg：错误描述。
 
 #### onJoinRoomSuccess
```
void onJoinRoomSuccess(HRTCConnection conn, String userId);
```
【**功能说明**】
成功加入房间回调。
【**回调参数** 】
- conn：回调对应的HRTCConnection实例。
- roomId：房间ID。
- userId：用户ID。
 
 #### onJoinRoomFailure
```
void onJoinRoomFailure(HRTCConnection conn, int error, String msg);
```
【**功能说明**】
加入房间失败回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- error：错误码。
- msg：错误信息。
 
 #### onLeaveRoom
```
void onLeaveRoom(HRTCConnection conn, HRTCLeaveReason reason, HRTCStatsInfo statsInfo);
```
【**功能说明**】
离开房间回调。
【**回调参数** 】
- conn：回调对应的HRTCConnection实例。
- reason：自己离开房间的原因，具体请参见[HRTCLeaveReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section207822774414)。
- statsInfo：会议期间的统计信息，具体请参见[HRTCStatsInfo](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section451795725415)。
 
 #### onRemoteUserOnline
```
void onRemoteUserOnline(HRTCConnection conn, String userId, String userName);
```
【**功能说明**】
用户加入房间成功回调，不包括自己。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- userId：用户ID。
- userName：用户名称。
 
 #### onRemoteUserOffline
```
void onRemoteUserOffline(HRTCConnection conn, String userId, int reason);
```
【**功能说明**】
用户离开房间回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- userId：用户ID。
- reason：预留字段。
 
 #### onConnectionChangedNotify
```
void onConnectionChangedNotify(HRTCConnection conn, HRTCConnStateTypes connStateTypes, HRTCConnChangeReason connChangeReason, String description);
```
【**功能说明**】
网络连接状态改变。
【**回调参数** 】
- conn：回调对应的HRTCConnection实例。
- connStateTypes：网络连接状态，具体请参见[HRTCConnStateTypes](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section1143012526423)。
- connChangeReason：网络连接状态原因，具体请参见[HRTCConnChangeReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section17275040104313)。
- description：描述。
 
 #### onUserRoleChangedNotify
```
void onUserRoleChangedNotify(HRTCConnection conn, HRTCRoleType oldRole, HRTCRoleType newRole);
```
【**功能说明**】
用户角色改变。
【**回调参数** 】
- conn：回调对应的HRTCConnection实例。
- oldRole：改变前的角色，具体请参见[HRTCRoleType](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section1130451518425)。
- newRole：改变后的角色，具体请参见[HRTCRoleType](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section1130451518425)。
 
#### onAudioRouteStateChangedNotify
```
void onAudioRouteStateChangedNotify(HRTCConnection conn, HRTCAudioRoute route);
```
【**功能说明**】
音频路由改变。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- route：音频路由，具体请参见[HRTCAudioRoute](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section18630124994113)。
 
 #### onUserAuxiliaryStreamAvailable
```
void onUserAuxiliaryStreamAvailable(HRTCConnection conn, String userId, boolean available);
```
【**功能说明**】
辅流加入房间。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- userId：用户ID。
- available：true为辅流开始推送，false为辅流停止推送。
 
 #### onVideoStatsNotify
```
void onVideoStatsNotify(HRTCConnection conn, List<HRTCLocalVideoStats> localStats, List<HRTCRemoteVideoStats> remoteStats);
```
【**功能说明**】
视频流详情，2s触发一次回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- localStats：本地视频发流详情参数，具体请参见[HRTCLocalVideoStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section10761129182318)。
- remoteStats：远端视频收流详情参数，具体请参见[HRTCRemoteVideoStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section34941520192413)。
 
 #### onAudioStatsNotify
```
void onAudioStatsNotify(HRTCConnection conn, List<HRTCLocalAudioStats> localStats, List<HRTCRemoteAudioStats> remoteStats);
```
【**功能说明**】
音频流详情，2s触发一次回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- localStats：本地音频发流详情，具体请参见[HRTCLocalAudioStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section17479113842318)。
- remoteStats：远端音频收流详情，具体请参见[HRTCRemoteAudioStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section1986482818245)。
 
 #### onAuxiliaryStreamStatsNotify
```
void onAuxiliaryStreamStatsNotify(HRTCConnection conn, List<HRTCLocalVideoStats> localStats, List<HRTCRemoteVideoStats> remoteStats);
```
【**功能说明**】
辅流详情，2s触发一次回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- localStats：本地辅流的发流详情，具体请参见[HRTCLocalVideoStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section10761129182318)。
- remoteStats：远端辅流的收流详情，具体请参见[HRTCRemoteVideoStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section34941520192413)。
 
 #### onRemoteAudioStateChangedNotify
```
void onRemoteAudioStateChangedNotify(HRTCConnection conn, String userId, HRTCRemoteAudioStreamState state, HRTCRemoteAudioStreamStateReason reason);
```
【**功能说明**】
远端音频流状态变化回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- userId：远端用户ID。
- state：远端音频流状态，具体请参见[HRTCRemoteAudioStreamState](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section1037761017453)。
- reason：远端音频流状态变化原因，具体请参见[HRTCRemoteAudioStreamStateReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section1272173884515)。
 
 #### onRemoteVideoStateChangedNotify
```
void onRemoteVideoStateChangedNotify(HRTCConnection conn, String userId, HRTCRemoteVideoStreamState state, HRTCRemoteVideoStreamStateReason reason);
```
【**功能说明**】
远端视频流状态变化回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- userId：远端用户ID。
- state：远端视频流状态，具体请参见[HRTCRemoteVideoStreamState](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section8616181318312)。
- reason：远端视频流状态变化原因，具体请参见[HRTCRemoteVideoStreamStateReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section163781283461)。
 
 #### onRejoinRoomSuccess
```
void onRejoinRoomSuccess(HRTCConnection conn, String userId);
```
【**功能说明**】
重新加入房间回调。例如网络异常后重连成功加入房间时触发。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- userId：用户ID。
 
 #### onUserVolumeStatsNotify
```
void onUserVolumeStatsNotify(HRTCConnection conn, List<HRTCVolumeInfo> volumeInfos, int totalVolume);
```
【**功能说明**】
提示频道远端用户以及自己的音量回调。
【**回调参数** 】
- conn：回调对应的HRTCConnection实例。
- volumeInfos：回调发言人信息列表，目前最多支持4人，包括自己，具体请参见[HRTCVolumeInfo](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section8783112315148)。
- totalVolume：远端混音后的总音量。
 
 #### onFirstRemoteVideoDecoded
```
void onFirstRemoteVideoDecoded(HRTCConnection conn, String userId, int width, int height);
```
【**功能说明**】
远端用户第一帧解码成功回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- userId：用户ID。
- width：视频宽度。
- height：视频高度。
 
 #### onFirstRemoteAuxiliaryStreamDecoded
```
void onFirstRemoteAuxiliaryStreamDecoded(HRTCConnection conn, String roomId, String userId, int width, int height);
```
【**功能说明**】
接收到第一帧远端辅流并解码成功，触发此回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- roomId：视频流对应的房间ID。
- userId：视频流对应的用户ID。
- width：视频流宽。
- height：视频流高。
 
 #### onAuthorizationExpired
```
void onAuthorizationExpired(HRTCConnection conn);
```
【**功能说明**】
签名过期回调，需要app调用renewAuthorization更新签名。
【**回调参数**】
conn：回调对应的HRTCConnection实例。
 #### onRenderSuccessNotify
```
void onRenderSuccessNotify(HRTCConnection conn, String userId, boolean isAux);
```
【**功能说明**】
用户视频流渲染成功通知回调。首帧渲染成功、分辨率变化或视频流中断后恢复触发。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- userId：用户ID。
- isAux：是否辅流。true为是辅流，false为不是辅流。
 
 #### onMediaStreamRecvPktNotify
```
void onMediaStreamRecvPktNotify(HRTCConnection conn, List<HRTCStreamPacketInfo> streamPacketInfoList);
```
【**功能说明**】
订阅的用户视频流收包信息回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- streamPacketInfoList：订阅的用户视频流收包信息，具体请参见[HRTCStreamPacketInfo](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section43836933319)。
 
 #### onNetworkQualityNotify
```
void onNetworkQualityNotify(HRTCConnection conn, List<HRTCQualityInfo> upStreamQuality, List<HRTCQualityInfo> downStreamQuality);
```
【**功能说明**】
加入房间后，基于流级别的网络质量状态回调，音频流、视频流分开回调。
【**回调参数**】
- 当远端订阅本端时（本端开始推流），本端才会开始收到网络质量回调。
- conn：回调对应的HRTCConnection实例。
- upStreamQuality：上行网络质量状态，具体请参见[HRTCQualityInfo](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section1275219474393)。当前不可用。
- downStreamQuality：下行网络质量状态，具体请参见[HRTCQualityInfo](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section1275219474393)。
 
 #### onMediaConnectStateChangedNotify
```
void onMediaConnectStateChangedNotify(HRTCConnection conn, HRTCMediaConnStateTypes state, HRTCMediaConnChangeReason reason, String description);
```
【**功能说明**】
媒体服务器连接状态变更通知。加入房间过后，收到媒体服务的数据包时，返回Connected消息，超过6s没有收到包，则返回Failed消息。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- state：连接状态，具体请参见[HRTCMediaConnStateTypes](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section171141341155620)。
- reason：连接状态变化的原因，具体请参见[HRTCMediaConnChangeReason](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section545124317564)。
- description：连接状态变化原因描述。
 
 #### onUserNameChangedNotify
```
void onUserNameChangedNotify(HRTCConnection conn, String oldUserName, String newUserName);
```
【**功能说明**】
调用changeUserName接口成功后，上报此事件通知修改昵称结果。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- oldUserName：修改前的昵称。
- newUserName：修改后的昵称。
 
 #### onRemoteUserNameChangedNotify
```
void onRemoteUserNameChangedNotify(HRTCConnection conn, String userId, String userName);
```
【**功能说明**】
远端用户修改昵称后，通知本端昵称变更。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- userId：修改昵称的用户id。
- userName：修改后的昵称。
 
 #### onRemoteVideoStatsNotify
```
void onRemoteVideoStatsNotify(HRTCConnection conn, List<HRTCRemoteVideoStats> remoteStats);
```
【**功能说明**】
远端视频流详情，2s触发一次回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- remoteStats：远端视频收流详情参数，具体请参见[HRTCRemoteVideoStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section34941520192413)。
 
 #### onRemoteAudioStatsNotify
```
void onRemoteAudioStatsNotify(HRTCConnection conn, List<HRTCRemoteAudioStats> remoteStats);
```
【**功能说明**】
远端音频流详情，2s触发一次回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- remoteStats：远端音频收流详情，具体请参见[HRTCRemoteAudioStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section1986482818245)。
 
 #### onVideoResolutionChangedNotify
```
void onVideoResolutionChangedNotify(HRTCConnection conn, String userid, int width, int height);
```
【**功能说明**】
远端视频大小改变回调。
【**回调参数**】
- conn：回调对应的HRTCConnection实例。
- userId：用户ID。
- width：视频流宽度。
- height：视频流高度。
 
 #### onStatsNotify
```
void onStatsNotify(HRTCConnection conn,List<HRTCOnStats> hrtcOnStats);
```
【**功能说明**】
当前会话统计回调。
【**回调参数** 】
- conn：回调对应的HRTCConnection实例。
- hrtcOnStats：会话统计信息，具体请参见[HRTCOnStats](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section1852195962619)。
 
 #### onStartPublishStream
```
void onStartPublishStream(HRTCConnection conn,int code, const char* taskId);
```
【**功能说明**】
开始旁路（RTMP）推流回调。
【**回调参数** 】
- conn：回调对应的HRTCConnection实例。
- code：错误码，0表示成功，非0请参见[错误码](https://support.huaweicloud.com/csdk-rtc/rtc_05_0035.html)。
- taskId：任务Id。
 
 #### onUpdateTransCoding
```
void onUpdateTransCoding(HRTCConnection conn,int code, const char* taskId);
```
【**功能说明**】
更新旁路（RTMP）推流回调。
【**回调参数** 】
- conn：回调对应的HRTCConnection实例。
- code：错误码，0表示成功，非0请参见[错误码](https://support.huaweicloud.com/csdk-rtc/rtc_05_0035.html)。
- taskId：任务Id。
 
 #### onStopPublishStream
```
void onStopPublishStream(HRTCConnection conn,int code, const char* taskId);
```
【**功能说明**】
停止旁路（RTMP）推流回调。
【**回调参数** 】
- conn：回调对应的HRTCConnection实例。
- code：错误码，0表示成功，非0请参见[错误码](https://support.huaweicloud.com/csdk-rtc/rtc_05_0035.html)。
- taskId：任务Id。
 
 #### onStreamPublishStateChange
```
void onStreamPublishStateChange(HRTCConnection conn,int code, const char* taskId, const HRTCUrlStatusList * urlStatus);
```
【**功能说明**】
RTMP推流状态回调。
【**回调参数** 】
- conn：回调对应的HRTCConnection实例。
- code：错误码，0表示成功，非0请参见[错误码](https://support.huaweicloud.com/csdk-rtc/rtc_05_0035.html)。
- taskId：任务Id。
- urlStatus：推流的url结果结构体，具体请参见[HRTCUrlStatusList](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section20558625443)。
 
 #### onTopActiveSpeaker
```
public void onTopActiveSpeaker(HRTCConnection conn, String userId, boolean noStream);
```
【**功能说明**】
上报当前最活跃的用户userId。该回调主要用于0号会场场景（额外订阅uid为0的用户音频）。
【**回调参数**】
userId：返回当前远端音量最活跃的用户ID。
noStream：该用户是否有视频流。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
0号会场模式下，SDK会持续监测（根据一定时间内用户音量大小）当前最活跃的用户，如果最活跃用户发生变化，则触发此回调并上报当前最活跃的用户userId。
 #### onRemoteMicrophoneStateChanged
```
void onRemoteMicrophoneStateChanged(HRTCConnection conn, String userId, HRTCRemoteMicState state);
```
【**功能说明**】
远端麦克风设备状态变更回调。
【**回调参数**】
- conn: 连接对象。
- userId：用户id。
- state：麦克风设备状态，具体请参见[HRTCRemoteMicState](https://support.huaweicloud.com/csdk-rtc/rtc_05_0037.html#rtc_05_0037__section13309133309)。
 
#### onRemoteShareStatusChangeNotify
```
void onRemoteShareStatusChangeNotify(HRTCConnection conn, String userId, boolean isRecving)
```
【**功能说明**】
上报下行辅流状态变化通知，接收端探测网络变化，分配给下行辅流，如果有辅流因为带宽不足被停掉或者带宽恢复而恢复，则上报给产品。
【**回调参数**】
conn: 连接对象。
userId：下行辅流对应的用户ID。
isRecving：是否接受。
