VidyoPlatform
  • Getting Started
  • Building custom client web application using Connector SDK
  • Android Integration
  • Resources
  • Use-Cases
    • Closed Captioning
    • Virtual Background - Banuba SDK
    • Calls Recording
    • Automatic Reconnection
    • Call Moderation
      • UnlockRoom API
      • Lock Room API
      • SetRoomPIN API
      • Remove RoomPIN API
      • Request Moderator Role API
      • Remove Moderator Role
      • Soft Mute
        • Soft Mute Audio
        • Soft Mute Video
      • Hard Mute
        • Hard Mute Audio
        • Hard Mute Video
      • Recording
      • Drop Participant
    • Custom noise suppression in web applications
    • Android: Picture-in-picture Mode
    • New Generation Renderer
    • Integrating with Epic
  • Twilio to Vidyo Migration
    • Twilio JavaScript SDK to VidyoClient JavaScript SDK
    • Twilio Android SDK to VidyoClient Android SDK
Powered by GitBook
On this page
  • Install the SDK
  • Set permissions
  • Code Changes
  • Initialize the SDK
  • Join session/room
  • Video
  • Mute/Unmute Microphone
  • Event Listeners
  • Leave session
  1. Twilio to Vidyo Migration

Twilio Android SDK to VidyoClient Android SDK

PreviousTwilio JavaScript SDK to VidyoClient JavaScript SDK

Last updated 1 year ago

This guide walks you through how to migrate your existing to . To complement this guide, we have also developed a sample app that can switch between Twilio SDK and Vidyo SDK simply using a build-time configuration. That app provides a handy “translation guide” between Twilio and VidyoClient Android SDK.

Install the SDK

Download and install the VidyoClient SDK from the . For example, if you're building using Gradle or Groovy, add this line to your app/build.gradle file:

implementation fileTree(dir: 'libs', include: ['*.aar'])

and locate VidyoClient.aar SDK file under /app/libs/:

VidyoClient SDK has several dependencies have to be also included:

/* Camera X: Required for Vidyo */
var cameraxVersion = "1.2.1"
implementation("androidx.camera:camera-camera2:$cameraxVersion")
implementation("androidx.camera:camera-lifecycle:$cameraxVersion")
implementation("androidx.camera:camera-extensions:$cameraxVersion")
implementation("androidx.concurrent:concurrent-futures-ktx:1.1.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")

If you like, you can also remove the Twilio SDK from your project with the following:

implementation 'com.twilio:video-android:<version>'

Set permissions

Ensure that you have all of the Android system permissions required by the VidyoClient SDK in your project (you can ignore permissions that you already have):

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />

If your project uses proguard, add the following rules to your project:

-keep class com.vidyo.** { *; }
-dontwarn com.vidyo.**

Code Changes

The code snippets below illustrate the mappings between the Vidyo and Twilio SDKs. Low-level functionality may differ between the two platforms, so the mappings may not be perfectly accurate for all use cases.

Initialize the SDK

In order to use The VidyoClient SDK, you must first initialize the Core SDK:

ConnectorPkg.initialize();
ConnectorPkg.setApplicationUIContext(this);

This is usually done when your app starts, but you can place it wherever it is appropriate for your implementation.

Initialize Connector, SDK instance. Vidyo SDK automatically sets the audio, video, and dominant speaker parameters, so the user does not need to set these parameters explicitly:

vidyoConnector = new Connector(binding.vidyoVideoView, 
Connector.ConnectorViewStyle.VIDYO_CONNECTORVIEWSTYLE_Default, 8, logLevel, "", 0);

There is no equivalent of this in the Twilio Video SDK, so it is important to find the correct place in your app to add initialization logic.

Join session/room

Twilio uses JSON Web Tokens (JWT) to generate a token for users to join sessions. Vidyo follows a different model – a meeting room is created on a backend middleware (referred to as Vidyo Portal) which generates a meeting link, and users join the room through their browser by clicking on the meeting link.

Twilio requires an Access Token to join a meeting room.

Generating Access Tokens with the Twilio CLI is a quick way to get an Access Token for testing and development purposes.

val connectOptions = ConnectOptions.Builder(accessToken)
    .videoTracks(localVideoTracks)
    .audioTracks(localAudioTracks)
    .roomName(sessionId)
    .build()

Video.connect(context, connectOptions, roomListener)

Joining a meeting in Vidyo SDK requires the following:

  1. URL of the VidyoPortal that owns/created the room.

  2. Room name

  3. Room pass code (optional). If this is set for a specific room, then users must enter the passcode to enter the room. This pass code is received as part of the meeting invitation.

String portal = BuildConfig.VIDYO_PORTAL;
String displayName = BuildConfig.VIDYO_DISPLAY_NAME;
String roomKey = BuildConfig.VIDYO_ROOM;
String roomPin = BuildConfig.VIDYO_ROOM_PIN;

vidyoConnector.connectToRoomAsGuest(portal, displayName, roomKey, roomPin, this);

In a real production setting, the room creation/meeting link generation functionality is handled by a backend VidyoPlatform component referred to as VidyoPortal.

The VidyoPortal provides a web interface (and REST/SOAP APIs) for creating meeting rooms, generating meeting links & moderating meetings.

Video

Moreover, Vidyo has a Composite Renderer concept where you just have to pass a container ViewGroup reference e.g. binding.vidyoVideoView and VidyoClient will handle all the Local/Remote participant composition for you.

Rendering local video

Twilio has a concept of video and audio tracks:

localAudioTrack = LocalAudioTrack.create(this, true, LOCAL_AUDIO_TRACK_NAME);

cameraCapturerCompat = new CameraCapturerCompat(this, CameraCapturerCompat.Source.FRONT_CAMERA);
localVideoTrack = LocalVideoTrack.create(this,true, cameraCapturerCompat, LOCAL_VIDEO_TRACK_NAME);

localVideoTrack.addSink(primaryVideoView);

Vidyo has a selectLocalCamera function to select which of the connected cameras to use in the call:

vidyoConnector.selectLocalCamera(localCamera);

Note: local camera list can be obtained from the: onAdded(LocalCamera localCamera) device events callback.

The biggest difference between the implementations is the amount of setup that is required for Twilio. While Twilio requires manually setting up a CameraCapturerCompat and LocalVideoTrack to specify your input sources, this is all handled internally within the VidyoClient SDK.

Turn the camera off

localVideoTrack.enable(false);

However, you also have to manually hide the renderer.

Vidyo’s implementation requires you to call a single API function to disable the local camera:

vidyoConnector.setCameraPrivacy(true);

Render remote user video

Twilio uses onParticipantConnected and onVideoTrackSubscribed event listeners to determine which remote videos to render.

@Override
public void onParticipantConnected(@NonNull Room room, @NonNull RemoteParticipant remoteParticipant) {
    addRemoteParticipant(remoteParticipant);
}

…

@Override
public void onVideoTrackSubscribed(
                    @NonNull RemoteParticipant remoteParticipant,
                    @NonNull RemoteVideoTrackPublication remoteVideoTrackPublication, @NonNull RemoteVideoTrack remoteVideoTrack) {
    addRemoteParticipantVideo(remoteVideoTrack);
}

…

/*
* Set primary view as renderer for participant video track
*/
private void addRemoteParticipantVideo(VideoTrack videoTrack) {
    moveLocalVideoToThumbnailView();
    primaryVideoView.setMirror(false);
    videoTrack.addSink(primaryVideoView);
}

Based on the Composite Renderer concept, Vidyo manages the video rendering part automatically, but the user can also register callbacks to listen to, for example, when a participant joins or leaves a room (later in this guide).

Mute/Unmute Microphone

Since Twilio API is track based, you have to disable the track individually:

localAudioTrack.enable(false);

Use the setMicrophonePrivacy function to set the selected microphone state:

vidyoConnector.setMicrophonePrivacy(true);

Event Listeners

Twilio has event listeners for room and participant management, allowing you to detect changes that occur during a meeting. In Twilio there are multiple listeners depending on the area of functionality you are using. So, it may require some refactoring to consolidate everything into one place.

Room.Listener interface:
- onConnected
- onReconnecting
- onReconnected
- onConnectFailure
- onDisconnected
- onParticipantConnected
- onParticipantDisconnected
[...]
RemoteParticipant.Listener interface:
- onVideoTrackSubscribed
- onVideoTrackUnsubscribed
[...]

Vidyo supports the concept of event listeners. Commonly used event listeners include:

  • Connection Event Listener registered during conference join:

Connector.IConnect interface: 

- onSuccess
- onDisconnected
- onFailure
  • Device Event Listeners:

vidyoConnector.registerLocalCameraEventListener(this);
Connector.IRegisterLocalCameraEventListener interface:
- onLocalCameraAdded
- onLocalCameraRemoved
- onLocalCameraSelected
- onLocalCameraStateUpdated
vidyoConnector.registerLocalMicrophoneEventListener(this);
Connector.IRegisterLocalMicrophoneEventListener interface:
- onLocalMicrophoneAdded
- onLocalMicrophoneRemoved
- onLocalMicrophoneSelected
- onLocalMicrophoneStateUpdated
vidyoConnector.registerLocalSpeakerEventListener(this);
Connector.IRegisterLocalSpeakerEventListener interface:
- onLocalSpeakerAdded
- onLocalSpeakerRemoved
- onLocalSpeakerSelected
- onLocalSpeakerStateUpdated
  • Participant Events Listener:

vidyoConnector.registerParticipantEventListener(this);
Connector.IRegisterParticipantEventListener interface: 
- onParticipantJoined
- onParticipantLeft
- onDynamicParticipantChanged
- onLoudestParticipantChanged

Leave session

To end the session, call the corresponding disconnect method:

room.disconnect();
vidyoConnector.disconnect();

View instructions here for how to .

Please refer to to see who to create a meeting room.

While Twilio requires to set the quality of the video, Vidyo handles the video quality automatically based on network conditions and device capabilities. In low bandwidth conditions Vidyo prioritizes audio over video, and shared content video tiles over participant video. Vidyo also supports configuration options to limit maximum resolution of local or remote video.

generate an Access Token using the Twilio CLI
Getting Started Guide
additional configuration
Twilio Video implementation
Vidyo Android SDK
Developer Portal