Twilio migration guide (Android)

This guide walks you through how to migrate your existing Twilio Video implementation to the Vonage Video SDK. Vonage offers two ways to get started: Vonage’s Video API.

Overview

Twilio and Vonage Video APIs have very similar concepts. This starter guide aims to assist you in migrating your video application.

The main difference is that in Twilio you need to create a room SID whereas in Vonage you create a SessionID. You then create authentication tokens which are used on the client side to connect to rooms in Twilio or sessions in Vonage.

The following diagrams detail the main differences:

Vonage Twilio migraiton illustration 1Vonage Twilio migraiton illustration 1

Get Video SDK credentials

Create a developer Account to access the developer portal. To get started with video you need to create an application. You can follow the create an application guide to obtain your application ID and private key.

Install the SDK

Replace the Twilio video SDK reference in your Gradle file (build.gradle) with the Vonage video SDK.

Thus from implementation 'com.twilio:video-android:7.5.1' to implementation ‘com.opentok.android:opentok-android-sdk:2.27.0’.


Enable required permissions

If not already done, please enable the following permission in the AndroidManifest.xml file:

Authentication

The Vonage Video SDK uses tokens to authenticate users. When generating a token you can set the user’s role (subscriber, publisher, or moderator). Optionally, you can also assign a string of metadata to the token (i.e. to identify the connected client).Please refer to our Token Creation Overview article for options you can use when generating tokens. Tokens are generated on the server-side and sent to the client-side. Visit the Server-side SDKs guides to learn more.

Create a video session

A session is like a room, clients with the same session ID will be able to communicate with each other. Like tokens, sessions are created on the server side.

Please refer to our Creating a session guide to learn more as well as the various configuration options available.

To create a session and generate a token, use one of our server SDKs.

Connect to a video session

To connect a client endpoint to a Vonage Video session you need an application ID, session ID, and token.

These credentials can be retrieved from the Dashboard and hardcoded in the application for development, however for a production environment use the server SDKs to provide the session ID and token (check Basic-Video-Chat project).

Twilio Vonage terminology mapping

TwilioVonage
RoomSession
ParticipantsSubscriber(s) + Publisher(s)
TracksStream
RemoteTracksSubscribers(s).stream
LocalTracksPublisher(s).stream

Connecting to a video session

Connecting and managing video streams are done using event handler.

There are three key event listeners you need to implement:

  • Session.SessionListener (private Session mSession;)
  • PublisherKit.PublisherListener (private Publisher mPublisher;)
  • SubscriberKit.SubscriberListener (private Subscriber mSubscriber;)

SessionListener

The Session.SessionListener methods are used to handle events involving the addition and removal of participants (subscribers and publishers).

This is equivalent to Twilio's Room.Listener event handler.

Below is the structure of the exposed SessionListener interface:

PublisherListener

The PublisherKit.PublisherListener is used to implement logic to execute based on the creation and end streams.

Below is the structure of the exposed PublisherListener interface:

SubscriberListener

The SubscriberKit.SubscriberListener is used to implement logic to execute when a subscriber joins a stream.

Below is the structure of the exposed SubscriberListener interface:

Connecting to a session

You will need your APP_ID , SESSION_ID to connect to a video stream.

A TOKEN corresponding to the stream you will like to join is also required.

Twilio

Vonage

Publishing video

Vonage Video SDKs handle video quality tuning automatically, based on network conditions and device capabilities.

That said, you can configure certain properties, such as resolution, frame rate, and audio fallback. A single publisher object can handle both audio and video. You may selectively control audio or video using methods available with the publisher object.

Add publisher

Twilio:

Vonage:

Audio track only

Twilio

Vonage:

Video track only

Twilio:

Vonage:

Unpublish from session

Twilio:

Vonage:

Mute Publisher Audio

Twilio:

Vonage:

UnMute Publisher Audio

Twilio:

Vonage:

Mute Publisher Video

Twilio:

Vonage:

UnMute Publisher Video

Twilio:

Vonage:

Subscribe to a stream

When a remote participant (subscriber) connects to a session, the Session.SessionListener.onStreamReceived() callback is invoked with corresponding stream object.

Twilio:

Vonage:

Disconnecting from a session

Twilio:

Vonage:

onPause() and onResume() methods

Vonage:

Ideally onPause() and onResume() should be implemented in the MainActivity Class.

Screen sharing

An example app for screen sharing.

Text chat app

An example app for sending text.

More Info