GoChat
  • Overview
  • Demo App
  • SDK Integration
  • Client-Side Implementation
  • GoChat Cloud Service
  • Server APIs
  • Error codes
  • Documentation
  • GoChat
  • GoChat Cloud Service

GoChat Cloud Service

Last updated:2022-03-22 13:06

1 Overview

For an voice chat room app to function properly, apart from building voice chat room 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 you can build such a backend service, ZEGO can provide a sample server-side project for your reference, which has the following features:

  • Creates a new chat room upon user's request (the room creator enters the room automatically).
  • Sends out notifications of room member changes.
  • Supports room members to leave a room halfway through.
  • Supports listeners in a room to raise their hand.
  • Supports the host of a room to invite listeners to speak.
  • Destroys the room on the server side when the room is ended.
  • Configure the maximum number of members and the maximum number of co-hosting members allowed in a room.

You can develop your backend service completely on your own. If you want to use this sample project as a reference, you can contact us to get the sample code.

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

The GoChat backend 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 GoChat backend interfaces do not have built-in authentication. It is recommended that you add your own authentication process.
  • Room names are entered by users and may not be unique, but the GoChat backend will automatically generate a unique room ID for each room.
  • User names are entered by users, and the GoChat backend will ensure that a user name will not be used by different users at the same time and automatically generate a unique user ID for each user. When a user logs out, the corresponding user name record will be deleted from the server.

3 Service Deployment

  1. Deploy Redis, where the status of GoChat rooms and room members (the host, listeners, and guest speakers) will be stored.
  2. Set up the configuration items for Redis, AppID, and AppSecret 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 .

roomRedisAddr = "192.168.100.62:6379" # redis host
roomRedisPassword = ""    # redis password
roomRedisIndex = 8            # redis database


AppId = 1234567890  # The AppID obtained from the Zego Admin Console
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 gochat-server/svr_gochat_room/
./svr_gochat_linux # linux
./svr_gochat_mac # mac os
svr_gochat.exe # win

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

cd gochat-server/svr_gochat_room/;go run main.go

4 Quick Start

4.1 Create a room

Send a create_room request to create and initialize a room on the GoChat backend.

{
    "uid": 100007274,
    "subject":"Science" 
}

Upon successful login, information of the room's default state will be returned, and the client needs to initialize the room based on this information.

 {
    "ret": {
        "code": 0,
        "message": ""  
    },     
    "data": {                
        "room_id": "200113279",
        "subject": "Science",
        "create_time": 1608186550647,
        "creator_name": "shawn",
        "creator_id": 1608186550647,
        "online_count": 1, 
        "on_stage_count": 1                    
    }
}

4.2 Operations for users already in a room

After users logging into a room, they can perform different actions and interact with each other based on their role in the room. Chat room clients can call related GoChat server APIs to realize such user interactions.

4.2.1 Change a user's microphone status or user role

Room members can send a set_user_info request to modify their own microphone status. The room host can also call this API to mute/unmute other users in the room or change their role (from listener to guest speaker or vice versa).

{
    "uid": 9999,
    "room_id": "46466",
    "target_uid": 888,
    "mic": 1,
    "on_stage":2,
    "type":1    
}

4.2.2 Raise hand

Send an operate_raise_hand request to raise hand or lower the raised hand.

{
    "room_id": "200114129",
    "uid": 100007274,
    "type": 1
}

4.2.3 Invite to the stage

The room host can send an invite_onstage request to invite a listener to the speaker stage.

{
    "uid": 9999,
    "room_id": "46466",
    "target_uid": 888
}

4.2.4 Leave the room

Send a quit_room request to leave the current room, and the corresponding user information will be deleted from the room. After the host and all the guest speakers leave the room, the room will be ended automatically.

{
    "uid": 9999,
    "room_id": "46466"
}

4.2.5 End the room

Send a close_room request to end the room, which will also disconnect all room members from the room and then immediately destroy the room.

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