Whiteboard SDK quickstart
Updated
Build a basic Interactive Whiteboard app with the Whiteboard SDK.
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 Whiteboard SDK to implement basic whiteboard features.
Understand the tech
The following figure shows the workflow to join an Interactive Whiteboard room.
Interactive Whiteboard room joining workflow
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 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
Project setup
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
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.whiteboard">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.WhiteBoard">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>Get Whiteboard SDK
dependencies {
implementation 'com.github.netless-io:whiteboard-android:<version>'
}You can find the latest SDK version number in the Release Notes.
Prevent code obfuscation
-keep class com.herewhite.** { *; }Create a room
Call the Interactive Whiteboard RESTful API on your app server to create a room. See Create a room (POST).
var request = require("request");
var options = {
"method": "POST",
"url": "https://api.netless.link/v5/rooms",
"headers": {
"token": "Your SDK Token",
"Content-Type": "application/json",
"region": "us-sv"
},
body: JSON.stringify({
"isRecord": false
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});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.
- Use code. See Generate a Token from your app server. Recommended.
- Call the Interactive Whiteboard RESTful API. See Generate a Room Token (POST).
var request = require('request');
var options = {
"method": "POST",
"url": "https://api.netless.link/v5/tokens/rooms/<Room UUID>",
"headers": {
"token": "Your SDK Token",
"Content-Type": "application/json",
"region": "us-sv"
},
body: JSON.stringify({"lifespan":3600000,"role":"admin"})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});Create user interface and join the whiteboard room
package com.example.whiteboard;
public class MainActivity extends AppCompatActivity {
final String appId = "Your App Identifier";
final String uuid = "Room UUID";
final String roomToken = "Room Token";
final String uid = "User uid";
WhiteboardView whiteboardView;
WhiteSdkConfiguration sdkConfiguration = new WhiteSdkConfiguration(appId, true);
RoomParams roomParams = new RoomParams(uuid, roomToken, uid);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
whiteboardView = findViewById(R.id.white);
sdkConfiguration.setRegion(Region.us);
WhiteSdk whiteSdk = new WhiteSdk(whiteboardView, MainActivity.this, sdkConfiguration);
whiteSdk.joinRoom(roomParams, new Promise<Room>() {
@Override
public void then(Room wRoom) {
MemberState memberState = new MemberState();
memberState.setCurrentApplianceName("pencil");
memberState.setStrokeColor(new int[]{255, 0, 0});
wRoom.setMemberState(memberState);
}
@Override
public void catchEx(SDKError t) {
Object o = t.getMessage();
Log.i("showToast", o.toString());
Toast.makeText(MainActivity.this, o.toString(), Toast.LENGTH_SHORT).show();
}
});
}
}Reference
Build the project in Android Studio, and run it on a simulator or a physical mobile device.
