Entering And Exiting A Room & Room Information
A brief overview of entering a room
Regular Room: You need to create the room in the backend first, obtain the Room ID, and then call the joinRoom method to enter the room.
Instant Room: There is no need to create the room in the backend first. You can directly call the joinRoomEx interface and pass in the Room ID to enter the room.Note: When joining a room using the token method, the Room ID must be consistent with the Room ID used when generating the token.
If a user ID is provided in roomParams, the SDK will use the provided userId. If no user ID is provided, the SDK will automatically generate a userId.Note: When joining a room using the token method, the user ID must be consistent with the user ID used when generating the token.
- About the Process and Callbacks for Joining a Room:
After calling the joinRoom interface, the SDK enters the process of joining the room:
Check Room: The SDK checks the room, verifying information such as the Room ID and user password. Upon success, you can obtain the basic information of the room and the basic information of the users;
Config Room: Room configuration. Upon success, you can obtain the room’s link IP address and the document server address;
Connect Socket: Establish a socket connection based on the obtained link IP address;
join Room: After successfully establishing the socket connection, the process of entering the room begins, and room information is returned (including the number of people in the room, room messages, published stream information, etc.).
Callback:
Process Callback: During this process, the user will receive the onError(int errorCode, String errMsg) or onWarning(int warning) delegate callbacks. Based on the warning code or error code returned in the delegate callback, you can understand whether each step has succeeded or failed.
Join Room Callback: After successfully entering the room, there is a -(void)onRoomJoined callback
joinRoom
- A brief description-the interface for joining a regular room
1.You need to create the room in the backend first, obtain the Room ID, and then call this interface to enter the room.
2.The appId is required. Before calling this interface, you need to call the init method and pass the appId in it.
- (int)joinRoom(RoomParams roomParams, UserParams userParams)
Parameter Name |
Required |
Type |
Description |
roomParams |
Yes |
RroomParams |
The basic parameters required for the room are detailed in the Related Extended Fields and the joinRoom definition. |
userParams |
Yes |
UserParams |
The basic parameters required for the user are detailed in the Related Extended Fields and the joinRoom definition. |
| RoomParams roomParams = new RoomParams();
roomParams.setPassword(RoomVariable.password);
roomParams.setRoomId(RoomVariable.serial);
roomParams.setHost(RoomVariable.host);
UserParams userParams = new UserParams();
userParams.setUserRole(userrole);
userParams.setUserId(RoomVariable.userid);
userParams.setNickname(RoomVariable.nickname);
TKRoomManager.getInstance().joinRoom(roomParams, userParams);
|
Type |
Description |
int |
0: Indicates successful invocation; Non-zero: Indicates invocation failure |
joinRoomEx
- A brief description-joining an instant room
1.There is no need to create a room in the backend. You can directly pass in the Room ID and then enter the room. After calling the interface, the backend will create a room using the provided Room ID.
2.An appId is required. Before calling this interface, you must first call init and pass in the appId.
3.A token is required. Before calling this interface, you need to generate a token and pass it into the RoomParams object. The generation rule is shown in the example below.
- (int)joinRoomEx(roomParams, userParams)
Parameter Name |
Required |
Type |
Description |
roomParams |
Yes |
RroomParams |
The basic parameters required for the room are detailed in the Related Extended Fields and the joinRoom definition. |
userParams |
Yes |
UserParams |
The basic parameters required for the user are detailed in the Related Extended Fields and the joinRoom definition. |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | RoomParams roomParams = new RoomParams();
UserParams userParams = new UserParams();
String thirdRoomid = "1122334455"; //第三方房间Id Third-party Room ID
String domain = "appId" ; //企业域名 Enterprise Domain
String authkey = "authkey"; //企业key Enterprise key
String userId = "22223333";
String ts = String.valueOf(new Date().getTime());
long expireTs = 3600; //房间过期时间 Room Expiration Time
String originalText = "appId=" + domain + "&thirdRoomId=" + account + "&userId=" + userId + "&ts=" + ts + "&expireTs=" + expireTs;
SecretKey restoredKey = AESUtil.getKeyFromString(authkey);
String token = AESUtil.encrypt(originalText, restoredKey,authkey);
roomParams.setTkToken(token);
roomParams.setThirdRoomId(thirdRoomid);
userParams.setUserId(userId);
TKRoomManager.getInstance().joinRoomEx(roomParams,userParams);
|
Type |
Description |
int |
0: Indicates successful invocation; Non-zero: Indicates invocation failure |
leaveRoom
- A brief description of exiting the classroom
After calling the interface, both I and other users in the room will receive corresponding callbacks. 1. I will receive a callback for leaving the room: -(void)onRoomLeaved. 2. Other users in the room will receive a callback that I have left the room: -(void)onUserLeft(RoomUser user).
- (int)leaveRoom()
Parameter Name |
Required |
Type |
Description |
None |
|
|
|
| int ret =TKRoomManager.getInstance().leaveRoom();
|
Type |
Description |
int |
0: Indicates successful invocation; Non-zero: Indicates invocation failure |
getRoomProperties
- A brief description-getting room attributes
This interface should be called after the joinRoom interface to obtain valid results. It returns all information related to the room, such as Room ID, room type, and configuration items. Configuration items refer to whether the room has enabled teaching assistance features, such as automatic class dismissal, quiz tools, and other interactive teaching functions.
- JSONObject getRoomProperties();
| jsonObject = TKRoomManager.getInstance().getRoomProperties();
|
Type |
Description |
JSONObject |
A dictionary containing room-related information |
getUser
- A brief description-obtaining a user based on a user ID
RoomUser is a user object class that stores information related to the user. This interface should be called after the joinRoom interface to obtain valid results.
- RoomUser getUser(String peerId)
Parameter Name |
Required |
Type |
Description |
peerId |
Yes |
String |
User ID |
| RoomUser roomUser = TKRoomManager.getInstance().getUser(peerId);
|
Type |
Description |
RoomUser |
If there is a user with this user ID in the room, it returns the RoomUser user object; otherwise, it returns null |
getServiceList
- A brief description of obtaining a server list
This can be used to switch connection servers. It should be called after the joinRoom interface to obtain valid results.
- getServiceList(TKRoomManagerObserver.OnGetServerListener listener)
| TKRoomManager.getInstance().getServiceList(new OnGetServerListener);
|
Type |
Description |
onResult(List list) |
If there are available servers, it returns a List collection object; otherwise, it returns null. |
getStreamStatus
- A brief description-obtaining the user’s uplink audio and video statistics data
Obtain the uplink audio and video network statistics data for a specific user, including packet loss, latency, bandwidth, and other statistical information. This interface should be called after the joinRoom interface to obtain valid results. After a successful call, you will receive a successful callback function: -(void)onGetStreamStatus(int errorCode, JSONObject streamStates).
- (void)getStreamStatus(String[] userIds)
Parameter Name |
Required |
Type |
Description |
peerId |
Yes |
String |
User ID Array |
| TKRoomManager.getInstance().getStreamStatus(null);
|
Type |
Description |
int |
0: Indicates successful invocation; Non-zero: Indicates invocation failure |