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:
- You have access to ConnectyCube account. If you don’t have an account, sign up here.
- 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
Сonnect SDK js file as a normal script:
Initialize SDK
Initialize the SDK with your ConnectyCube application credentials. You can access your application credentials in ConnectyCube Dashboard:
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
Register a user
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 login
method:
Now that the user is authorized in the application, they can proceed with chat creation and messaging 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:
Step 4: Connect WebRTC lib
For Android - there is nothing extra required. Android Cordova WebView supports all the WebRTC API stack.
For iOS - a cordova-plugin-iosrtc has to be used.
Step 5: Create video session
In order to use Video Calling API you need to create a call session object - choose your opponents with whom you will have a call and a type of session (VIDEO or AUDIO):
Step 6: Access local media stream
To have a video chat session you need to get an access to the user’s devices (webcam / microphone):
This method lets the browser ask the user for permission to use devices. You should allow this dialog to access the stream. Otherwise, the browser can’t obtain access and will throw an error for getUserMedia
callback function.
For more information about possible audio/video constraints, here is a good code sample from WebRTC team how to work with getUserMedia constraints: https://webrtc.github.io/samples/src/content/getusermedia/resolution/
Step 7: Initiate call
Initiate Call function sets up the foundational connection between the caller and the selected opponents:
The extension is used to pass any extra parameters in the request to your opponents.
After this, your opponents will receive a callback call:
Or if your opponents are offline or did not answer the call request:
Step 8: Accept a call
To accept a call the following code snippet is used:
After this, you will get a confirmation in the following callback:
Also, both the caller and opponents will get a special callback with the remote stream:
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!