
# 房间功能
 #### joinRoom
```
virtual int joinRoom(const HRTCJoinParam &joinParam)
```
【**功能说明**】
加入房间。该方法让用户加入通话房间。
【**请求参数**】
joinParam：入会参数。具体请参见[HRTCJoinParam](https://support.huaweicloud.com/csdk-rtc/rtc_05_0128.html#rtc_05_0128__section11398133002711)。
【**返回参数**】
- 0：方法调用成功。
- \>0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
会触发以下回调：
- [onConnectStateChange](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section106922242518)：连接状态发送改变。
- [onJoinRoomSuccess](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section1319832102216)：加入房间成功。
- [onJoinRoomFailure](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section1184221016238)：加入房间失败。
- [onRemoteUserOnline](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__section422052222412)：远端用户收到当前用户加入房间的通知。
音频的自动订阅策略设置只在音频订阅模式下生效。
 #### leaveRoom
```
virtual int leaveRoom()
```
【**功能说明**】
离开房间。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
会触发以下回调：
- [onLeaveRoom](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section18952103711231)：离开房间回调。
- [onConnectStateChange](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section106922242518)：连接状态改变回调。
- [onRemoteUserOffline](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section166775422416)：远端用户收到当前用户离开房间的通知。
 
 #### renewAuthorization
```
virtual int renewAuthorization(const char* signature, long long ctime)
```
【**功能说明**】
鉴权签名过期，收到[onAuthorizationExpired](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section9566994582)签名鉴权过期回调后，更新鉴权签名。
【**请求参数**】
- signature：鉴权签名字符串。
- ctime：过期时间。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
 #### changeUserRole
```
virtual int changeUserRole(HRTCRoleType role, const char *authorization, long long ctime)
```
【**功能说明**】
设置用户在当前房间内的角色类型，角色切换时使用。
【**请求参数**】
- role：用户角色类型，joiner类型和player类型，具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。

- authorization：预留参数，填null。
- ctime：预留参数，填0。
【**返回参数**】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 加入房间前，可以通过joinRoom的userRole参数确认角色信息。
- 加入指定房间后才可以在指定房间内进行角色切换，当前仅支持joiner和player角色切换。跨房场景下，通过对应connection连接下的changeUserRole接口实现在跨入房间中的角色类型切换。
- 切换成功触发[onUserRoleChangedNotify](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__section9263123615018)回调。切换失败会触发[onError](https://support.huaweicloud.com/csdk-rtc/rtc_05_0115.html#rtc_05_0115__zh-cn_topic_0000001162260659_section07911946101112)回调，返回HRTC_ERR_CODE_USER_ROLE_CHANGE_FAIL错误码。
- 同一时间不同房间最多只能有一个joiner，player切换joiner的时候，需要将其他房间的joiner先切换成player。
- 不支持缺省用户昵称入会。
 
 #### changeUserName
```
virtual int changeUserName(const char* userName)
```
【**功能说明**】
房间内设置用户自己的昵称。
【**请求参数**】
userName：变更的昵称。
【**返回参数** 】
- 0：方法调用成功。
- \> 0：方法调用失败。具体请参见[HRTCErrorCode](https://support.huaweicloud.com/csdk-rtc/rtc_05_0125.html)。
 
![](https://support.huaweicloud.com/csdk-rtc/public_sys-resources/caution_3.0-zh-cn.png)
- 该接口仅支持房间内调用，更改的昵称会被实时同步到房间内其他用户的用户列表，退出房间不会保存，再次加入房间变更为加入房间时设置的昵称（参考[joinRoom]接口注意事项）。
- 会触发以下回调： onUserNameChangedNotify：用户名变更的通知。
  
 
