Twilio migration guide (iOS)

This guide walks you through migrating your existing Twilio video application to Vonage Video.

For the most flexibility and versatility in programming your video solution, the Vonage Video API iOS SDK has you covered.

If your requirements extend beyond simple video functions and include features like broadcasting, SIP integration, media processing, and customizable stream settings, you'll discover that the Vonage Video iOS SDK offers unmatched power and flexibility.

Overview

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

One key difference between Twilio and Vonage video implementation is the use of room SID, this is a session ID when it comes to Vonage. We will look at how to generate a sessionID in a later section.

You will also need an authentication token when connecting a client to an active session.

The diagram below illustrates the architectural differences between Twilio and Vonage video.

Vonage Twilio migraiton illustration 1Vonage Twilio migraiton illustration 1

Twilio Vonage terminology mapping

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

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

You can install the Vonage Video iOS SDK through the Swift Package Manager or Cocoapods:

Using Swift Package Manager

To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter the repository URL:

https://github.com/opentok/vonage-client-sdk-video.git

Using Cocoapods

When adding the SDK using CocoaPods edit the Podfile and add the following line:

pod 'OTXCFramework'

Save changes to the Podfile, open the root directory of the project in the terminal/command-line and run:

pod install

This should pull in the Vonage video SDK and its dependencies.

You can now add the SDK to your view controller. In Xcode, open your ViewController.swift file and, at the very top of the file, add the following lines to import the video library:

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 guide to learn how to generate tokens. Tokens are generated on the server-side and then used on the client-side. Visit the Server-side SDKs guides to learn more.

Create a video session

A session is like a room. All clients using 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.

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

You can declare all your keys as property in your ViewController.swift file:

Connect to a video session

With all your keys set you can now connect to an active video session.

You must do this before you can publish your audio-video stream to the session or view other participants streams.

Twilio

Vonage

Event Listeners

Vonage and Twilio have delegate protocols to help you maintain the state of a session/call for all participants connected to a session.

Session/Room connection changes

Twilio

Vonage

Publishing Video

When a user is connected to an active session, it can publish an audio-video stream to the session, using the device's camera and microphone:

This is achieved by adding a publisher property to the ViewController class:

Modify the implementation of the OTSessionDelegate.sessionDidConnect(_:) method to include code to publish a stream to the session. Here is an example:

The Vonage Video SDK handles the video quality automatically, based on network conditions and device capabilities. That said, you can configure certain properties, such as resolution, frame rate, and audio fallback.

Next we will implement methods from the OTPublisherDelegate protocol. This protocol includes methods for handling events related to the publisher.

To do so you can add the following code to your ViewController.swift file:

Turn the camera on/off

The Vonage SDK offers simple methods to control the camera.

Twilio

Vonage

Render a remote user video

Similar to Twilio's participantDidConnect and didSubscribeToVideoTrack event listeners, Vonage also triggers connectionCreated and streamCreated events when a remote participant connects to the session and starts sending video.

Twilio

Vonage

Audio

Vonage manages both audio and video using a single Publisher object. When you start publishing with the default options, the SDK publishes both audio and video. However, if you would prefer to have an audio-only session, you may configure the publisher object to not publish Video.

Mute microphone

With Twilio, you must get the audio track to mute the microphone. Vonage simplifies this by providing a single invocable method.

Twilio

Vonage

Unmute microphone

Similarly, with Twilio Video, you must get the audio track to unmute the microphone. Vonage simplifies this by providing a single invocable method.

Twilio

Vonage

Text chat

You can exchange data (i.e. text chat messages or custom JSON messages) between individual participants in a session, as well as all participants in a session.

The following method sends a message to clients connected to the session. Each signal is defined by a string type identifying the type of message (in this case "chat") and a string containing the message:

When another client connected to the session sends a message, the implementation of a callback from OTSessionDelegate allows you to receive the message:

Leave and End sessions The code below shows how to end an active session (disconnect a user from a session).

Twilio

Vonage

More information: