Skip to content

Make first call

ConnectyCube Video Calling Peer-to-Peer (P2P) API provides a solution for integrating real-time video and audio calling into your application. This API enables you to create smooth one-on-one and group video calls, supporting a wide range of use cases like virtual meetings, telemedicine consultations, social interactions, and more. The P2P approach ensures that media streams are transferred directly between users whenever possible, minimizing latency and delivering high-quality audio and video.

If you’re planning to build a new app, we recommend starting with one of our code samples apps as a foundation for your client app.
If you already have an app and you are looking to add chat and voice/video calls to it, proceed with this guide. This guide walks you through installing the ConnectyCube SDK in your app, configure it and then initiating the call to the opponent.

Before you start

Before you start, make sure:

  1. You have access to ConnectyCube account. If you don’t have an account, sign up here.
  2. An app created in ConnectyCube dashboard. Once logged into your ConnectyCube account, create a new application and make a note of the app credentials (app ID, auth key, and auth secret) that you’ll need for authentication.

Step 1: Configure SDK

To use chat in a client app, you should install, import and configure ConnectyCube SDK.

Note: If the app is already created during the onboarding process and you followed all the instructions, you can skip the ‘Configure SDK’ step and start with Create and Authorise User.

Install SDK

To get the ConnectyCube SDK project running you will need Android Studio and Maven installed.

The repository https://github.com/ConnectyCube/connectycube-android-sdk-releases contains binary distributions of ConnectyCube Android SDK and an instruction how to connect SDK to your project. Check it out.

Include reference to sdk repository in your build.gradle file at the app level (top level):

repositories {
maven {
url "https://github.com/ConnectyCube/connectycube-android-sdk-releases/raw/master/"
}
}

Then include dependencies to particular sdk-modules in build.gradle project file:

dependencies {
implementation "com.connectycube.sdk:connectycube-android:2.0.0-beta05"
}

Import SDK

Add the following import statement to start using all classes and methods.

import com.connectycube.ConnectyCubeAndroid;

Initialize SDK

Initialize the SDK with your ConnectyCube application credentials. You can access your application credentials in ConnectyCube Dashboard:

ConnectyCubeAndroid.init(APP_ID, AUTH_KEY, AUTH_SECRET, context = applicationContext)

Step 2: Create and Authorise User

To make API requests, firstly you need to create and authenticate a user who will initiate a call later.

Create an application session

ConnectyCube.createSession({ session -> }, { error -> })

Register a user

val userTags = listOf("iphone", "apple")
val userToSignUp = ConnectycubeUser(login = "marvin18", password = "supersecurepwd").apply {
email = "awesomeman@gmail.com"
fullName = "Marvin Simon"
phone = "47802323143"
website = "https://dozensofdreams.com"
tags = userTags.joinToString(",")
}
ConnectyCube.signUp(userToSignUp, { user -> }, { error -> })

Create a user’s session

To allow users to proceed with any actions within the application, you need to create a session for them. Having created an application session, you need to upgrade it to a user session by calling signIn method:

val userToLogin = ConnectycubeUser(login = "marvin18", password = "supersecurepwd")
ConnectyCube.signIn(userToLogin, { user -> }, { error -> })

Now that the user is authorized in the application, they can proceed with chat creation, messaging, voice and video calls with opponent(s).

Step 3: Connect User to chat

Connecting to the chat is an essential step in enabling real-time communication.

To start using Video Calling API you need to connect user to Chat as ConnectyCube Chat API is used as a signalling transport for Video Calling API:

val user = ConnectycubeUser().apply {
id = 21
password = "supersecurepwd"
}
// or just
// val user = user {
// id = 21
// password = "supersecurepwd"
//}
ConnectyCube.chat.login(user, {}, { ex -> Log.d(tag, "login ex= $ex") })

Step 4: Permissions to access camera, microphone and internet

Before starting the audio / video calling with the opponent(s), the video chat module requires camera, microphone and internet permissions. Make sure you add relevant permissions to your app manifest:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />

You can get more info on how to work with app permissions at Android Permissions Overview

Step 5: Initiate a call

To call users, you should create a session and start a call:

val opponents: MutableList<Int> = ArrayList()
opponents.add(21)
// User can pass an additional info along with the call request
val userInfo: HashMap<String, String> = HashMap()
userInfo["key1"] = "value1"
//Init session
val session = P2PCalls.createSession(opponents, CallType.VIDEO)
session.startCall(userInfo)

After this, your opponents will receive a call request callback onReceiveNewSession via RTCClientSessionCallbacks.

Step 6: Accept a call

You will receive all incoming call requests in RTCClientSessionCallbacks.onReceiveNewSession(session) callback.

To accept the call request use the following code snippet:

// RTCCallSessionCallback
override fun onReceiveNewSession(session: P2PSession) {
// obtain received user info
// val userInfo = session.getUserInfo()
// set your user info if needed
val userInfo = HashMap<String, String>()
userInfo["key1"] = "value1"
// Accept the incoming call
session.acceptCall(userInfo)
}

After this, you will receive an accept callback:

// RTCSessionEventsCallback
override fun onCallAcceptByUser(session: P2PSession,
opponentId: Int,
userInfo: Map<String, String?>?) {
}

Great work! You’ve completed the essentials of making a call in ConnectyCube. From this point, you and your opponents should start seeing and hearing each other.

What’s next?

To enhance your calling feature with advanced functionalities, such as call recording, screen sharing, or integrating emojis and attachments during calls, follow the API guides below. These additions will help create a more dynamic and engaging experience for your users!