Skip to main content
Android
iOS
Web
Electron

Classroom SDK & Proctor SDK

This page introduces how to add Flexible Classroom into your app.

Understand the tech

Module introduction

The source code of Flexible Classroom contains the following packages:

  • app: (Optional) This module contains code for the classroom login interface and a client-side token generator and shows how to call APIs to join a flexible classroom. This module is an open-source project available on GitHub and for reference only.
  • Specifications defined for the login interface (such as the length requirement of the user name and the room name and character restrictions) do not apply to all apps – make sure to define them according to your business requirements.
  • The client-side token generator provided by Agora is only for rapid testing. When your app goes live, to ensure security, you must deploy a server-side token generator and generate tokens on your server. For details, see Secure authentication with tokens.
    • AgoraEduUIKit: (Optional) This module contains code for the classroom UI. It shows how to call APIs to aggregate and update UI data based on Flexible Classroom APIs and data callbacks. This module is an open-source project available on GitHub. You can develop your classroom UI based on this module.
    • AgoraClassSDK: (Optional) This module provides methods to configure the SDK, launch a flexible classroom, register ext apps, and the activity implementation of each teaching scenario. This module is an open-source project available on GitHub. Agora recommends integrating this module.
    • AgoraEduCore: (Required) The core module of Flexible Classroom. Since v2.0.0, this module is closed-source, and you can import this module only by adding a remote dependency.
    • AgoraCloudScene: (Optional) The cloud classroom module of the Flexible Classroom. Depends on the AgoraEduCore cloud classroom UI implementation of the module.

    Integrated education scenario

    If you use the default UI of Flexible Classroom, take the following steps to add remote dependencies and integrate the whole Flexible Classroom through Maven:

    1. Add the following library to your project's build.gradle file:

      repositories {
      maven { url 'https://jitpack.io' }
      google()
      mavenCentral()
      maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
      }
      Copy
    2. Add the following dependencies in the project's build.gradle file to import the following modules: AgoraEduUIKit, AgoraClassSDK, and AgoraEduCore:

      dependencies {
      ...
      implementation "io.github.agoraio-community:AgoraEduCore:{VERSION}"
      implementation "io.github.agoraio-community:AgoraEduUIKit:{VERSION}"
      implementation "io.github.agoraio-community:AgoraClassSDK:{VERSION}"
      }
      Copy

      For example, for v2.8.20:

      dependencies {
      implementation "io.github.agoraio-community:AgoraEduCore:2.8.20"
      implementation "io.github.agoraio-community:AgoraEduUIKit:2.8.20"
      implementation "io.github.agoraio-community:AgoraClassSDK:2.8.20"
      }
      Copy

      To use Flexible Classroom versions equal to or earlier than 2.7.0, also add the hyphenate dependency inside the dependencies block in the project's build.gradle file:

      dependencies {
      ...
      implementation "io.github.agoraio-community:hyphenate:{VERSION}"
      }
      Copy
      Information
      Click here to view the latest version of Flexible Classroom.
    3. After version 2.8.70, the following code needs to be initialized in the Application onCreate method:

      AgoraSDKInitUtils.initSDK(this);
      Copy
    4. To launch a classroom, call AgoraClassroomSDK.launch. Sample code:

      // Before starting the classroom, you need to dynamically apply for `Manifest.permission.RECORD_AUDIO` and `Manifest.permission.CAMERA` permissions
      fun startClassRoom() {
      val appId = "" // Your app ID
      val rtmToken = "" // Your signaling Token
      val userName = "Tom" // Your user name
      val roomName = "MyRoom" // Your room name
      val roomType = RoomType.SMALL_CLASS.value // Class type: 0: One-on-one, 2: Large class, 4: Small class
      val roleType = AgoraEduRoleType.AgoraEduRoleTypeStudent.value // Role: 1: Teacher role, 2: Student role
      val roomUuid = HashUtil.md5(roomName).plus(roomType).lowercase()
      val userUuid = HashUtil.md5(userName).plus(roleType).lowercase()
      val roomRegion = AgoraEduRegion.cn // Area
      val duration = 1800L // Class duration

      val config = AgoraEduLaunchConfig(
      userName,
      userUuid,
      roomName,
      roomUuid,
      roleType,
      roomType,
      rtmToken,
      null,
      duration
      )

      config.appId = appId
      config.region = roomRegion
      // Set large window video area parameters (large stream)
      config.videoEncoderConfig = EduContextVideoEncoderConfig(
      FcrStreamParameters.HeightStream.width,
      FcrStreamParameters.HeightStream.height,
      FcrStreamParameters.HeightStream.frameRate,
      FcrStreamParameters.HeightStream.bitRate
      )

      AgoraClassroomSDK.setConfig(AgoraClassSdkConfig(appId))
      AgoraClassroomSDK.launch(this, config, AgoraEduLaunchCallback { event ->
      Log.e("agora", ":launch-Class status:" + event.name)
      })
      }
      Copy

      You can set the video parameters of the large and small windows by setting FcrStreamParameters, where:

      • Small stream mode: When in the stage area, switch to the small stream mode. This parameter indicates the video parameters in the stage area.
      • Large stream mode: When in the large window area, switch to the large stream mode. This parameter indicates the video parameters in the large window.
      public class FcrStreamParameters {
      // Small stream
      public static class LowStream {
      public static int width = 320;
      public static int height = 240;
      public static int frameRate = 15;
      public static int bitRate = 200;
      }

      // Large stream
      public static class HeightStream {
      public static int width = 640;
      public static int height = 480;
      public static int frameRate = 15;
      public static int bitRate = 600;
      }
      }
      Copy
    5. Set up dark mode

      Because switching to the dark mode requires restarting the Activity, in order to be compatible with all mobile phone models, it is recommended to set the theme directly in Application#onCreate. Refer to the following sample code:

      void setDarkMode() {
      // Add the logic of whether to enable the dark mode here
      boolean isDarkMode = ""
      if (isDarkMode) {
      SkinUtils.INSTANCE.setNightMode(true);
      }
      }
      Copy
    6. To prevent code obfuscation, add the following in the /Gradle Scripts/proguard-rules.pro file:

      -keep class io.agora.**{*;}
      -keep class com.agora.**{*;}
      -keep class com.hyphenate.**{*;}
      Copy

    Integrated cloud classroom

    If you use the default UI of Flexible Classroom Cloud Classroom, take the following steps to add remote dependencies and integrate the whole Flexible Classroom through Maven:

    1. Add the following code to the build.gradle file in the project root directory:

      repositories {
      maven { url 'https://jitpack.io' }
      google()
      mavenCentral()
      maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
      }
      Copy
    2. Add the following dependencies to the build.gradle file in the project root directory. Import AgoraCloudScene and AgoraEduCore module:

      dependencies {
      implementation "io.github.agoraio-community:AgoraEduCore:{VERSION_NUMBER}"
      implementation "io.github.agoraio-community:AgoraCloudScene:{VERSION_NUMBER}"
      }
      Copy

      For example, for version 2.8.70:

      dependencies {
      implementation "io.github.agoraio-community:AgoraEduCore:2.8.70"
      implementation "io.github.agoraio-community:AgoraCloudScene:2.8.70"
      }
      Copy
      Information
      Click here to view the latest version of Flexible Classroom.
    3. In the Application onCreate method, initialize the following:

      AgoraSDKInitUtils.initSDK(this)
      Copy
    4. Call AgoraOnlineClassroomSDK.launch to start the class. The parameters of AgoraOnlineClassroomSDK and AgoraClassroomSDK are the same. Refer to the following sample code:

      // Before starting the classroom, you need to dynamically apply for `Manifest.permission.RECORD_AUDIO` and `Manifest.permission.CAMERA` permissions
      fun startClassRoom() {
      val appId = "" // Your app ID
      val rtmToken = "" // Your signaling Token
      val userName = "Tom" // Your user name
      val roomName = "MyRoom" // Your room name
      val roomType = RoomType.SMALL_CLASS.value // Class type: 4: Small classes
      val roleType = AgoraEduRoleType.AgoraEduRoleTypeStudent.value // The role only supports 2: Student role
      val roomUuid = HashUtil.md5(roomName).plus(roomType).lowercase()
      val userUuid = HashUtil.md5(userName).plus(roleType).lowercase()
      val roomRegion = AgoraEduRegion.cn // Area
      val duration = 1800L // Class duration

      val config = AgoraEduLaunchConfig(
      userName,
      userUuid,
      roomName,
      roomUuid,
      roleType,
      roomType,
      rtmToken,
      null,
      duration
      )

      config.appId = appId
      config.region = roomRegion
      // Set large window video area parameters (large stream)
      config.videoEncoderConfig = EduContextVideoEncoderConfig(
      FcrStreamParameters.HeightStream.width,
      FcrStreamParameters.HeightStream.height,
      FcrStreamParameters.HeightStream.frameRate,
      FcrStreamParameters.HeightStream.bitRate
      )

      AgoraOnlineClassroomSDK.setConfig(AgoraOnlineClassSdkConfig(appId))
      AgoraOnlineClassroomSDK.launch(this, config, AgoraEduLaunchCallback { event ->
      Log.e("agora", ":launch-class status:" + event.name)
      })
      }
      Copy
    5. To prevent code obfuscation, add the following in the /Gradle Scripts/proguard-rules.pro file:

      -keep class io.agora.**{*;}
      -keep class com.agora.**{*;}
      Copy
    Information
    Cloud Classroom does not support dark mode yet.

    Integration considerations

    Third-party libraries

    No matter which method you choose, the third-party libraries Flexible Classroom uses may conflict with the third-party libraries on which your project depends. You can use exclude to resolve this conflict or change the version that your project depends on.

    vundefined