Examples for Cordova

TrueConfAbout 9 min

Examples for Cordova

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

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

  • The iOS section includes a project for Xcode IDE;

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

All you need to get started with TrueConf Mobile SDK is to obtain an instance of the SDK 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 done by calling the start function. After initialization, event handling is configured in the onSDKReady method using 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 setup: you need to specify the repository address and add the method calls registerApp and setFallbackActivity (detailed information is provided here).

Example 1. Demonstration of the main SDK features

A single-page application implementing the main features of TrueConf Mobile SDK:

  1. Initialization and connection to the server.

  2. Tracking client statuses.

  3. Connect to the server, log in as a user, and log out by pressing 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 server connection status;

    • onLogin - tracking login status;

    • onLogout - tracking logout status;

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

  2. Clicking the respective 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 corresponding input field.

Example 2. Demonstrating the use of trueconf links

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

  1. Initializing the SDK without specifying a server.

  2. Processing the entered trueconf link when the button is clicked.

The example includes the core functionality of TrueConf Mobile SDK:

  1. Processing events:

    • onServerStatus - monitoring the server connection status;

    • onStateChanged - client state tracking;

    • onLogin - tracking login status;

    • onLogout - tracking logout status;

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

  2. Clicking the respective buttons triggers the methods:

    • start - SDK initialization;

    • parseProtocolLink - executes a sequence of commands for a TrueConf link.

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 operates based on a single event handler block, onUserStatusUpdate, which is executed when the server sends a user's status. To monitor any user, the getUserStatus method is used. This implemented code allows tracking and displaying changes in a specific user's status in the table, handling the addition of new users, and adding any user for monitoring.

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 logging in as a user.

  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 server connection status;

    • onLogin - tracking login status;

    • onLogout - tracking logout status;

    • onInvite - handles incoming calls and invitations to group conferences;

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

  2. Clicking the respective buttons triggers the methods:

    • start - SDK initialization;

    • loginAs - authentication using TrueConf ID and password;

    • logout - user deauthorization;

    • getUserStatus - retrieve the user's status and add it to the watch list in 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 allows connecting only to existing conferences on the server.

There are four ways to connect:

  1. Receiving an invitation via an incoming call, similar to 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 method parseProtocolLink.

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

The example includes the core functionality of TrueConf Mobile SDK:

  1. Processing events:

    • onServerStatus - monitoring the server connection status;

    • onLogin - tracking login status;

    • onLogout - tracking logout status;

    • onInvite - handles incoming calls and invitations to group conferences;

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

    • onConferenceEnd - handles the moment of exiting the conference.

  2. Clicking the respective buttons triggers the methods:

    • start - SDK initialization;

    • loginAs - authentication using TrueConf ID and password;

    • logout - user deauthorization;

    • joinConf - joining a conference by its ID.

Example 5: Interface Customization

The example demonstrates how you can 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.

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

Example 6. Chat

A single-page application implementing the main features of TrueConf Mobile SDK:

  1. Initialization and connection to the server.

  2. Tracking client statuses.

  3. Connect to the server, log in as a user, and log out by pressing the corresponding buttons.

  4. Sending a message to another user via 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 server connection status;

    • onLogin - tracking login status;

    • onLogout - tracking logout status;

    • onInvite - handles incoming calls and invitations to group conferences;

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

  2. Clicking the respective 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 corresponding input field.