GoClass
  • iOS : Objective-C
  • Android
  • Web
  • Electron
  • Overview
  • Demo App
  • Sample Codes
  • SDK Integration
  • Small Classes Implementation
  • Large Classes Implementation
  • GoClass Backend Service
  • Error Codes
  • Documentation
  • GoClass
  • GoClass Backend Service

GoClass Backend Service

Last updated:2022-03-22 13:06

1 Overview

For an online classroom app to function properly, apart from building classroom features into your app clients with ZEGO's SDKs, you will also need a backend service for server-side processing such as room management and room-related signaling. To demonstrate how to build such a backend service, ZEGO provides a sample server-side project for your reference, which has the following features:

  • Create a classroom automatically upon the first login to the classroom.
  • Send out notifications of any changes to the members in the classroom.
  • Allow students and teachers to leave the classroom in the middle of a class.
  • Allow teachers to end a class, which will also destroy the related classroom object.
  • Support teachers to manage students' sharing permissions.
  • Configure the maximum number of members and the maximum number of co-hosting members allowed in a classroom.

You can develop your backend service completely on your own. If you want to use this sample project as a reference, see Sample codes for details about how to download and run the sample code for both the client side and server side (they work together).

While you may adapt the sample code into your project, ZEGO will not be responsible for the deployment to your testing/production environments and any subsequent maintenance. Also, make sure you perform sufficient tests to avoid any potential production issues.

2 Technical Introduction

GoClass backend service is developed in Go language based on the open-source HTTP framework beego. The current version uses Redis to store data and allows you to scale out your service on demand.

  • Currently, all the interfaces do not have built-in authentication. It is recommended that you add your own authentication process.
  • Room IDs can be entered by users. If the specified room does not exist yet, it will be created automatically. If it already exists, then the user can be admitted into the room according to the business logic.
  • User IDs should be generated by the client application and must be unique across the application to ensure that there will be no user ID conflicts in any classroom.

3 Service Deployment

  1. Deploy Redis, where the status of the classrooms, teachers, and students will be stored.

  2. Set up the configuration items for Redis, App Id, and App Secret in the file app.conf as demonstrated below.

Please visit ZEGO Admin Console to register a ZEGO account and create a project to get a ZEGO AppID and ServerSecret. For the detailed instructions, please refer to Project Management.

RedisAddr = "192.168.100.62:6379" # redis host
RedisPassword = "" # redis password
RedisIndex = 8 # redis database

[SmallClass] # Configurations related to small classes
AppId = 1234567890
AppSecret = "eb2280544902dc1b7ab1fde3985bd083" # The ServerSecret obtained from the Zego Admin Console

[LargeClass] # Configurations related to large classes.
AppId = 1234567890
AppSecret = "eb2280544902dc1b7ab1fde3985bd083" # The ServerSecret obtained from Zego Admin Console
  1. Go to the source code directory and run the executable file of the corresponding system.
cd edu_room
./edu_room_linux # Linux
./edu_room_mac # macOS
edu_room.exe # Windows

Or, you can install the Go development environment and then run the following commands:

cd edu_room;go run main.go

4 Quick Start

4.1 Log in to a Classroom

Call the API login_room to log in to a classroom. If the classroom with the specified room_id does not exist yet, it will be created and initialized automatically. If it already exists, the user will enter the specified classroom. All users who log in with the same room_id will be in the same class. The client application needs to ensure the uniqueness of the uid, which is used by the GoClass back-end service to identify a user.

{
  "uid":171171717,
  "room_id":"123456",
  "nick_name":"Shawn",
  "role":2,
  "room_type":2
}

Upon successful login, the default status and configuration items of the classroom, as well as the user's status information, will be returned. The client application needs to initialize the classroom and user status based on the returned information.

{
  "ret": {
    "code": 0,
    "message": "succeed"
  },
  "data": {
    "max_join_live_num": 4,
    "room_id": "123456",
    "default_camera_state": 2,
    "default_mic_state": 2,
    "allow_turn_on_camera": 2,
    "allow_turn_on_mic": 2,
    "uid": 171171717,
    "nick_name": "Shawn",
    "role": 1,
    "login_time": 1600920322511,
    "camera": 1,
    "mic": 1,
    "can_share": 2
  }
}

4.2 Operations During a Class

During a class, the teacher and students may need to change their own audio/video device status or leave in the middle of the class, and the teacher will need to manage students' audio/video device status, sharing permissions, and end the class at the end of the class or for other reasons. You can use the following APIs to realize all these features.

4.2.1 Change Device Status and Sharing Permission

Call set_user_info to change a user's audio/video device status and sharing permission. Teachers can change students’ equipment status and sharing permission by calling this API.

{
  "uid":171171717,
  "room_id":"123456",
  "room_type": 2,
  "target_uid":171171717,
  "mic":2,
  "camera":2,
  "can_share":2
}

4.2.2 Leave the Classroom

Call leave_room to leave the classroom, and the related user status information will be deleted. When all users have left the classroom, it will be automatically destroyed 15 minutes later.

{
  "uid":171171717,
  "room_id":"123456",
  "room_type": 2
}

4.2.3 End the Class

Call end_teaching to end the class, which will log out all users currently in the classroom and then immediately destroy the classroom.

{
  "uid":171171717,
  "room_id":"123456",
  "room_type": 2
}
Page Directory