You can get the current state of the room as follows
When the room is initialized, the corresponding method is passed in. When the state of the room changes, the SDK will actively call the corresponding method to notify the developer that the state of the room has changed.
In calling the joinRoom
method of WhiteSDK
, in the roomCallbacks
parameter, pass in an instance that implements the RoomCallbacks
interface, or AbstractRoomCallbacks
, the latter can override the callback method of interest.
public interface RoomCallbacks {
/** Room network connection status callback event */
void onPhaseChanged(RoomPhase phase);
void onBeingAbleToCommitChange(boolean isAbleToCommit);
/** Whiteboard loses connection callback, with error message */
void onDisconnectWithError(Exception e);
/** The user was kicked out of the room by the remote server, with the reason for the kick out */
void onKickedWithReason(String reason);
/**
When the RoomState property in the room changes, the callback will be triggered.
Note: The actively set RoomState will not trigger this callback.
@param modifyState changed RoomState content
*/
void onRoomStateChanged(RoomState modifyState);
/** User error event capture, with user id and error reason */
void onCatchErrorWhenAppendFrame(long userId, Exception error);
}
Call the createPlayer
method of WhiteSdk, the playerEventListener
parameter, and pass in the instance that implements the PlayerEventListener
interface.
/**
* Playback status switch callback
*/
void onPhaseChanged(PlayerPhase phase);
/**
* First frame loading callback
*/
void onLoadFirstFrame();
/**
* Shard switching callback, need to understand the sharding mechanism. No practical use at present
*/
void onSliceChanged(String slice);
/**
* Callback when the status changes during playback
*/
void onPlayerStateChanged(PlayerState modifyState);
/**
* Error pause
*/
void onStoppedWithError(SDKError error);
/**
* Progress time changes
*/
void onScheduleTimeChanged(long time);
/**
* Error adding frame
*/
void onCatchErrorWhenAppendFrame(SDKError error);
/**
* An error occurred during rendering
*/
void onCatchErrorWhenRender(SDKError error);
}
APIs for actively obtaining room status are divided into asynchronous APIs and synchronous APIs.
Only the synchronous API is introduced here. The corresponding asynchronous API can be viewed through the notes of the synchronous API, so I won't go into details here.
//Currently globalState is empty and there is no more current state content.
GlobalState globalState = room.getGlobalState();
//Get the memberState of the room: teaching aids
MemberState memberState = room.getMemberState();
//Get the user's current perspective status
BroadcastState broadcastState = room.getBroadcastState();
//Get room member information
RoomMember[] roomMembers = room.getRoomMembers();
//Get the SceneState page information of the room, see SceneState class for details
SceneState sceneState = room.getSceneState();
//Get all Scene page information in the current scene directory of the room
Scene scenes = room.getScenes();
/**
* Get room status
* Currently: the initial state is WhitePlayerPhaseWaitingFirstFrame
* When WhitePlayerPhaseWaitingFirstFrame is called, the return value of calling getPlayerStateWithResult may be empty.
*/
public PlayerPhase getPhase();
/**
* When the phase state is WhitePlayerPhaseWaitingFirstFrame
* The data obtained by the callback is empty
*/
public PlayerState getPlayerState()
/**
* Get player information (current duration, total duration, start UTC time stamp)
* The unit of duration is milliseconds
*/
public void getPlayerTimeInfo(final Promise<PlayerTimeInfo> promise) {
Actively acquiring the room status is actually the SDK monitoring the room status changes through the previous API, and then merge the changed status with the cached status attributes. This is convenient for users to call.
If you use an API that can change the state of the room in the same code block (replace teaching aids, switch pages, etc.), you can check the synchronization API immediately, and you will find that the state has not changed. This is because the states need to be merged in the next main thread loop. In this case, please use the asynchronous API.
2.4.7 New API
The globalState
property in the real-time room state is a public readable and writable state for all customers; the playback room state globalState
is a read-only property, and the modification will not take effect. If the custom event is to synchronize a custom behavior, then globalState
is used to synchronize a custom state.
2.0 version always set custom
globalState
state.setGlobalState:
API, pass in a customglobalState
subclass to pass the customized content to other users in the room.
Developers can call the setCustomGlobalStateClass
class method in WhiteDisplayerState
to set custom globalState
properties globally.
public class WhiteDisplayerState extends WhiteObject {
/**
* Set the custom global variable type. After setting, all GlobalState will be converted to instances of this class.
*
* @param <T> type constraints
* @param classOfT custom GlobalState Class
* @since 2.4.7
* example
*/
public static <T extends GlobalState> void setCustomGlobalStateClass(Class<T> classOfT);
}
Sample code:
/** Set a custom global state, and in the subsequent callbacks, GlobalState can directly perform type conversion */
WhiteDisplayerState.setCustomGlobalStateClass(MyGlobalState.class);
After passing in the developer-defined GlobalState
subclass, RoomState
and PlayerState
will automatically deserialize the content into this subclass when deserializing globalState
.
After setting the custom
globalState
, no additional operations are required. You only need to perform the corresponding type coercion when using the original API.