Agora offers a growing number of RESTful APIs for extending the features of live voice and video applications. This includes Cloud Recording, Real-Time Transcription, and RTMP integrations.
To make using these RESTful APIs from your infrastructure easier, Agora’s developer community has released the open-source project, Agora Middleware Service. This Go-based backend provides a set of RESTful APIs for token generation, cloud recording management, and real-time transcription. It simplifies integrating features that require Agora’s cloud services into your existing real-time voice and video applications.
The project serves two primary purposes:
Using this middleware, developers can offload complex and time-consuming server-side builds and focus on delivering great user experiences in their real-time applications.
Key features of the middleware include:
Let’s dive into setting up and using this powerful tool!
Before you begin, make sure you have the following:
To get started with the Agora Middleware Service, first clone the repo:
git clone https://github.com/AgoraIO-Community/agora-go-backend-middleware.git
Navigate to the project directory:
cd agora-go-backend-middleware
Install the required dependencies:
go mod download
A properly configured environment is crucial for the middleware to function. To set up your environment, first copy the example environment file:
cp .env.example .env
Then, open the .env
file in your favorite text editor and fill in the required values:
APP_ID=your_agora_app_id
APP_CERTIFICATE=your_agora_app_certificate
CUSTOMER_ID=your_customer_id
CUSTOMER_SECRET=your_customer_secret
CORS_ALLOW_ORIGIN=*
SERVER_PORT=8080
STORAGE_VENDOR=
STORAGE_REGION=
STORAGE_BUCKET=
STORAGE_BUCKET_ACCESS_KEY=
STORAGE_BUCKET_SECRET_KEY=
# Agora Endpoint Config (default)
AGORA_BASE_URL=https://api.agora.io/
AGORA_CLOUD_RECORDING_URL=v1/apps/{appId}/cloud_recording
AGORA_RTT_URL=v1/projects/{appId}/rtsc/speech-to-text
AGORA_RTMP_URL=v1/projects/{appId}/rtmp-converters
AGORA_CLOUD_PLAYER_URL=v1/projects/{appId}/cloud-player
Now that you’ve configured the service, it’s time to run it. We have a few options.
Using Go:
go run cmd/main.go
Using Docker and Make:
make build
make run
If everything is set up correctly, you should see the output in your console indicating that the server is running on http://localhost:8080
(unless you've specified a different port in the .env
file).
The middleware service exposes endpoints for Token Generation, Agora Cloud Recording, Agora Real-Time Transcription, and Agora’s RTMP (Push & Pull) services. Let’s explore each set of endpoints and how to use them.
The Token Generation API allows you to create access tokens for audio and video streams on Agora’s network. These tokens are essential for authenticating users and maintaining the security of your application.
Endpoint: POST /token/getNew
You can generate tokens for:
Check out examples using cURL commands to generate tokens.
The Cloud Recording API provides endpoints for managing cloud recording sessions. This includes starting and stopping recordings, updating layouts, and getting the status of recording resources.
Key endpoints:
POST /cloud_recording/start
POST /cloud_recording/stop
GET /cloud_recording/status
POST /cloud_recording/update/layout
Check out examples using cURL commands to manage cloud recordings.
The Real-Time Transcription (RTT) API allows developers to control transcription sessions, enabling speech-to-text conversions and translations in real-time during Agora calls.
Key endpoints:
POST /rtt/start
POST /rtt/stop/:taskId
GET /rtt/status/:taskId
Check out examples using cURL commands to manage real-time transcription sessions.
The RTMP (Real-Time Messaging Protocol) Service provides APIs for managing RTMP push and pull operations. This allows developers to stream media to 3rd party streaming services that use RTMP and to pull streams into Agora channels from CDN storage or other RTMP-based broadcasts.
RTMP Push, also known as RTMP converter enables streaming content from an Agora channel to an RTMP destination.
Key endpoints:
POST /rtmp/push/start
POST /rtmp/push/stop
POST /rtmp/push/update
GET /rtmp/push/list
RTMP Pull, also referred to as Cloud Player, pulls RTMP streams into an Agora channel.
Key endpoints:
POST /rtmp/pull/start
POST /rtmp/pull/stop
POST /rtmp/pull/update
GET /rtmp/pull/list
Check out examples using cURL commands to manage RTMP converters and cloud players.
Both RTMP Push and Pull services support various configuration options for audio and video, allowing fine-tuned control over the streaming process. Remember to handle the responses appropriately in your application to manage the RTMP sessions effectively.
With the service running, it’s time to test it and ensure it’s working correctly. To test the APIs you can use the cURL commands above or with tools like Bruno or Postman. We’ve prepared a comprehensive set of examples for each service.
Remember to replace localhost:8080
with the appropriate address if your service is running on a different host or port. Also, make sure to update any placeholder values (like channel names, UIDs, etc.) with real values that match your testing environment.
To make the most of the Agora Middleware Service, consider the following best practices:
If you encounter issues while setting up or using the middleware service, try the following:
.env
configuration to ensure all values are correct.If you need further assistance or have questions about the Agora Middleware Service, you have several options:
The Agora team is here to help and support our community succeed in building amazing real-time communication applications.
Happy coding, and we can’t wait to see what you’ll build with Agora!