joinRoom method
- NSString token,
- ByteRTCUserInfo userInfo,
- BOOL userVisibility,
- ByteRTCRoomConfig roomConfig,
@detail api
@author shenpengliang
@brief 加入 RTC 房间。
调用 createRTCRoom:{@link #ByteRTCEngine#createRTCRoom} 创建房间后,调用此方法加入房间,同房间内其他用户进行音视频通话。
@param token 动态密钥,用于对进房用户进行鉴权验证。
进入房间需要携带 Token。测试时可使用控制台生成临时 Token,正式上线需要使用密钥 SDK 在你的服务端生成并下发 Token。Token 有效期及生成方式参看使用 Token 完成鉴权。
使用不同 AppID 的 App 是不能互通的。
请务必保证生成 Token 使用的 AppID 和创建引擎时使用的 AppID 相同,否则会导致加入房间失败。
@param userInfo 用户信息。参看 ByteRTCUserInfo{@link #ByteRTCUserInfo}。
@param userVisibility 用户可见性。建议在进房时将用户可见性都设置为 false,并在用户需要发送音视频流时再通过 setUserVisibility:{@link #ByteRTCRoom#setUserVisibility} 设置为 true。从而避免因房间内用户达到数量上限所导致的进房失败。默认情况下,一个 RTC 房间最多同时容纳 50 名可见用户,其中最多 30 人可同时上麦,更多信息参看用户和媒体流上限。
@param roomConfig 房间参数配置,设置房间模式以及是否自动发布或订阅流。具体配置模式参看 ByteRTCRoomConfig{@link #ByteRTCRoomConfig}。
@return 方法调用结果。
- 0: 成功。触发以下回调:
- 本端收到房间状态通知 rtcRoom:onRoomStateChanged:withUid:state:extraInfo:{@link #ByteRTCRoomDelegate#rtcRoom:onRoomStateChanged:withUid:state:extraInfo} 回调。
- 本端收到本地流发布状态通知 rtcRoom:onVideoPublishStateChanged:info:state:reason:{@link #ByteRTCRoomDelegate#rtcRoom:onVideoPublishStateChanged:info:state:reason}、rtcRoom:onAudioPublishStateChanged:info:state:reason:{@link #ByteRTCRoomDelegate#rtcRoom:onAudioPublishStateChanged:info:state:reason}。
- 本端收到流订阅状态通知 rtcRoom:onVideoSubscribeStateChanged:info:state:reason:{@link #ByteRTCRoomDelegate#rtcRoom:onVideoSubscribeStateChanged:info:state:reason}、rtcRoom:onAudioSubscribeStateChanged:info:state:reason:{@link #ByteRTCRoomDelegate#rtcRoom:onAudioSubscribeStateChanged:info:state:reason}。
- 本端收到房间内已发布流的通知 rtcRoom:onUserPublishStreamVideo:info:isPublish:{@link #ByteRTCRoomDelegate#rtcRoom:onUserPublishStreamVideo:info:isPublish}、rtcRoom:onUserPublishStreamAudio:info:isPublish:{@link #ByteRTCRoomDelegate#rtcRoom:onUserPublishStreamAudio:info:isPublish}。
- 如果本端用户为可见用户,房间内其他用户收到 rtcRoom:onUserJoined:{@link #ByteRTCRoomDelegate#rtcRoom:onUserJoined} 回调通知。
- -1: 参数无效
- -2: 已经在房间内。接口调用成功后,只要收到返回值为 0 ,且未调用 leaveRoom{@link #ByteRTCRoom#leaveRoom} 成功,则再次调用进房接口时,无论填写的房间 ID 和用户 ID 是否重复,均触发此返回值。
调用失败时,具体失败原因会通过 rtcRoom:onRoomStateChanged:withUid:state:extraInfo:{@link #ByteRTCRoomDelegate#rtcRoom:onRoomStateChanged:withUid:state:extraInfo} 回调告知。
@note
- 同一个 AppID 的同一个房间内,每个用户的用户 ID 必须是唯一的。如果两个用户的用户 ID 相同,则后加入房间的用户会将先加入房间的用户踢出房间,并且先加入房间的用户会收到 rtcRoom:onRoomStateChanged:withUid:state:extraInfo:{@link #ByteRTCRoomDelegate#rtcRoom:onRoomStateChanged:withUid:state:extraInfo} 回调通知,错误类型为重复登录 ByteRTCErrorCodeDuplicateLogin。
- 本地用户调用此方法加入房间成功后,会收到 rtcRoom:onRoomStateChanged:withUid:state:extraInfo:{@link #ByteRTCRoomDelegate#rtcRoom:onRoomStateChanged:withUid:state:extraInfo} 回调通知。若本地用户同时为可见用户,加入房间时远端用户会收到 rtcRoom:onUserJoined:{@link #ByteRTCRoomDelegate#rtcRoom:onUserJoined} 回调通知。
- 房间内不可见用户的容量远远大于可见用户,而且用户默认可见,因此对于不参与互动的用户,你需要调用 setUserVisibility:{@link #ByteRTCRoom#setUserVisibility} 更改为不可见用户。从而避免因房间内用户达到数量上限所导致的进房失败。默认情况下,一个 RTC 房间最多同时容纳 50 名可见用户,其中最多 30 人可同时上麦,更多信息参看用户和媒体流上限。
- 用户加入房间成功后,在本地网络状况不佳的情况下,SDK 可能会与服务器失去连接,并触发 rtcEngine:onConnectionStateChanged:{@link #ByteRTCEngineDelegate#rtcEngine:onConnectionStateChanged} 回调。此时 SDK 会自动重试,直到成功重连。重连成功后,本地会收到 rtcRoom:onRoomStateChanged:withUid:state:extraInfo:{@link #ByteRTCRoomDelegate#rtcRoom:onRoomStateChanged:withUid:state:extraInfo}。
Implementation
FutureOr<int> joinRoom(NSString token, ByteRTCUserInfo userInfo,
BOOL userVisibility, ByteRTCRoomConfig roomConfig) async {
return await nativeCall('joinRoom:userInfo:userVisibility:roomConfig:',
[token, userInfo, userVisibility, roomConfig]);
}