Skip to main content

Integrate Flexible Classroom

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

Understand the tech

The following figure shows the overall technical architecture of Flexible Classroom:

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.
    • hyphenate: (Optional) The UI and logic of the chat feature implemented with the Hyphenate IM SDK. It is not required to import this module if you implement the chat feature on your own and let AgoraEduUIkit rewrite the code related to the class message chat function in the module.

    Module relations

    • AgoraEduCore is the required core module, and all the other modules depend on it.
    • Both AgoraEduUIKit and AgoraClassSDK depend on AgoraEduCore, and there is no dependency between them.
    • AgoraEduUIKit depends on hyphenate.
    • hyphenate depends on AgoraEduCore.
    • app depends on all other modules.

    Integrate Flexible Classroom through Maven

    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:


      _6
      repositories {
      _6
      maven { url 'https://jitpack.io' }
      _6
      google()
      _6
      mavenCentral()
      _6
      maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' }
      _6
      }

    2. Add the following dependencies in the project's build.gradle file to import four modules: AgoraEduUIKit, AgoraClassSDK, AgoraEduCore, and hyphenate:


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

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


      _4
      dependencies {
      _4
      ...
      _4
      implementation "io.github.agoraio-community:hyphenate:{VERSION}"
      _4
      }

      Use the Maven repository search to find the latest version for each dependency. For example, type io.github.agoraio-community:AgoraClassSDK in the search box to find the latest version of the AgoraClassSDK module.

    3. To launch a classroom, call AgoraClassroomSDK.setConfig and AgoraClassroomSDK.launch. Sample code:


      _31
      fun startClassRoom() {
      _31
      val appId = "" // Your app ID
      _31
      val rtmToken = "" // Your signaling Token
      _31
      val streamState = AgoraEduStreamState(videoState = 1, audioState = 1)
      _31
      _31
      val config = AgoraEduLaunchConfig(
      _31
      "xiaoming", // The user name
      _31
      "xiaoming2", // The user ID
      _31
      "agoraclass", // The room name
      _31
      "agoraclass4", // The room ID
      _31
      2, // The user's role in the class, 2: Student
      _31
      4, // The room type, 0: One-to-one interactive teaching, 2: Big class, 4: Online interactive small class
      _31
      rtmToken, // The RTM Token used for authentication
      _31
      System.currentTimeMillis(), // Starting time of the class
      _31
      1800L, // The class duration
      _31
      AgoraEduRegion.na, // The area
      _31
      null, // The video encoder configuration
      _31
      null, // Media stream-related settings
      _31
      streamState, // Control whether students automatically send audio or video streams after they go to the podium
      _31
      AgoraEduLatencyLevel.AgoraEduLatencyLevelUltraLow, // Viewer latency level
      _31
      null, // User properties defined by the developer
      _31
      null // Agora widget configuration
      _31
      )
      _31
      _31
      config.appId = appId
      _31
      config.uiMode = AgoraEduUIMode.LIGHT // The class interface display mode, AgoraEduUIMode.LIGHT: Bright mode, AgoraEduUIMode.DARK: Dark mode
      _31
      AgoraClassSDK.setConfig(AgoraClassSdkConfig(appId))
      _31
      AgoraClassSDK.launch(this, config, AgoraEduLaunchCallback { event ->
      _31
      Log.e(TAG, ":launch-Classroom State:" + event.name)
      _31
      })
      _31
      }

    4. To prevent code obfuscation, add the following in the /Gradle Scripts/proguard-rules.pro file:


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

    See also

    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