# Examples for iOS

Here are some examples for Xcode IDE when developing for iOS/iPadOS. You can download them from our GitHub.

# 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 server connection (start).

  2. Tracking client statuses.

  3. Manual login (by pressing a button) by the user and manual logout.

  4. Call a user by their TrueConf ID (callTo).

  5. Ability to receive incoming video calls.

  6. Reset the SDK state to its initial condition.

The entire SDK essentially consists of the TCSDK class and necessary constants. To get started, all you need to do is import TrueConfSDK.h:

#import "TrueConfSDK/TrueConfSDK.h"

and declare an object of type TCSDK somewhere:

TCSDK* tcsdk;

The initialization of the TCSDK and the configuration for handling necessary events in the example are located in the startSDK method and are called from the viewDidLoad method of the ViewController class. The initialization is performed using the method initWithViewController:

[[TCSDK alloc] initWithViewController:self forServer:@””];

Next, there is an optional configuration for event handling. Finally, the SDK is launched using the method start:

[self.tcsdk start];

You can configure event handlers even after start and change them at any time.

Some of the available event handlers implemented in the example:

  • onServerStatus – the method that triggers when the server connection status changes.

  • onStateChanged – a method triggered by any change in the SDK state (such as server connection status, user login status, or call status). For instance, you can perform a check with isConnectedToServer here.

  • onLogin and onLogout are triggered when a user logs in and logs out, respectively. You can check whether the user is logged in at any time using the method isLoggedIn.

  • onInvite triggers when there is an incoming call from another user or an invitation to a group conference. Use the method acceptCall with a parameter of true or false to respond. However, it is not necessary to respond directly from this block or at all.

The example also uses the following methods:

  • loginAs – method for logging in.

  • logout – method for logging out.

  • callTo – call to a user with a known TrueConf ID.

Resetting the SDK state is done by simply assigning nil to the tcsdk object after calling the method stop and reinitializing if necessary. See (IBAction)doClear:(id)sender.

The example automatically connects to the server, after which you have the opportunity to perform any actions described in the TrueConf link as a package:

  • reconnect to another server;

  • log in with the required user;

  • Call another user by their TrueConf ID or join a group conference using its ID.

All actions are performed sequentially and automatically. You only need to use the method parseProtocolLink, with the trueconf link in the String format as its parameter.

You can read more about the trueconf: control protocol in this article.

The example also demonstrates the use of the method scheduleLoginAs, which has numerous defined parameters for executing the sequential actions described above.

# Example 4. Working with User Statuses

The example provides a functioning code sample that allows you to monitor the statuses of users on the server with whom a connection can be established, as well as add any users to track their statuses and monitor their availability. In addition to the user's status itself, standard SDK functionality is used:

  • automatic server connection;

  • automatic login;

  • automatic call answering.

The entire operation of the example is based on a single block, the onUserStatusUpdate event, which is triggered when the server sends the status of any user from our address book. To track any user, use the method getUserStatus. The implemented code allows you to seamlessly track and display status changes of a specific user in the table, handle the addition of new users, and add any user for tracking.

To simplify the example, we didn't use common classes, so the work is done only in ViewController and TableViewController. The main means of data storage is NSMutableSet *userSet, which, when updating data, adds users to the set, i.e., it simply accumulates user data.

The accumulated data is processed in the TableViewController, which displays the list of users. The sorted list of users from NSSet (since we need to work with an array for the TableView class) is stored in NSMutableArray *userArray as an array of NSString. User statuses are stored in NSMutableDictionary *cashStatusDictionary, where the key is the TrueConf ID from the array, and the value is an NSNumber representing the status.

The array management is implemented through the method -(NSArray *) userList, where the legacy initialization of the userArray takes place. Note that the users in the displayed list are a combination of the contact list (permanent list) and those whose status we are simply monitoring during the current session.

# Example 3. Working with group conferences

One of the key features of TrueConf Mobile SDK is the ability to participate in video conferences with multiple users simultaneously. Currently, it only allows joining existing conferences.

Joining a group conference.

  1. Receiving an invitation via an incoming call, similar to a regular call onInvite with confirmation acceptCall.

  2. Via conference ID using the method joinConf.

  3. Using a trueconf link that includes the conference ID with the method parseProtocolLink.

  4. Use the method scheduleLoginAs, passing the conference ID as the callToUser parameter and setting isPublic=true. This method is similar to the parseProtocolLink method but does not require knowledge of the command line format, providing a fixed set of parameters.

Also covered is event handling:

# 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 own window on top of the conference window.

In the example, the images of standard buttons in the conference control panel, as well as the buttons on the self-view, are changed. Customization is done by adding images with specific names to the Assets.

Below is a list of icon names that can be replaced:

  • call_end - end of call;

  • camera_on_new / camera_off_new - camera is in on/off state;

  • mic_on_new / mic_off_new - microphone on/off status;

  • sound_off_new - audio output device is muted;

  • sound_on_new - current audio output device - loudspeaker;

  • receiver_sound - current audio output device - handset speaker;

  • airpods_device - the current audio output device is the AirPods wireless headphones;

  • airpodspro_device - the current audio output device is AirPods Pro wireless headphones;

  • bluetooth_device - current audio output device - Bluetooth device;

  • wired_device - current audio output device - wired headphones;

  • more_new - the ellipsis button, which opens a list of additional buttons;

  • camera_swap - switch the camera from front to back and vice versa;

  • more_btn - camera selection and flashlight toggle;

  • resize_selfview_visible / resize_selfview_small - enable/disable compact self-view mode.

To apply icons in Assets, you need to specify the NSBundle used in the resources property.

self.tcsdk.resources = [NSBundle mainBundle];

In the example, 3 additional buttons are also added in the extraButtons method. There can be an unlimited number of additional buttons, and they will be added to the list that opens when the ellipsis button is tapped, in the order they appear in the provided array. For an additional button TCSDKExtraButton, you can set the text, image, and a block of code that executes when the user presses the button.

Additionally, this example demonstrates how to display any other UIViewController over the conference window. By pressing any of the 3 additional buttons, the UIViewController created here is displayed in different UIModalPresentationStyle styles: pageSheet, formSheet, or fullScreen using the method presentViewController.

# Example 6. Connecting to a server from the list

The example is generally similar to Example 1. Here is a code sample demonstrating how to launch the SDK by specifying a list of potential servers for connection. The example will connect to the first available active server from the list. During initialization with the method initWithViewController, you can specify any string for the server, and then in the method startWithServersList, pass a string containing a comma-separated list of server addresses. In this case, the SDK will attempt to connect to the servers in the order they are listed.

You can subscribe to the event onServerStatus to monitor the address selection process. For "bad" addresses, connected=false will be reported, and for the first "good" one, connected=true, and the process will stop. This process may take some time - usually no more than 30 seconds per address.

# Example 7. Customizing the video layout in a conference

The example demonstrates the ability to place your own image and the images of conference participants in separate UIView elements. It also shows the independent implementation of conference control buttons on the main window.

Everything you need to change the sizes and coordinates of other conference participants is to implement the TCWindowsDelegate protocol method. This, along with assigning the delegate to the windowsDelegate property, is implemented directly in the ViewController:

self.tcsdk.windowsDelegate = self;

The hideConfControls property is used to hide the default conference controls and create your own controls anywhere.

The windowsDelegate property is used to change the coordinates of each participant's video windows. The TCWindowsDelegate protocol has only one method tcWindowsGetPlaces and is called automatically when the SDK needs to rebuild the received video. In this example, we reduce the width of all videos to half by modifying the rectangle properties of TCSDKWindowRect objects. Each object also contains the userId and resolution properties. The resolution property holds the original resolution of the decoded video.

To position the conference participants' window and your own image arbitrarily, use the xview and xsview properties, which are specified as parent elements for them.

3 UIViews have been added to the Storyboard:

  • pink - contains buttons for conference management, which partially duplicate the functions of the standard control panel: End - ends the call using the hangup method, Mic - changes the microphone status using the muteMicrophone method, Cam - changes the camera status using the muteCamera method.

  • green - is set to the xview property and therefore contains incoming video during the conference. The coordinates and sizes can be any values you specify.

  • yellow - set in the xsview property and therefore contains your own image during the conference. The coordinates and dimensions can be any that you specify.

To manage audio output devices, an Audio button has been added, which is only displayed during a conference. Pressing it brings up a UIAlertController with cells filled with information about available audio devices (name and image). The method getAudioDeviceList is used to obtain the list of audio devices. Tapping on a cell in this UIAlertController will switch the current audio device to the selected one, specifying it in the property audioDevice.

A Swap button has been added to switch from the front camera to the rear camera (or vice versa), and it is displayed only during a conference. When pressed, it executes the method swapCamera, which switches the current camera.

# Example 8. Chat

The example demonstrates the ability to send text messages using the sendChatMessage method and handle new incoming messages in the onChatMessageReceived event.

Implemented the ability to send and receive messages from the main ViewController example, as well as in a separate chat window ChatViewController, which can be opened from the main window by clicking the Open Simple Chat button. Additionally, while in a conference, you can open the chat via the custom Chat button created using the method setNewExtraButtons (the creation of additional conference control buttons is discussed in detail in Example 5).

If a message is sent to a user who is offline, it will be delivered as soon as they come online. If a message is sent when there is no connection to the server, it is queued and will be sent once the server connection is restored.