Introduction to JavaScript SDK

Overview

Integration with the backend has to be done following a strict internal protocol. All kinds of messages are exchanged in a well-defined binary format. We use a Connection class to abstract all the network-related stuff.

Real-time updates

Real-time updates are the way we update our local user state about any transient or persistent change and how we make our applications react to specific changes. For example, when a call offer is received by a user, you want to allow your user to accept, decline, mute, etc.

See below what kinds of updates our backend support.

Transient

Updates that notify about any transient state (i.e. a call offer was received, the user started typing a message):

/**
 * Traits:
 *
 * - updates.OrganizationUpdate
 * - tpl::InstantUpdate
 */
export interface TransientUpdateOffer {
  readonly _id: -115912433;
  readonly _name: "updates.transientUpdateOffer";
  readonly _type: "updates.TransientUpdate";
  readonly organizationId: number;
  readonly peer: TPeer;
  readonly callParticipant: TCallParticipant;
  /**
   * call identifier
   */
  readonly legacyCallId: number;
  readonly callUuid: string;
  readonly date: number;
  readonly offer: TOffer;
}

Persistent

Updates that notify about a permanent change of an entity. See below an example of a:

Synchronization

Imagine the following scenario:

  1. You are connected and receiving messages, making calls, etc.

  2. The user loses connection with the server for 10 hours

What happened during the time this user was offline and unable to receive any update from the backend? A new group might've been created with this user, new messages from his contacts might have accepted a meeting request.

We need to be able to get our local data up-to-date with the current user state. Our backend offers an updates API so we can synchronize with the backend. Please see an example of how to do that below:

This is only valid for persistent updates.

Bot Integration

Our backend has bultin support for a bots API. You can use our MS Bot Framework adapter to create your own bot. See an example below on how to achieve that:

Connection

Connection will deal with all the means on how to send or receive messages appropriately. That will all depend on the layer version selected during the class instantiation. See a small example on how to instantiate the Connection class:

After connection is created, you can, for example, authenticate using your phone number:

WebAssembly

Following our protocol guidelines, we need to perform encryption every time we send or receive a message. To make sure we're able to keep a certain performance standard, we compile OpenSSL + custom C99 code to WebAssembly so our users can take advantage of the features provided by this technology.

To initialize the protocol WebAssembly JS runtime, you can do so by using the Native class:

This class will be used by the internal implementation of the protocol to perform all kinds of low-level stuff using WebAssembly.

Authentication Key

Before you can actually start sending messages, you need to generate an authentication key. During this process, for a short period, there will be unencrypted communication with the backend.

Please see below an example of how to generate an authentication key:

Layers

Our backend can provide backward compatibility with older clients. So if you've developed a client targetting version 1.8.0 and it has been updated to a version 2.0.0, your client targetting the old version will continue to be stable.

Worth noticing that you're free to use the newer 2.0.0 version as well when you're ready.

Last updated