People engage longer when they see, hear, and interact with each other. The Agora SDK enables you to embed real-time voice and video interaction in any app, on any device, anywhere.
This page shows the minimum code you need to add voice call into your app by using the Agora Video SDK.
The following figure shows the workflow of a voice call implemented by the Agora SDK.
As shown in the figure, the workflow for adding Voice Call in your project is as follows:
Retrieve a token
A token is the credential that authenticates a user when your app client joins a channel. In a test or production environment, your app client retrieves tokens from a server in your security infrastructure.
Join a channel
Call joinChannel
to create and join a channel. App clients that pass the same channel name join the same channel.
Publish and subscribe to audio in the channel
After joining a channel, the app client automatically publishes and subscribes to audio in the channel.
For an app client to join an RTC channel, you need the following information:
In this section, we will create a Windows project and integrate the SDK into the project.
Now, let's build a Windows project from scratch. Skip to Integrate the SDK if a Windows project already exists.
Choose one of the following ways to add agora_rtc_sdk
into the project according to the type of your Windows Forms App.
.net core
agora_rtc_sdk
, select the Latest stable SDK, and then click Install. The SDK is now added to your project..net framework
agora_rtc_sdk
, select the Latest stable SDK, and then click Install. The SDK is now added to your project.This section introduces how to use the Agora SDK to make a voice call. The following figure shows the API call sequence of a basic one-to-one video call.
Create the user interface (UI) for the one-to-one video call in your project. Skip to Import the SDK if you already have a UI in your project.
If you are implementing a voice call, we recommend adding an end-call button.
Add the following line to import the Agora SDK:
using agora.rtc;
The C# SDK is developed upon C++. In this step, we create an AgoraRtcEventHandler
class from IAgoraRtcEngineEventHandler
for managing callback events:
class AgoraRtcEventHandler : IAgoraRtcEngineEventHandler
{
public AgoraRtcEventHandler()
{
}
};
Create and initialize the IAgoraRtcEngine
object before calling any other Agora APIs.
Call the CreateAgoraRtcEngine
and Initialize
methods, and pass in the App ID to initialize the IAgoraRtcEngine
object.
You can also listen for callback events, such as when the local user joins or leaves the channel.
// Declare variables
IAgoraRtcEngine rtc_engine_ = null;
IAgoraRtcEngineEventHandler event_handler_ = null;
if (null == rtc_engine_)
{
// Create rtc engine
rtc_engine_ = AgoraRtcEngine.CreateAgoraRtcEngine();
}
RtcEngineContext context = new RtcEngineContext(appId);
// Initialize rtc engine
int ret = rtc_engine_.Initialize(context);
event_handler_ = new AgoraRtcEventHandler();
// Initialize the engine event handler
rtc_engine_.InitEventHandler(event_handler_);
After initializing the IRtcEngine object, you can call the JoinChannel
method to join a channel. In this method, set the following parameters:
channelName
: Specify the channel name that you want to join.
token
: Pass a token that identifies the role and privilege of the user. You can set it as one of the following values:
uid
is the same with those you use to generate the token.token
as "".uid
: ID of the local user that is an integer and should be unique. If you set uid
as 0, the SDK assigns a user ID for the local user and returns it in the OnJoinChannelSuccess
callback.
mute
methods accordingly.rtc_engine_.JoinChannel("", "testChannelId","", 0, new ChannelMediaOptions(true, true, true, true));
Call the LeaveChannel
method to leave the current call according to your scenario, for example, when the call ends, when you need to close the app, or when your app runs in the background.
rtc_engine_.LeaveChannel();
After building the app, follow the steps to add the necessary libraries to the execution path:
.netcore
64-bit apps, copy all the libraries under netCore/x86_64
..netframework
32-bit apps, copy all the libraries under netFramework/x86
.Run the project on your Windows device. You can hear the remote user when you successfully start a one-to-one voice call in your app.
Agora provides an open-source JoinChannelAudio sample project on GitHub. You can try it out or view the source code.