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 video call into your app by using the Agora Video SDK.
The following figure shows the workflow to integrate into your app in order to add Video Call functionality.
As shown in the figure, the workflow for adding Video 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 and video in the channel
After joining a channel, the app client automatically publishes and subscribes to audio and video in the channel.
For an app client to join a 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 video 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 video call, we recommend adding the following elements into the UI:
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_);
// Enable video
rtc_engine_.EnableVideo();
After initializing the IAgoraRtcEngine
object, set the local video view before joining the channel so that you can see yourself in the call.
VideoCanvas vs = new VideoCanvas((ulong)localWindowId.Handle, RENDER_MODE_TYPE.RENDER_MODE_FIT);
rtc_engine_.SetupLocalVideo(vs);
After initializing the IRtcEngine object and setting the local video view, 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));
In a video call, you should be able to see other users too. This is achieved by calling the SetupRemoteVideo
method after joining the channel.
Shortly after a remote user joins the channel, the SDK gets the remote user's ID in the OnUserJoined
callback. Call the SetupRemoteVideo
method in the callback, and pass in the uid
to set the video view of the remote user.
// Call SetupRemoteVideo to set the remote video view
VideoCanvas vc = new VideoCanvas((ulong)remoteWindowId,
RENDER_MODE_TYPE.RENDER_MODE_FIT, "testChannelId", remoteUid);
rtc_engine_.SetupRemoteVideo(vc);
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 see both the local and remote video views when you successfully start a one-to-one video call in your app.
Agora provides an open-source JoinChannelVideo sample project on GitHub. You can try it out or view the source code.