Examples for .NET
Examples for .NET
The examples are cross-platform application projects using MAUI based on .NET 8. Each example consists of three parts: an Android part, an iOS part, and shared code (based on .NET 8).
The Android part of the project includes settings and platform-specific code for Android.
iOS section - corresponding iOS code and settings;
The section with common code contains the UI, core operational logic code, and SDK usage code.
To use TrueConf Mobile SDK, you first need to import platform-specific interfaces in the App class:
using Trueconf.Sdk.NET;
#if ANDROID
using Trueconf.Sdk.Android;
#elif IOS
using Trueconf.Sdk.iOS;
#endifAll you need to get started is to obtain the ITrueConfSDK object by initializing the implementation for Android or iOS of this interface:
ITueConfSDK tcSDK = new TrueConfSDKAndroid(); // for Android
ITrueConfSDK tcSDK = new TrueConfSDKiOS(); // for iOSAll examples contain common parts:
- In the App class constructor, when creating a MainPage object, the obtained
ITrueConfSDKobject is passed to the MainPage constructor:
MainPage = new MainPage(tcSDK);- In the MainPage constructor, the received
ITrueConfSDKobject is stored in thetcSDKclass field, and the handling of necessary events is configured:
tcSDK.OnServerStatusEvent += TrueConfSDK_OnServerStatusEvent;
tcSDK.OnStateChangedEvent += TrueConfSDK_OnStateChangedEvent;
tcSDK.OnLoginEvent += TrueConfSDK_OnLoginEvent;
tcSDK.OnLogoutEvent += TrueConfSDK_OnLogoutEvent;
tcSDK.OnInviteEvent += TrueConfSDK_OnInviteEvent;
tcSDK.OnRejectEvent += TrueConfSDK_OnRejectEvent;
tcSDK.OnRejectTimeOutEvent += TrueConfSDK_OnRejectTimeOutEvent;
tcSDK.OnAcceptEvent += TrueConfSDK_OnAcceptEvent;
tcSDK.OnConferenceEndEvent += TrueConfSDK_OnConferenceEndEvent;
tcSDK.OnConferenceStartEvent += TrueConfSDK_OnConferenceStartEvent;
tcSDK.OnUserStatusUpdateEvent += TrueConfSDK_OnUserStatusUpdateEvent;The initial initialization occurs in the platform-specific sections of the project, with platform-specific parameters being passed—
Activityfor Android andUIApplicationfor iOS. Then theStartmethod is called in the MainPage class, and the setup for handling necessary events in the example is located in the MainPage class constructor. Event handlers can also be configured afterStartand changed at any time.Android section: In the
MainActivityclass within theOnCreatemethod, the static methodInitis called, passing the currentActivityfor subsequent initialization:
TrueConfSDKAndroid.Init(this);- iOS section: In the
AppDelegateclass, the static methodInitis called within theFinishedLaunchingmethod, passing the currentUIApplicationfor further initialization:
TrueConfSDKiOS.Init(application);Example 1. Demonstration of the main SDK features
A single-page application implementing the main features of TrueConf Mobile SDK:
Initialization and connection to the server.
Tracking client statuses.
Connect to the server, log in as a user, and log out by pressing the corresponding buttons.
Call another user by their TrueConf ID.
Ability to automatically accept incoming video calls and invitations to group conferences.
The MainPage class contains the core functionality of TrueConf Mobile SDK:
Processing events:
OnServerStatusEvent- monitoring the server connection status;OnLoginEvent- tracking login status;OnLogoutEvent- monitoring the logout status;OnInviteEvent- handling of incoming calls and invitations for automatic acceptance;OnStateChangedEvent- client state tracking.
Clicking the respective buttons triggers the methods:
Start- SDK initialization;LoginAs- authentication with TrueConf ID and password;Logout- user deauthorization;CallTo- call to the user whose TrueConf ID is entered in the appropriate input field.
The UpdateConnectionState method uses the following property methods:
IsStarted- check if the SDK is running;IsConnectedToServer- retrieve the server connection status;IsLoggedIn- retrieve the authorization status on the server;IsInConference– check if the client is in a call or conference.
Example 2. Demonstrating the use of trueconf links
A single-page application with the following features implemented TrueConf Mobile SDK:
Initializing the SDK without specifying a server.
Processing the entered trueconf link when the button is clicked.
The MainPage class contains the core functionality of TrueConf Mobile SDK:
Processing events:
OnServerStatusEvent- monitoring the server connection status;OnStateChangedEvent- client state tracking.
Clicking the respective buttons triggers the methods:
Start/Stop- SDK initialization and termination;ParseProtocolLink- execution of a sequence of commands from a TrueConf link.
The UpdateConnectionState method uses the following property methods:
IsConnectedToServer- retrieves the server connection status.
Example 3: Working with user statuses
The example provides a working code sample that allows you to monitor the status of users on the server with whom you can establish a connection, as well as add any users for status tracking and monitor their availability. In addition to the user status, it uses the standard TrueConf Mobile SDK functionality: server connection, login, and automatic call acceptance.
The entire example is based on a single OnUserStatusUpdateEvent event handler block, which executes when the server sends a user's status. The GetUserStatus method is used to add any user to the watch list. The implemented code allows tracking and displaying status changes of a specific user in a table, handling the addition of new users, and adding any user for tracking.
To store the list of users with their statuses, a UserStatus class is implemented with the fields string userId, string status, Color color. This class implements the INotifyPropertyChanged interface to support the automatic updating of the user status table upon changes in the list. The MainPage class contains a field with a list of UserStatus objects for storing all tracked users and their statuses:
ObservableCollection<UserStatus> users;In the constructor of the MainPage class, this list is passed as the ItemsSource to a ListView element on the page for display.
The example is a single-page application that implements the main features of TrueConf Mobile SDK:
Tracking the status of users from the address book and watchlist.
Adding users to the watchlist by their TrueConf ID.
Connecting to the server and logging in as a user.
Displaying a list of users with their statuses from the address book and watch list.
Ability to automatically accept incoming video calls and invitations to group conferences.
The MainPage class contains the core functionality of TrueConf Mobile SDK:
Processing events:
OnServerStatusEvent- monitoring the server connection status;OnLoginEvent- tracking login status;OnLogoutEvent- monitoring the logout status;OnInviteEvent- handling of incoming calls and invitations for automatic acceptance;OnStateChangedEvent- client state tracking;OnUserStatusUpdateEvent- monitors user status changes in the address book or watch list.
Clicking the respective buttons triggers the methods:
Start- SDK initialization;LoginAs- authentication with TrueConf ID and password;Logout- user deauthorization;GetUserStatus- retrieves the user's status and adds them to the watchlist in the current session.
The UpdateConnectionState method uses the following property methods:
IsStarted- check if the SDK is running;IsConnectedToServer- retrieve the server connection status;IsLoggedIn- retrieve the authorization status on the server;IsInConference– checks whether the client is in a call or conference;GetMyId- retrieve the TrueConf ID of the authorized user.
Example 4. Working with group conferences
One of the key features of TrueConf Mobile SDK is the ability to create and participate in video conferences with multiple users simultaneously. Currently, the SDK allows connecting only to existing conferences on the server.
There are four ways to connect:
Receiving an invitation via an incoming call, similar to a regular call
OnInviteEventwith confirmationAcceptCall.By conference ID using the
JoinConfmethod.Via a TrueConf link that includes a conference ID using the
ParseProtocolLinkmethod.Using the
ScheduleLoginAsmethod, pass the conference ID as thecallToUserparameter and setisPublic=true. This method is similar to theParseProtocolLinkmethod but does not require knowledge of the command line format, providing a fixed set of parameters.
The MainPage class contains the core functionality of TrueConf Mobile SDK:
Processing events:
OnServerStatusEvent- monitoring the server connection status;OnLoginEvent- tracking login status;OnLogoutEvent- monitoring the logout status;OnInviteEvent- handling of incoming calls and invitations for automatic acceptance;OnStateChangedEvent- client state tracking.
Clicking the respective buttons triggers the methods:
Start- SDK initialization;LoginAs- authentication with TrueConf ID and password;Logout- user deauthorization;JoinConf- joining a conference by its ID.
The UpdateConnectionState method uses the following property methods:
IsStarted- check if the SDK is running;IsConnectedToServer- retrieve the server connection status;IsLoggedIn- retrieve the authorization status on the server;IsInConference– check if the client is in a call or conference.
Example 5: Interface Customization
The example demonstrates how to replace the images of all buttons displayed during a call, add your own custom buttons, and open your window on top of the conference window.
The general part duplicates the functionality of Example 1:
connection to the server;
authorization and deauthorization;
call to user via TrueConf ID;
Handling of key events and client status monitoring.
Additionally, in the Android and iOS versions, the implementation includes adding custom buttons and displaying a separate alert window over the conference window.
Android section:
After calling the Init function in the OnCreate method of the MainActivity class, an array of objects of type TCExtraButton is created. Here, you need to specify the button name and the action to be executed of type Android.Views.View.IOnClickListener:
var btns = new TCExtraButton[] {
new TCExtraButton("Button 1", new OnClickListener(handler: v => AlertCreate(1))),
...
};The AlertCreate function creates an AlertDialog and displays it using the Show method:
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.SetPositiveButton("OK", (sender, e) => { });
dialog.SetCancelable(false);
dialog.SetTitle("Title");
dialog.SetMessage("Message");
dialog.Show();Then, in the OnCreate method of the MainActivity class, the created buttons are added to the SDK using the static method AddCustomButtons:
TrueConfSDKAndroid.AddCustomButtons(btns);iOS section:
After calling the Init function in the FinishedLaunching method of the AppDelegate class, an array of TCSDKExtraButton objects is created. In these objects, a UIAlertController is created and displayed using the PresentViewController method:
var btns = new UIAlertAction[] { new TCSDKExtraButton("Button 1", UIImage.GetSystemImage("star"), () => { var alertController = UIAlertController.Create("Title", "Message", UIAlertControllerStyle.Alert); alertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Cancel, null)); TrueConfSDKiOS.PresentViewController(alertController, true, null, null); }), ... };Then, in the FinishedLaunching method of the AppDelegate class, after creating an array of TCSDKExtraButton type buttons, the created array is added to the SDK using the static method AddCustomButtons:
TrueConfSDKiOS.AddCustomButtons(btns);Example 6. Chat
A single-page application implementing the main features of TrueConf Mobile SDK:
Initialization and connection to the server.
Tracking client statuses.
Connect to the server, log in as a user, and log out by pressing the corresponding buttons.
Sending a message to another user via their TrueConf ID.
Ability to automatically accept incoming video calls and invitations to group conferences.
The MainPage class contains the core functionality of TrueConf Mobile SDK:
Processing events:
OnServerStatusEvent- monitoring the server connection status;OnLoginEvent- tracking login status;OnLogoutEvent- monitoring the logout status;OnInviteEvent- handling of incoming calls and invitations for automatic acceptance;OnStateChangedEvent- client state tracking;OnChatMessageReceivedEvent- processes incoming chat messages. When a new text message is received, an alert appears displaying the message text and the sender's name.
Clicking the respective buttons triggers the methods:
Start- SDK initialization;LoginAs- authentication with TrueConf ID and password;Logout- user deauthorization;SendChatMessage- sends a chat message to a user whose TrueConf ID is entered in the appropriate input field.
The UpdateConnectionState method uses the following property methods:
IsStarted- check if the SDK is running;IsConnectedToServer- retrieve the server connection status;IsLoggedIn- retrieve the authorization status on the server;IsInConference– check if the client is in a call or conference.
