# Examples for Cordova

The examples are cross-platform Cordova application projects. Each example consists of three parts: an Android part, an iOS part, and a common JS code.

  • The Android section includes a project for the Android Studio IDE;

  • The iOS section includes a project for the Xcode IDE.

  • The JS part includes the UI, the main logic code, and the SDK usage code.

All you need to start working with TrueConf Mobile SDK is to obtain an SDK instance in JS using the getInstance function:

let sdkBuilder = cordova.require('trueconf-sdk-plugin.sdk');
sdkBuilder.getInstance().then(instance => {
  sdk = instance; // save the SDK instance for further use
}, error => console.log(error));

The SDK initialization is performed by calling the start function. Following the initialization, the onSDKReady method is used to set up event handling with the addEventListener function:

onSDKReady: function() {
  sdk.addEventListener("onLogin", this.onLogin.bind(this));
  sdk.addEventListener("onLogout", this.onLogout.bind(this));
  sdk.addEventListener("onServerStatus", this.onServerStatus.bind(this));
  sdk.addEventListener("onInvite", this.onInvite.bind(this));
}

The iOS project is ready to use. Simply open the xcworkspace file in Xcode from the platforms/ios folder.

The Android project requires additional configuration: you need to specify the repository address and add the method calls for registerApp and setFallbackActivity (more details can be found here).

# 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 receive incoming video calls and invitations to group conferences.

The example includes the core functionality of TrueConf Mobile SDK.

  1. Processing events:

    • onServerStatus - monitoring the connection status to the server;

    • onLogin - tracking login status;

    • onLogout - monitoring of logout status;

    • onInvite - handles incoming calls and invitations to a group conference.

  • Clicking the corresponding buttons triggers the methods:

    • start - SDK initialization;

    • loginAs - authentication with TrueConf ID and password;

    • logout - user deauthorization;

    • callTo - call to a user whose TrueConf ID is entered in the corresponding input field.

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 example includes the core functionality of TrueConf Mobile SDK.

  1. Processing events:

    • onServerStatus - monitoring the connection status to the server;

    • onStateChanged - client state tracking;

    • onLogin - tracking login status;

    • onLogout - monitoring of logout status;

    • onInvite - handles incoming calls and invitations to a group conference.

  • Clicking the corresponding buttons triggers the methods:

    • start - SDK initialization;

    • parseProtocolLink - execution of a sequence of commands in a TrueConf link.

# 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 example is based on a single event handler block onUserStatusUpdate, which is triggered when the server sends a user's status update. The getUserStatus method is used to add any user to the watch list. The implemented code allows you to track and display changes in a specific user's status in the table, handle the addition of new users, and add any user for tracking.

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 receive incoming video calls and invitations to group conferences.

The example includes the core functionality of TrueConf Mobile SDK.

  1. Processing events:

    • onServerStatus - monitoring the connection status to the server;

    • onLogin - tracking login status;

    • onLogout - monitoring of logout status;

    • onInvite - processing incoming calls and invitations to a group conference;

    • onUserStatusUpdate - tracking changes in user statuses from the address book or watch list.

  • Clicking the corresponding 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 it to the watchlist for 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:

  1. Receiving an invitation via an incoming call functions the same as a regular onInvite call with acceptCall confirmation.

  2. By conference ID using the joinConf method.

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

  4. Use the method scheduleLoginAs by 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.

The example includes the core functionality of TrueConf Mobile SDK.

  1. Processing events:

    • onServerStatus - monitoring the connection status to the server;

    • onLogin - tracking login status;

    • onLogout - monitoring of logout status;

    • onInvite - processing incoming calls and invitations to a group conference;

    • onConferenceStart - handles the moment of connecting to a conference;

    • onConferenceEnd - handles the moment of exiting a conference.

  • Clicking the corresponding buttons triggers the methods:

    • start - SDK initialization;

    • loginAs - authentication with TrueConf ID and password;

    • logout - user deauthorization;

    • joinConf - joining a conference by its ID.

# Example 5. Interface Customization

The example demonstrates how to add your own custom buttons and open your window on top of 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.

The example demonstrates adding a custom button and displaying a separate window over the conference window. The addExtraButton function takes the name of the custom button, and then in the onExtraButtonPressed event handler, the showAlertPage function is called to display a new window over the conference window - Activity for Android, UIViewController for iOS. In this case, these windows are created and configured directly in the SDK plugin: for Android, it's the DialogActivity class, and for iOS, it's the DialogViewController class. These classes can be edited.

# 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 receive incoming video calls and invitations to group conferences.

The example includes the core functionality of TrueConf Mobile SDK.

  1. Processing events:

    • onServerStatus - monitoring the connection status to the server;

    • onLogin - tracking login status;

    • onLogout - monitoring of logout status;

    • onInvite - processing incoming calls and invitations to a group conference;

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

  • Clicking the corresponding buttons triggers the methods:

    • start - SDK initialization;

    • loginAs - authentication with TrueConf ID and password;

    • logout - user deauthorization;

    • sendChatMessage - sends a chat message to the user whose TrueConf ID is entered in the corresponding input field.