# 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 configuration settings and platform-specific code for Android.

  • iOS part - includes iOS code and settings;

  • The section with common code includes the UI, core business logic code, and SDK usage code.

To use TrueConf Mobile SDK, you first need to import the platform-specific interfaces in the App class:

using Trueconf.Sdk.NET;                                        
#if ANDROID                                                
using Trueconf.Sdk.Android;                                    
#elif IOS                                                
using Trueconf.Sdk.iOS;                                        
#endif

All you need to get started is to obtain the ITrueConfSDK object by initializing the implementation of this interface for Android or iOS:

ITrueConfSDK tcSDK = new TrueConfSDKAndroid();  // for Android           
ITrueConfSDK tcSDK = new TrueConfSDKiOS();      // for iOS

All examples contain common parts:

  • In the App class constructor, when creating the MainPage object, the received ITrueConfSDK object is passed to the MainPage constructor:
MainPage = new MainPage(tcSDK);
  • In the MainPage constructor, the received ITrueConfSDK object is stored in the tcSDK class field, and the necessary event handling 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 takes place in the platform-dependent parts of the project with the transfer of platform-specific parameters - Activity for Android and UIApplication for iOS. Then, the Start method 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 after Start and changed at any time.

  • Android part: In the MainActivity class, the OnCreate method calls the static Init method, passing the current Activity for subsequent initialization:

TrueConfSDKAndroid.Init(this);
  • iOS Part: In the AppDelegate class, the FinishedLaunching method calls the static Init method, passing the current UIApplication for subsequent initialization:
TrueConfSDKiOS.Init(application);

# Example 1. Demonstration of the main capabilities of the SDK

A single-page application where all the main features of TrueConf Mobile SDK are implemented:

  1. Initialization and connection to the server.

  2. Client status monitoring.

  3. Connecting to the server, logging in as a user, and logging out are performed by clicking the corresponding buttons.

  4. Call another user by their TrueConf ID.

  5. Ability to automatically accept incoming video calls and invitations to group conferences.

The MainPage class contains the core functionality of the TrueConf Mobile SDK.

  1. Processing events:

    • OnServerStatusEvent - tracking the server connection status;

    • OnLoginEvent - tracking login status;

    • OnLogoutEvent - tracks logout status;

    • OnInviteEvent - handles incoming calls and invitations for auto-acceptance;

    • OnStateChangedEvent - client state tracking.

  • Clicking the corresponding buttons triggers the methods:

    • Start - SDK initialization;

    • LoginAs - authentication using TrueConf ID and password;

    • Logout - user deauthorization;

    • CallTo - call to the user whose TrueConf ID is entered in the respective input field.

  • The UpdateConnectionState method uses the following property methods:

    • IsStarted - check if the SDK is running;

    • IsConnectedToServer - gets the server connection status;

    • IsLoggedIn - get the authorization status on the server;

    • IsInConference – checks if the client is in a call or conference.

A single-page application with the following features implemented in TrueConf Mobile SDK:

  1. Initializing the SDK without specifying the server.

  2. Processing the entered trueconf link upon clicking the button.

The MainPage class contains the core functionality of the TrueConf Mobile SDK.

  1. Processing events:

    • OnServerStatusEvent - tracking the server connection status;

    • OnStateChangedEvent - client state tracking.

  • Clicking the corresponding buttons triggers the methods:

    • Start/Stop - initialization and termination of the SDK;

    • ParseProtocolLink - executes the sequence of commands in a trueconf link.

  • The UpdateConnectionState method uses the following property methods:

    • IsConnectedToServer - retrieve the server connection status.

# Example 3. Working with user statuses

The example provides a working code sample that allows you to track user statuses on the server, enabling connections with those users. It also allows you to monitor the statuses of any users and track their availability. In addition to the user status, it uses the standard functionality of TrueConf Mobile SDK: server connection, login, and automatic call acceptance.

The entire operation of the example is based on a single event handler block, OnUserStatusUpdateEvent, which executes when the server sends the status of a user. To track any user, the GetUserStatus method is used. The implemented code enables tracking and displaying status changes of a specific user in the table, as well as handling the addition of new users and tracking any user.

To store a list of users with statuses, a class UserStatus is implemented with the fields string userId, string status, and Color color. This class implements the INotifyPropertyChanged interface to support automatic updates of the user status table when changes occur in the list. In the MainPage class, there is a field with a list of UserStatus objects to store all monitored 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:

  1. Tracking the status of users from the address book and watchlist.

  2. Adding users to the watchlist by their TrueConf ID.

  3. Connecting to the server and user login.

  4. Displaying a list of users with their statuses from the address book and watch list.

  5. Ability to automatically accept incoming video calls and invitations to group conferences.

The MainPage class contains the core functionality of the TrueConf Mobile SDK.

  1. Processing events:

    • OnServerStatusEvent - tracking the server connection status;

    • OnLoginEvent - tracking login status;

    • OnLogoutEvent - tracks logout status;

    • OnInviteEvent - handles incoming calls and invitations for auto-acceptance;

    • OnStateChangedEvent - client state tracking;

    • OnUserStatusUpdateEvent - tracking changes in the status of users from the address book or watchlist.

  • Clicking the corresponding buttons triggers the methods:

    • Start - SDK initialization;

    • LoginAs - authentication using TrueConf ID and password;

    • Logout - user deauthorization;

    • GetUserStatus - retrieves the user's status and adds it to the watchlist in the current session.

  • The UpdateConnectionState method uses the following property methods:

    • IsStarted - check if the SDK is running;

    • IsConnectedToServer - gets the server connection status;

    • IsLoggedIn - get the authorization status on the server;

    • IsInConference – checks if 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 only allows connection to existing conferences on the server.

Connection is possible in 4 ways:

  1. Receiving an invitation via an incoming call, similar to a regular OnInviteEvent call with AcceptCall confirmation.

  2. Via conference ID using the method JoinConf.

  3. Via a trueconf link that includes the conference ID using the ParseProtocolLink method.

  4. By using the method ScheduleLoginAs, you pass the conference ID as the callToUser parameter and set isPublic=true. This method is similar to the ParseProtocolLink method, but it does not require knowledge of the command line format, providing a fixed set of parameters.

The MainPage class contains the core functionality of the TrueConf Mobile SDK.

  1. Processing events:

    • OnServerStatusEvent - tracking the server connection status;

    • OnLoginEvent - tracking login status;

    • OnLogoutEvent - tracks logout status;

    • OnInviteEvent - handles incoming calls and invitations for auto-acceptance;

    • OnStateChangedEvent - client state tracking.

  • Clicking the corresponding buttons triggers the methods:

    • Start - SDK initialization;

    • LoginAs - authentication using TrueConf ID and password;

    • Logout - user deauthorization;

    • JoinConf - joining a conference using its ID.

  • The UpdateConnectionState method uses the following property methods:

    • IsStarted - check if the SDK is running;

    • IsConnectedToServer - gets the server connection status;

    • IsLoggedIn - get the authorization status on the server;

    • IsInConference – checks if the client is in a call or conference.

# Example 5. Interface Customization

The example demonstrates how you can replace the images of all buttons displayed during a call, add your own additional buttons, and open your own window over the conference window.

The general section duplicates the functionality of Example 1:

  • connecting to the server;

  • authorization and deauthorization;

  • Call the user by TrueConf ID.

  • Processing of main events and client status tracking.

Additionally, in the Android and iOS sections, custom buttons have been implemented, as well as the display of 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 TCExtraButton objects is created. You need to provide the button name and the action to be performed 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 which a UIAlertController is created and displayed using the PresentViewController method:

```csharp
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 buttons of type `TCSDKExtraButton`, the created array is added to the SDK using the static method `AddCustomButtons`:

```cs
TrueConfSDKiOS.AddCustomButtons(btns);

# Example 6. Chat

A single-page application where all the main features of TrueConf Mobile SDK are implemented:

  1. Initialization and connection to the server.

  2. Client status monitoring.

  3. Connecting to the server, logging in as a user, and logging out are performed by clicking the corresponding buttons.

  4. Sending a message to another user by their TrueConf ID.

  5. Ability to automatically accept incoming video calls and invitations to group conferences.

The MainPage class contains the core functionality of the TrueConf Mobile SDK.

  1. Processing events:

    • OnServerStatusEvent - tracking the server connection status;

    • OnLoginEvent - tracking login status;

    • OnLogoutEvent - tracks logout status;

    • OnInviteEvent - handles incoming calls and invitations for auto-acceptance;

    • OnStateChangedEvent - client state tracking;

    • OnChatMessageReceivedEvent - handles incoming chat messages. When a new text message is received, an alert appears displaying the message text and the sender's name.

  • Clicking the corresponding buttons triggers the methods:

    • Start - SDK initialization;

    • LoginAs - authentication using TrueConf ID and password;

    • Logout - user deauthorization;

    • SendChatMessage - sends a chat message 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 - gets the server connection status;

    • IsLoggedIn - get the authorization status on the server;

    • IsInConference – checks if the client is in a call or conference.