ZEGOCLOUD no longer classifies environments into production environments and testing environments.
If you create your project in ZEGOCLOUD Admin Console on/before 2021-11-16, refer to the Testing environment deprecation to upgrade the SDK and adjust related codes.
This article is divided into two parts to introduce the ZegoWhiteboardView SDK:
You must first ensure that the initialization of ZegoExpress-Video SDK|_blank is successful, and then initialize ZegoWhiteboardView SDK.
Initialize ZegoExpress-Video SDK. For details, please refer to ZegoExpress - Quick starts - 3 Implementation steps.
/** Define a ZegoExpressEngine object */
ZegoExpressEngine engine;
ZegoEngineProfile profile = new ZegoEngineProfile();
/** Use the AppID and AppSign assigned by ZEGO when you create your project in the ZEGO Admin Console. */
/** AppID format: 123456789L */
profile.appID = appID;
/** AppSign format: "0123456789012345678901234567890123456789012345678901234567890123"(64 characters)*/
profile.appSign = appSign;
/** General scenario */
profile.scenario = ZegoScenario.GENERAL;
/** Set application object of App */
profile.application = getApplication();
/** Create a ZegoExpressEngine instance */
engine = ZegoExpressEngine.createEngine(profile, null);
If the errorCode in the callback onInit is 0, it means the initialization is successful and more operations can be performed. For errorCode, please refer to Common Error Codes.
ZegoWhiteboardManager.getInstance().init(context, new IZegoWhiteboardInitListener() {
@Override
public void onInit(int errorCode) {
if (errorCode == 0) {
/** Initialization successful */
} else {
/** Initialization failure */
}
}
});
Call the setup listener of ZegoWhiteboardManager to monitor common whiteboard events: setWhiteboardManagerListener(IZegoWhiteboardManagerListener listener).
Contains the following events:
//Error callback in the process of using whiteboard
//For detailed error codes, see ZegoWhiteboardConstants.java
void onError(int errorCode);
//Whiteboard operation permission change callback
//This permission is used to control the operation of the whiteboard, including zooming and scrolling
void onWhiteboardAuthChanged(HashMap<String,Integer> authInfo) {}
//Graphic element operation permission change callback
//Primitive operation permissions include create, delete, move, update, and clear all primitives
void onWhiteboardGraphicAuthChanged(HashMap<String,Integer> authInfo) {}
//When other users in the room create a new ZegoWhiteboardView, they will receive a callback for adding ZegoWhiteboardView
//Users can add the new whiteboardView to the view
void onWhiteboardAdded(ZegoWhiteboardView zegoWhiteboardView);
//When other users in the room delete ZegoWhiteboardView, they will receive a callback for the removal of ZegoWhiteboardView
//Users can remove the corresponding ZegoWhiteboardView according to the whiteboardID
void onWhiteboardRemoved(long whiteboardID);
For details of the error code, please refer to Login Room Error Code.
/** Create user */
ZegoUser user = new ZegoUser("user1");
/** Start to log in to the room */
engine.loginRoom("room1", user);
//Create a whiteboard model
ZegoWhiteboardViewModel zegoWhiteboardViewModel = new ZegoWhiteboardViewModel();
zegoWhiteboardViewModel.setAspectHeight(9); // The equal height of the whiteboard you want to create
zegoWhiteboardViewModel.setAspectWidth(16 * 5); // The equal width of the whiteboard you want to create, if you need to create a multi-page whiteboard, you need to multiply it by the corresponding multiple
zegoWhiteboardViewModel.setName("Whiteboard 1");
zegoWhiteboardViewModel.setPageCount(5); // The number of whiteboard pages
zegoWhiteboardViewModel.setRoomId("123");
ZegoWhiteboardManager.getInstance().createWhiteboardView(zegoWhiteboardViewModel, new IZegoWhiteboardCreateListener() {
@Override
public void onCreate(int errorCode, @Nullable ZegoWhiteboardView whiteboardView) {
}
});
if (errorCode == 0 && zegoWhiteboardView != null) {
addView(zegoWhiteboardView,LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
)
}
currentWhiteboardView.setWhiteboardOperationMode(ZegoWhiteboardConstants.ZegoWhiteboardOperationModeDraw)
ZegoWhiteboardViewToolNone, // not selected
ZegoWhiteboardViewToolPen, // graffiti brush
ZegoWhiteboardViewToolText, // text
ZegoWhiteboardViewToolLine, // straight line
ZegoWhiteboardViewToolRect, // rectangle
ZegoWhiteboardViewToolEllipse, // circle
ZegoWhiteboardViewToolSelector, // select primitive
ZegoWhiteboardViewToolEraser, // eraser
ZegoWhiteboardViewToolLaser, // Laser pointer
ZegoWhiteboardViewToolClick, // click
ZegoWhiteboardViewToolCustomImage, // custom graphics
int toolType = ZegoWhiteboardConstants.ZegoWhiteboardViewToolPen;
int color = Color.RED;
int size = 4;
/** Set the type of brush*/
ZegoWhiteboardManager.getInstance().setToolType(toolType);
/** Set the color of the pen*/
ZegoWhiteboardManager.getInstance().setBrushColor(color);
/** Set the size of the brush*/
ZegoWhiteboardManager.getInstance().setBrushSize(size);
After setting the graffiti brush successfully, press and move your finger within the range of whiteboardView to see the graffiti effect displayed on the whiteboardView.
Different users only need to join the same room and get ZegoWhiteboardView, and add ZegoWhiteboardView to the interface, you can observe ZegoWhiteboardView Location synchronization.
As long as the user remains logged in, the ZegoWhiteboardView SDK will automatically synchronize the content and scrolling position on ZegoWhiteboardView, and users in the room will see the same content. Development There is no need for additional operations.
Call scrollTo method to make ZegoWhiteboardView scroll to the corresponding position.
/** Whiteboard scroll */
float horizontalPercent = 1.0f;
float verticalPercent = 1.0f;
zegoWhiteboardView.scrollTo(horizontalPercent, verticalPercent);
Call destroyWhiteboardView method of ZegoWhiteboardManager class to remove the whiteboard.
After the removal is successful, users in the same room will receive a callback notification of onWhiteboardRemoved
.
long whiteboardID = 1;
ZegoWhiteboardManager.getInstance().destroyWhiteboardView(whiteboardID, new IZegoWhiteboardDestroyListener() {
@Override
public void onDestroy(int errorCode, long whiteboardID) {
if (errorCode == 0) {
/** The whiteboard was destroyed successfully*/
} else {
/** Failed to destroy the whiteboard*/
}
}
});
Please refer to 3.1 Initialize SDK and 3.2 Login Room to initialize ZegoWhiteboardView SDK and log in to the room.
Different users need to join the same room to receive various callbacks from ZegoWhiteboardView SDK to achieve interactive collaboration.
Call getWhiteboardViewList of ZegoWhiteboardManager interface to get the ZegoWhiteboardView list created in the room. The user can directly add the obtained ZegoWhiteboardView to the interface for display, and the user can use getWhiteboardViewModel property to get whiteboard information.
//Get the list of ZegoWhiteboardView created in the room
ZegoWhiteboardManager.getInstance().getWhiteboardViewList(new IZegoWhiteboardGetListListener() {
@Override
public void onGetList(int errorCode, ZegoWhiteboardView[] whiteboardViewList) {
if (errorCode == 0) {
/** Successfully obtained */
} else {
/** Get failed */
}
}
});
Developers can follow the callbacks when adding and deleting whiteboards as needed. Before paying attention to the callback, you must ensure that the method of ZegoWhiteboardManager is set: setWhiteboardManagerListener
.
ZegoWhiteboardManager.getInstance().setWhiteboardManagerListener(new IZegoWhiteboardManagerListener() {
@Override
public void onError(int errorCode) {
}
@Override
public void onWhiteboardAdded(ZegoWhiteboardView zegoWhiteboardView) {
addView(zegoWhiteboardView,LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT))
}
@Override
public void onWhiteboardRemoved(long whiteboardID) {
}
});
ZegoWhiteboardManager.getInstance().setWhiteboardManagerListener(new IZegoWhiteboardManagerListener() {
@Override
public void onError(int errorCode) {
}
@Override
public void onWhiteboardAdded(ZegoWhiteboardView zegoWhiteboardView) {
}
@Override
public void onWhiteboardRemoved(long whiteboardID) {
removeView(getWhiteboardViewHolder(whiteboardID))
}
});
Developers can experience the interactive whiteboard business in the interactive whiteboard sample project, and view the complete source code and code logic. For details, please refer to Collaborative Whiteboard - Sample Codes.