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:
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.
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.
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
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
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
}
}
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.
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
}
Send an operate_raise_hand request to raise hand or lower the raised hand.
{
"room_id": "200114129",
"uid": 100007274,
"type": 1
}
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
}
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"
}
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"
}