Whiteboard SDK quickstart
Interactive Whiteboard rooms enable users to present ideas, share multi-media content, and collaborate on projects on a shared whiteboard from multiple devices simultaneously.
This article describes how to create a basic project and use the Interactive Whiteboard SDK to implement basic whiteboard features.
Understand the tech
The following figure shows the workflow to join an Interactive Whiteboard room.
When an app client requests to join an Interactive Whiteboard room, the app client and your app server interact with the Interactive Whiteboard server in the following steps:
- The app server sends a request with the SDK token to the Interactive Whiteboard server to create a whiteboard room.
- The Interactive Whiteboard server returns the room UUID to the app server when a room is created successfully.
- The app server generates a room token using the returned room UUID and sends the room token and UUID to the app client.
- The app client initializes a Interactive Whiteboard SDK instance with the App Identifier received from the Agora Console.
- The app client calls a method to join the Interactive Whiteboard room using the room UUID and room token.
Prerequisites
- Android Studio
- Android API level 19 or higher
- A valid Agora account
- An Agora project with the Interactive Whiteboard enabled. Get the app identifier and SDK token from the Agora Console. See Enable and configure Interactive Whiteboard
Create an Android project
Create a project in Android Studio.
- Set the project name as
WhiteBoard
. - Set the package name as
com.example.whiteboard
. - Select Empty Activity.
- Select API 19 for Minimum SDK.
Add Android device permission
Refer to the following code to add Internet access permission in the AndroidManifest.xml
file:
Get Interactive Whiteboard SDK
Open the build.gradle
file in the app folder of the Android project, and add the following lines:
You can find the latest SDK version number in the Release Notes.
Prevent code obfuscation
Add the following lines to the proguard-rules.pro
file:
Implement whiteboard features
Interactive Whiteboard SDK has now been integrated into the Android project. Next, call the core APIs in the SDK to implement basic whiteboard features.
1. Create a room
Before an app client requests to join a room, you need to call the Interactive Whiteboard RESTful API on your app server to create a room. See Create a room (POST).
Request example
Refer to the following Node.js script to send an HTTP request:
request
module. You can run the command line npm install request
to install the module.If the request is successful, Agora's server for the Interactive Whiteboard returns information about the created room, including the uuid
, which is the unique identifier of the room. You need to pass in this parameter when an app client joins the room.
Response example
2. Generate a Room Token
After creating a room and getting the uuid
of the room, you need to generate a Room Token on your app server and send it to the app client. When an app client joins a room, Agora's server uses the Room Token for authentication.
To generate a Room Token on your app server, you can:
- Use code. See Generate a Token from your app server. (Recommended)
- Call the Interactive Whiteboard RESTful API. See Generate a Room Token (POST).
The following examples describe how to use the Interactive Whiteboard RESTful API to generate a Room Token.
Request example
Refer to the following Node.js script to send an HTTP request:
Before sending an HTTP request using Node.js, make sure that you have installed the request
module. You can run the command line npm install request
to install the module.
If the request is successful, Agora's server returns a Room Token.
Response example
3. Create user interface
Refer to the following code sample to modify the activity_main.xml
file. After modification, you should see a whiteboard page named com.herewhite.sdk.WhiteboardView
, which is implemented by the Interactive Whiteboard SDK.
4. Initialize the Interactive Whiteboard SDK and join a room
Edit the MainActivity.java
file to implement the steps from initializing the Interactive Whiteboard SDK to joining a room. You need to pass in the following parameters:
appId
: The App Identifier of the Interactive Whiteboard project in Agora Console. See Get security credentials for your Interactive Whiteboard project.uuid
: The Room UUID, the unique identifier of a whiteboard room. See Create a room.uid
: The unique identifier of a user in the string format. The maximum length is 1024 bytes. If you use v2.15.0 and later versions, you must pass in this parameter; if you use versions earlier than v2.15.0, do not pass in this parameter.roomToken
: The Room Token used for authentication. The Room Token must be generated using the Room UUID above. See Generate a Room Token.region
: The data center, which must be the same as the data center you chose when creating the room.
Build and run the project
Build the project in Android Studio, and run it on a simulator or a physical mobile device. If the project runs successfully, you can see a new page and use your mouse to write and draw on the page.
Reference
We provide an open-source sample project Whiteboard-Android that implements the whiteboard room on GitHub. You can download the sample project and refer to the source code.