Manage room state
The Interactive Whiteboard SDK provides the state
property in the room
interface to indicate the various states of a room. By reading or modifying the state
property of a room
object, you can change the behavior of the whiteboard or implement custom business logic.
This page describes the different states of an interactive whiteboard room and how to listen for room state changes.
Understand the tech
In an interactive whiteboard room, the state
property includes the following fields:
memberState
: The whiteboard tool currently in use. By modifying thememberState
value of the current room, you can switch the whiteboard tool. See Use Whiteboard Tools.broadcastState
: The view mode of the user, as well as the user ID of the host in the room.cameraState
: The state of the view, including the coordinates of the center, the width and height, and the scale factor of the view.roomMember
.: The information of all the users in interactive mode (those who have read and write permission) in the room.sceneState
: The information of the current scene, including the name, index, and path of the scene. By modifying thesceneState
value of the current room, you can switch the scene. See Manage Scenes.globalState
: The global state of the room. You can useglobalState
to implement custom business logic.
To get the current room states, you can either read the value of each field, or register a callback to listen for their changes.
Prerequisites
To follow the procedure on this page, ensure that you have integrated the Interactive Whiteboard SDK into your project and implemented joining a room. For details, see Join the Whiteboard Room.
The following section extends the Join a Whiteboard Room sample code to show the implementation of getting or listening for room states.
Implement room state management
Read the value of a state
After successfully joining a whiteboard room, to get a room state, you can directly read the corresponding field in the state
property of the room
object.
For example, to get information about the current scene (sceneState
) after joining a room, add the following line to the joinWhiteboard.js
file:
Save the changes, refresh the index.html
page, and open the console of your browser. You can see the following information on the console:
Use callbacks to listen for state changes
The Interactive Whiteboard SDK provides the onRoomStateChanged
method in RoomCallbacks
to report room state changes. You can register this callback when calling joinRoom
to listen for room state changes in real time.
For example, to listen for changes of broadcastState
, you can add the following code to the joinWhiteboard.js
file:
Save the changes, refresh the index.html
page, and open the console of your browser. You can see the following information on the console: