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:
Create a project in ZEGO Admin Console and apply for a valid AppID. For details, please refer to Console - Project Management.
Integrate the ZegoWhiteboardView SDK in the project. For details, please refer to Quick Starts - Integration.
The current product needs to be used with the Real-Time Audio and Video product. And the Web platform features of the Real-Time Audio and Video are not enabled by default. To use related features, you will need to contact ZEGO Technical Support to enable them first.
ZegoWhiteboardView SDK includes ZEGO real-time audio and Video functions, and its initialization method is consistent with ZegoExpress-Video SDK.
Method 1: Download the SDK from the official website, and manually integrate the initialization of the SDK.
<script src="ZegoExpressWhiteboardWeb.js"></script>
/**
* appID is the application ID, please obtain it from the instant management ZEGO Admin Console https://console-express.zego.im/
* server is the address of the access server, please obtain it from the instant management ZEGO Admin Console https://console-express.zego.im/
*/
// Initialize the instance
const zegoExpressEngine = new window.ZegoExpressEngine(appID, server);
Method 2: Use npm to get the SDK initialization.
import {ZegoExpressEngine} from'zego-express-whiteboard-web';
/**
* appID is the application ID, please obtain it from the instant management ZEGO Admin Console https://console-express.zego.im/
* server is the address of the access server, please obtain it from the instant management ZEGO Admin Console https://console-express.zego.im/
*/
// Initialize the instance
const zegoExpressEngine = new ZegoExpressEngine(appID, server);
Call the on method, pass in the name of the monitoring event, and monitor the common callback events:
zegoExpressEngine.on(zegoEventName: ZegoEvent, callBack)
.
ZegoEventName can refer to ZegoEvent.
It is recommended to pay attention to the following events:
//When other users in the room create a new zegoWhiteboardView, they will receive a callback for adding zegoWhiteboardView
zegoExpressEngine.on('viewAdd', function(zegoWhiteboardView){
//Users can add the new zegoWhiteboardView to the view
})
//When other users in the room delete zegoWhiteboardView, they will receive a callback of zegoWhiteboardView removal
zegoExpressEngine.on('viewRemoved', function(whiteboardID){
//Users can remove the corresponding zegoWhiteboardView list maintained by themselves according to the whiteboardID
})
When logging in to a room, you need to pass in a token for user authentication. To obtain the login token, see User privilege control.
To log in to a room, call the loginRoom
with the following parameters:
roomID
parametertoken
parameterroomID
and userName
parameteruserID
must be the same as the one used in token generation.config
parameter based on the actual situation.If the roomID does not exist, a new room will be created and you will log in automatically when you call the loginRoom
method.
// Log in to a room. It returns `true` if the login is successful.
// The roomUserUpdate callback is disabled by default. To receive this callback, you must set the `userUpdate` property to `true` when logging in to a room.
const result = await zg.loginRoom(roomID, token, {userID: userID, userName: userName}, {userUpdate: true});
const zegoWhiteboardView = await zegoExpressEngine.createView({
roomID:'Login room number',
name:'Whiteboard name',
aspectWidth: 1600 * 5,
aspectHeight: 900,
pageCount: 5,
fileInfo?: {
fileID:'File ID',
fileName:'File name',
fileType:'File Type',
authKey:''
}
})
Field | Description | Required |
---|---|---|
roomID | Room ID | Yes |
name | Whiteboard name | Yes |
aspectWidth | Isometric width | Yes |
aspectHeight | isometric height | yes |
pageCount | Whiteboard pages | Yes |
fileInfo | Related file information | No |
FileInfo parameter explanation:
Field | Description | Required |
---|---|---|
fileID | File conversion complete unique ID | Yes |
fileName | File name | Yes |
fileType | File Type | Yes |
authKey | Reserved field | No |
After the creation is successful, other users in the same room will receive the listening callback of viewAdd.
Show ZegoWhiteboardView
Add a container div in Html.
<div id="parent" style="width:1600px;height:900px"> </div>
zegoExpressEngine.attachView(zegoWhiteboardView: ZegoWhiteboardView,parent: string): Promise<void>
zegoWhiteboardView.setWhiteboardOperationMode(operationMode: ZegoWhiteboardOperationMode): void
OperationMode parameter explanation:
Field | Description |
---|---|
1 | Inoperable mode, if mixed with other modes, it is still inoperable mode. |
2 | Scroll mode. In this mode, you can scroll and turn pages and synchronize to other terminals. At this time, it will not be able to respond to manual drawing operations and cannot be mixed with ZegoWhiteboardOperationModeDraw. |
4 | Drawing mode. In this mode, it will respond to primitive drawing operations and synchronize primitives to other ends. It cannot be scrolled and cannot be mixed with ZegoWhiteboardOperationModeScroll. |
8 | Zoom mode, in this mode, you can zoom in on the content of ZegoWhiteboardView. |
Set the tool type and characteristics of the current whiteboard through the setToolType interface. Currently, 10 whiteboard tools are supported.
ZegoWhiteboardViewToolPen // graffiti brush
ZegoWhiteboardViewToolText, // text
ZegoWhiteboardViewToolLine, // straight line
ZegoWhiteboardViewToolRect, // rectangle
ZegoWhiteboardViewToolEllipse, // circle
ZegoWhiteboardViewToolSelector ,// select primitives
ZegoWhiteboardViewToolEraser, // eraser
ZegoWhiteboardViewToolLaser, // Laser pointer
ZegoWhiteboardViewToolClick, // dynamic ppt click tool
ZegoWhiteboardViewToolCustomImage, // Custom graphics tool
// 1. Set the whiteboard tool to pen, pen color, the default is #f54326, pen thickness, the default is 6
zegoWhiteboardView.setToolType(1)
After setting the graffiti brush successfully, press the mouse to graffiti within the range of zegoWhiteboardView, and you can see the graffiti effect displayed on zegoWhiteboardView.
Different users only need to join the same room and get ZegoWhiteboardView list using getViewList, and add ZegoWhiteboardView to the interface, you can observe ZegoWhiteboardView synchronization with location.
// 1. After joining the same room, request a list of whiteboards in the room
var zegoWhiteboardViewList = []
zegoExpressEngine.getViewList().then(res=>{
zegoWhiteboardViewList = res
})
// 2. Suppose that the user entering the room needs to load the designated whiteboard, the ID of the whiteboard is 1
var targetWhiteboardID = 1
// 3. According to the filter criteria, filter the target whiteboard from the whiteboard list
zegoWhiteboardView = zegoWhiteboardViewList.filter(function (v) {
return targetWhiteboardID === v.getID();
})[0];
// 4. Render the target whiteboard
zegoExpressEngine.attachView(zegoWhiteboardView, parentId)
As long as the user remains logged in, the ZegoWhiteboardView SDK will automatically synchronize the content and scroll position on the zegoWhiteboardView, and the users in the room will see the same content, and the developer does not need to do additional operations.
Call scroll method to make ZegoWhiteboardView scroll to the corresponding location.
zegoWhiteboardView.scroll(horizontalPercent: number,verticalPercent: number): boolean
Call destroyView interface to remove the whiteboard. After the removal is successful, users in the same room will receive the callback of viewRemoved
.
zegoExpressEngine.destroyView(zegoWhiteboardView: ZegoWhiteboardView): Promise<void>
zegoExpressEngine.on('viewRemoved', function(whiteboardID){
//Users can remove the corresponding zegoWhiteboardView list maintained by themselves according to the whiteboardID
})
Please refer to 3.1 Initialize ZegoWhiteboardView 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 monitoring callbacks of ZegoWhiteboardView SDK, so as to achieve interactive collaboration.
Call getViewList interface to get the whiteboard list.
zegoExpressEngine.getViewList(): Promise<ZegoWhiteboardView[]>
Developers can follow the monitoring callbacks when adding and deleting whiteboards as needed.
//When other users in the room create a new zegoWhiteboardView, they will receive a callback for adding zegoWhiteboardView
zegoExpressEngine.on('viewAdd', function(zegoWhiteboardView){
//Users can add the new zegoWhiteboardView to the view
})
//When other users in the room delete zegoWhiteboardView, they will receive a callback of zegoWhiteboardView removal
zegoExpressEngine.on('viewRemoved
', function(whiteboardID){
//Users can remove the corresponding zegoWhiteboardView list maintained by themselves according to the whiteboardID
})
Developers can experience the Collaborative Whiteboard business in the Collaborative Whiteboard sample project, and view the complete source code and code logic. For details, please refer to Collaborative Whiteboard - Sample Codes.