Quickstart
Updated
Build a basic voice calling, video calling, or streaming app with the Agora RTC SDK.
This page provides a step-by-step guide on how to create a basic real-time app using the Agora RTC SDK. The same steps apply whether you're building voice calling, video calling, interactive live streaming, or broadcast streaming — only a few configuration values change based on your use case.
Understand the tech
To start a real-time session, implement the following steps in your app:
-
Initialize the engine: Before calling other APIs, create and initialize an engine instance.
-
Join a channel: Call methods to create and join a channel.
-
Join as a host: A live streaming event has one or more hosts. A host publishes audio and video to the channel and can also subscribe to streams from other hosts.
-
Join as audience: Audience members can only subscribe to streams published by hosts.
Note
For the voice calling and video calling use cases, each user joins as a host.
-
-
Send and receive audio and video: Hosts publish streams to the channel. Audience members subscribe to audio and video streams published by hosts.
-
For streaming applications, set the latency level based on your use case:
-
Interactive live streaming: Optimized for real-time interaction with ultra-low latency. Use this when hosts and audience need to interact quickly, such as in live Q&A sessions, interactive classrooms, or auctions.
-
Broadcast streaming: Optimized for scalability with slightly higher latency. Use this for large-scale events where one-way broadcasting is sufficient, such as concerts, sports events, or news broadcasts.
-
Prerequisites
-
A camera and a microphone.
-
A valid Agora account and project. See Agora account management for details.
-
Unreal Engine 4.27 or higher.
-
Prepare your development environment according to your target platform and engine version:
-
Two physical devices for testing.
Set up your project
Refer to the following steps or the Unreal official guide to create a new project. If you already have an Unreal project, skip to the next section.
-
Open Unreal Engine. Select Games under New Project Categories, and click Next.
-
Configure your project as follows:
- Template: Select Blank.
- Project Defaults:
- Language: Select Blueprint.
- Target Platform: Pick Desktop.
- Project Location: Enter a project files storage path.
- Project Name: Type a suitable name for your project.
Click Create.
-
In the Unreal Project Browser, click on Browse and locate the
.uprojectfile. -
Select the project and click Open.
Install the SDK
Take the following steps to add the RTC SDK to your project:
- Download the latest version of Agora Unreal RTC SDK from Download SDKs and unzip it.
- In your project root folder, create a
Pluginsfolder. - Copy
AgoraPluginfrom the Unreal SDK folder toPlugins.
Implement Realtime Communication
This section guides you through the implementation of basic real-time audio and video interaction in your app.
Create a level
-
In the Content folder of the Content Browser, right-click and select Level to create a Level Blueprint and name it BasicVideoCallScene.
-
Double-click BasicVideoCallScene and click Blueprints > Open Level Blueprint above the editor to open the level blueprint.
Implement basic processes
In the My Blueprint panel, double-click Graphs > EventGraph to open the event graph. You see two event nodes: Event BeginPlay (game starts) and Event End Play (game ends). Create event nodes with the corresponding functions and variables, and connect them as shown in the following figure to implement the Realtime Communication logic:
The following table lists the main nodes:
| # | Node | Type | Description |
|---|---|---|---|
| 1 | Set Show Mouse Cursor | Native* | (Optional) Set whether to display the mouse cursor. Check to display it. Note
|
| 2 | Load Agora Config | Custom** | Loads Agora configuration. Used to verify user identity when creating and joining channels. |
| 3 | Create BP Video Widget | Native | Create user interface:
|
| 4 | Set Basic Video Call Widget | Custom | Set up the user interface:
|
| 5 | BindUIEvent | Custom | Use Bind UI events to handle event logic after clicking the Join Channel and Leave Channel buttons. |
| 6 | Add to Viewport | Native | Add user interface to the viewport. |
| 7 | Check Permission | Custom | (Optional) Check whether you have obtained the system permissions required for real-time audio and video interaction, such as access to the camera and microphone. Note If your target platform is Android, create this node to check system permissions. |
| 8 | Init Rtc Engine | Custom | Create and initialize the RTC engine. |
| 9 | Un Init Rtc Engine | Custom | Leave the channel and release resources. |
* Native nodes are nodes that come with the blueprint and can be added and called directly.
** Custom nodes are not included in the blueprint. You create a custom function before you can add the corresponding node.
Add channel-related variables
Add variables to create an engine instance and join a channel.
-
Create three variables:
Token, ChannelId, and AppId. Select the Variable Type as String.
-
In the Load Agora Config function, add the Sequence node, and then connect Set Token, Set Channel Id, and Set App Id respectively. Fill in the token, channel name, and app ID values obtained from Agora Console.
Initialize RTC engine
-
If your target platform is Android, check whether system permissions have been granted before initializing the RTC engine. Refer to the following figure to create nodes for adding permissions to access the microphone and camera in the CheckPermission function.
Note
If your target platform is macOS or iOS, please refer to How do I add the permissions needed for real-time interaction to my Unreal Engine project?
-
To initialize the RTC engine, in the InitRtcEngine function, create and connect nodes as shown in the following figure:
-
Create
IRtcEngineandIRtcEngineEventHandler.-
To store references to the engine and event-handler interface classes, create
RtcEngineandEventHandlervariables, and set the Variable Type to Agora Rtc Engine and IRtc Engine Event Handler, respectively. -
Add two Construct Object From Class nodes, set Class to Agora Rtc Engine and IRtc Engine Event Handler respectively. Connect to Set Rtc Engine and Set Event Handler, respectively.
-
-
Bind
IRtcEngineEventHandlerclass-related callback functions.-
Create
onJoinChannelSuccess,onLeaveChannel,onUserJoined, andonUserOfflinecallback functions. Refer to the following table to configure the input parameters of the callbacks:Callback Description Input parameters FOnJoinChannelSuccessThe local user successfully joined a channel. channel: (String) Channel name.uid: (Integer64) The ID of the user joining the channel.elapsed: (Integer) The time (in milliseconds) that elapsed from the local call toJoinChanneltill the occurrence of this event.
FOnLeaveChannelThe local user left the channel. - stats: Call statistics.FOnUserJoinedA remote user joined the current channel. uid: (Integer64) The user ID of the remote user joining the channel.elapsed: (Integer) The time (in milliseconds) that elapsed from the local call toJoinChanneltill the occurrence of this event.
FOnUserOfflineA remote user left the current channel. uid: (Integer64) The ID of the user going offline.reason: Offline reason. For details, seeEUSER_OFFLINE_REASON_TYPE.
-
Create a Bind Event function. In this function, add a Sequence node, and then bind the
onJoinChannelSuccess,onLeaveChannel,onUserJoined, andonUserOfflinecallback events.
-
-
IRtcEngineinitialization- Call Initialize to initialize the RTC engine.
- Connect to the RtcEngineContext configuration
IRtcEngineinstance.
Set the channelProfile, clientRoleType, and audienceLatencyLevel according to your use case:
| Use case | Channel profile | Client role | Latency level |
|---|---|---|---|
| Voice calling | CHANNEL_PROFILE_COMMUNICATION | CLIENT_ROLE_BROADCASTER | AUDIENCE_LATENCY_LEVEL_ULTRA_LOW_LATENCY (default) |
| Video calling | CHANNEL_PROFILE_COMMUNICATION | CLIENT_ROLE_BROADCASTER | AUDIENCE_LATENCY_LEVEL_ULTRA_LOW_LATENCY (default) |
| Interactive live streaming | CHANNEL_PROFILE_LIVE_BROADCASTING | CLIENT_ROLE_BROADCASTER or CLIENT_ROLE_AUDIENCE | AUDIENCE_LATENCY_LEVEL_ULTRA_LOW_LATENCY (default) |
| Broadcast streaming | CHANNEL_PROFILE_LIVE_BROADCASTING | CLIENT_ROLE_BROADCASTER or CLIENT_ROLE_AUDIENCE | AUDIENCE_LATENCY_LEVEL_LOW_LATENCY |
Note
- Only broadcasters can publish media. Audience members cannot publish until promoted to broadcaster.
- Choose Communication mode for calls where every user publishes, typically fewer than 17 participants. Choose Live Broadcasting mode for larger events with separate hosts and audience.
- The latency level only applies to the audience role, and affects your pricing tier.
Bind UI events
To bind UI events:
-
Create and implement the
OnJoinChannelClickedevent callback.- Call Enable Video and Enable Audio to enable the video and audio modules.
- Call Join Channel to join the channel.
- Set the following parameters in Make ChannelMediaOptions:
- Set Publish Camera Track to
AGORA TRUE VALUEto publish the video stream recorded by the camera. - Set Publish Microphone Track to
AGORA TRUE VALUEto publish the audio stream recorded by the microphone. - Set Auto Subscribe Video to
AGORA TRUE VALUEto automatically subscribe to all video streams. - Set Auto Subscribe Audio to
AGORA TRUE VALUEto automatically subscribe to all audio streams. - Check Client Role Type Set Value and set Client Role Type to
CLIENT_ROLE_BROADCASTERorCLIENT_ROLE_AUDIENCE, to set the user role to host or audience. - Check Channel Profile Set Value and set Channel Profile to
CHANNEL_PROFILE_LIVE_BROADCASTING.
- Set Publish Camera Track to
-
Create and implement the
OnLeaveChannelClickedevent callback. When the event is triggered, call Leave Channel to leave the channel. -
In the Bind UIEvent function, refer to the figure below to bind the
OnJoinChannelClickedandOnLeaveChannelClickedcallback functions to the Join Channel and Leave Channel buttons respectively. When the button is clicked, the corresponding event callback is triggered.
Note
You can also bind UI events in Unreal Motion Graphics (UMG). This document only shows binding using the Bind UIEvent Function.
Set up local and remote views
-
Create and implement the MakeVideoView function to load the view when local or remote users join the channel:
- In this function, create
SavedUID,SavedSourceType,SavedChannelIDlocal variables, set the Variable Type toInteger64,VIDEO_SOURCE_TYPE, andString, respectively. Save the variables for use when loading the view later. - Create a local view. In the local view, if the UID is 0, a value is randomly assigned by the SDK, and the video source type is
VIDEO_SOURCE_CAMERA_PRIMARY(the first camera). - Create a remote view. In the remote view, the
uidis the uid sent from the remote end, and the video source type isVIDEO_SOURCE_REMOTE(remote video obtained from the network).
- In this function, create
-
Create and implement the ReleaseVideoView function to release the view when a local or remote user leaves the channel.
- In this function, create
SavedUID,SavedSourceType, andSavedChannelIDlocal variables, set the Variable Type toInteger64,VIDEO_SOURCE_TYPE, andString, respectively. Save the variables for use when releasing the view later. - Release the local view.
- Release the remote view.
- In this function, create
Implement callback function
Configure the previously created onJoinChannelSuccess, onLeaveChannel, onUserJoined, and onUserOffline callback functions as follows:
-
After the local user successfully joins the channel, the
onJoinChannelSuccesscallback is triggered and the local view is created. Theuidis set to0by default, but it is assigned a random value by the SDK. The video source type isVIDEO_SOURCE_CAMERA_PRIMARY(first camera): -
After the local user leaves the channel, the
onLeaveChannelcallback is triggered which releases the local view: -
When a remote user joins the channel, the
onUserJoinedcallback is triggered to create a remote view.uidis the uid sent from the remote end, and the video source type isVIDEO_SOURCE_REMOTE(remote video obtained from the network): -
When a remote user leaves the channel, the
onUserOfflinecallback is triggered to release the remote view:
Leave the channel and release resources
To leave the channel, implement the following steps:
- Leave the channel.
- Unregister Agora backend event callback.
- Destroy
IRtcEngineObjectto release all resources used by Agora SDK.
Refer to the figure below to implement the UnInitRtcEngine function:
Test the sample code
Take the following steps to test the sample code:
-
In the Load Agora Config function, fill in the app ID, channel name, and temporary token for your project.
-
In the Unreal Editor, click Play to run your project. Click JoinChannel to join a channel.
-
Invite a friend to run the demo client on a second device. Use the same app ID, channel name, and token to join. After your friend joins successfully, you can hear and see each other.
Reference
This section contains content that completes the information on this page, or points you to documentation that explains other aspects of this product.
- If a firewall is deployed in your network environment, refer to Connect with Cloud Proxy to use Agora services normally.
Next steps
After implementing the quickstart sample, read the following documents to learn more:
- To ensure communication security in a test or production environment, best practice is to obtain and use a token from an authentication server. For details, see Secure authentication with tokens.
Sample project
Agora provides open source sample projects on GitHub for your reference. Download or view the JoinChannelVideo project for a more detailed example.
Frequently asked questions
- How can I listen for audience joining or leaving a channel?
- How can I fix black screen issues?
- Why can't I turn on the camera?
- How can I solve channel-related issues?
- How can I set the log file?
