# 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:
Initialization and connection to the server.
Client status monitoring.
Manual login (by pressing a button) by the user and manual logout.
Call another user by their TrueConf ID.
Ability to receive incoming video calls and invitations to group conferences.
Reset the SDK state to its original settings.
The entire SDK essentially consists of the TCSDK class and necessary constants. All you need to get started is to import TrueConfSDK.h
:
#import "TrueConfSDK/TrueConfSDK.h"
and declare an object of type TCSDK
somewhere:
TCSDK* tcsdk;
The initialization of TCSDK and the configuration for handling necessary events in the example are found in the startSDK
method, which is called from viewDidLoad
in 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
is a method that triggers when the server connection status changes.onStateChanged
is a method that triggers when there is a change in the SDK state, such as the connection status to the server, whether the user is logged in, or whether a call is in progress. For example, you can perform a checkisConnectedToServer
here.onLogin
andonLogout
are triggered when a user logs in and logs out, respectively. You can check if a user is logged in at any time using the methodisLoggedIn
.onInvite
is triggered when there is an incoming call from another user or an invitation to a group conference. Use the methodacceptCall
with the parametertrue
orfalse
to respond. However, it is not necessary to reply 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 a user with a known TrueConf ID.
Resetting the SDK state is done by simply assigning nil
to the tcsdk
object after executing the method stop
and reinitializing if necessary. Refer to (IBAction)doClear:(id)sender
.
# Example 2. Demonstration of working with TrueConf links
The example automatically connects to the server, after which you can perform any actions described in the trueconf link as a batch:
reconnect to another server;
log in with the necessary 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 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 multiple defined parameters to perform the sequential actions described above.
# Example 3. Working with user statuses
The example provides a working code sample that allows you to track the status of users on the server who can be contacted, as well as add any users for status tracking and monitor their availability. In addition to the user's status, it utilizes the standard SDK functionality:
automatic connection to the server;
automatic login;
Automatic call answering.
The entire example operates 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 monitor any user, use the method getUserStatus
. The implemented code allows seamless tracking and display of a specific user's status changes in the table, processing the addition of new users, and adding any user for monitoring.
To simplify the example, we didn't use shared classes, so all the work is done exclusively in ViewController and TableViewController. The main data storage is NSMutableSet *userSet
, which adds users to the set when data is updated, essentially accumulating user information.
The processing of accumulated data is handled in the TableViewController, which displays a list of users. The sorted list of users from NSSet
(since we need an array to work with 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 is handled via the method -(NSArray *) userList
, where the array userArray
is initialized. Note that the users in the displayed list are a combination of the contact list (a permanent list) and those whose status we are just monitoring during the current session.
# 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:
Receiving an invitation via an incoming call, similar to a regular onInvite call with acceptCall confirmation.
By Conference ID using the joinConf method.
Via a TrueConf link that includes the conference ID, using the method
parseProtocolLink
.Use the
scheduleLoginAs
method, passing the conference ID as thecallToUser
parameter and settingisPublic=true
. This method is similar to theparseProtocolLink
method but does not require knowledge of the command line format, providing a fixed set of parameters.
Also covered is event handling:
onAccept
- if the called user has accepted your call;onReject
- if the called user rejected your call;onConferenceStart
- conference start;onConferenceEnd
- end of the conference;onConferencePasswordRequired
- if there was an unsuccessful attempt to join a conference that is password-protected on the server. To join such a conference, use the methodjoinConf
with thepassword
parameter.
# 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.
In the example, the images of standard buttons on 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 Assets.
Below is a list of icon names that can be replaced:
call_end
- end of call;camera_on_new / camera_off_new
- camera state on/off;mic_on_new / mic_off_new
- microphone in on/off state;sound_off_new
- sound output device is off;sound_on_new
- the current audio output device is the loudspeaker;receiver_sound
- current audio output device - earpiece speaker;airpods_device
- the current audio output device is AirPods wireless headphones;airpodspro_device
- the current audio output device is AirPods Pro wireless earbuds;bluetooth_device
- current audio output device is a Bluetooth device;wired_device
- current audio output device - wired headphones;more_new
- the "ellipsis" button, which opens a list of additional buttons;camera_swap
- switching the camera between front and rear, and vice versa;more_btn
- selecting the camera and turning the flashlight on/off;resize_selfview_visible / resize_selfview_small
- enable/disable compact self-view mode.
To apply the icons in Assets, you need to specify the used NSBundle
in the property resources
.
self.tcsdk.resources = [NSBundle mainBundle];
In the example, three additional buttons are 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 tapping the ellipsis button, in the order they are arranged in the provided array. For an additional TCSDKExtraButton
, you can set the text, image, and a code block that executes when the user presses the button.
Additionally, this example demonstrates how to display any other UIViewController
on top of the conference window. By pressing any of the three 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. This sample code demonstrates how to launch the SDK by specifying a list of potential servers for connection. The example will connect to the first available running server from the list. During initialization with the method initWithViewController
, you can specify an arbitrary server string, and then in the method startWithServersList
, pass a string containing a list of server addresses separated by commas. In this case, the SDK will attempt to connect to the servers in the order they are listed.
You can subscribe to the onServerStatus
event to monitor the address cycling process. For "bad" addresses, connected=false
will be reported, and for the first "good" address, connected=true
will be indicated, stopping the process. This 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 into separate UIView
. It also shows a custom implementation of conference control buttons on the main window.
All you need to adjust the sizes and positions of other conference participants is to implement the TCWindowsDelegate
protocol method. This, along with setting the delegate in the windowsDelegate
property, is implemented directly in the ViewController:
self.tcsdk.windowsDelegate = self;
The property hideConfControls
is used to hide the default conference controls and create custom ones anywhere.
The property windowsDelegate
is used to adjust 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 by half by modifying the rectangle properties of TCSDKWindowRect
objects. Each object also has userId
and resolution
properties. The resolution
property contains the original resolution of the decoded video.
To place the window with conference participants and your own image anywhere, use the properties xview
and xsview
, which are specified as their parent elements.
3 UIViews have been added to the Storyboard:
pink
- includes buttons for conference management that partially replicate the functions of the standard control panel: End - terminates 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 thexview
property and therefore contains incoming video during the conference. You can specify any coordinates and dimensions.yellow
- is set in thexsview
property and thus contains your own image during the conference. You can specify any coordinates and dimensions you prefer.
To manage audio output devices, an Audio
button has been added, which is displayed only during a conference. When clicked, a UIAlertController
appears with cells populated with information about available audio devices (name and icon). To obtain the list of audio devices, the getAudioDeviceList
method is used. Clicking on a cell in this UIAlertController
will switch the current audio device to the selected one, specifying it in the audioDevice
property.
To switch the camera from front to rear (or vice versa), a Swap
button has been added, which is only displayed during a conference. When pressed, it triggers the method swapCamera
, which changes the current camera.
# Example 8. Chat
The example demonstrates the ability to send text messages using the method sendChatMessage
and handle new incoming messages in the event onChatMessageReceived
.
Implemented is the capability to send and receive messages from the main ViewController example, as well as in a separate chat window, ChatViewController. This window can be opened from the main window using the Open Simple Chat
button, or while in a conference, using the custom Chat
button. This button is created with 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.