- Local peer is a device running the app right now.
- Remote peer is an opponent device.
- Signaling. At this phase, the peers’ local IPs and ports where they can be reached (ICE candidates) are exchanged as well as their media capabilities and call session control messages.
- Discovery. At this phase, the public IPs and ports at which endpoints can be reached are discovered by STUN/TURN server.
- Establishing a connection. At this phase, the data are sent directly to each party of the communication process.
Please use this WebRTC Video Calling to make the Group Calls with 4 or fewer users. Because of Mesh architecture we use for multi-point where every participant sends and receives its media to all other participants, the current solution supports group calls with up to 4 people.
Before you begin
- Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
- Configure QuickBlox SDK for your app. Check out Setup page for more details.
- Create a user session to be able to use QuickBlox functionality. See Authentication page to learn how to do it.
- Connect to the Chat server to provide a signaling mechanism for Video Calling API. Follow our Chat page to learn about chat connection settings and configuration.
Initialize WebRTC
To be able to receive incoming video chat calls, you should initializeQBRTCClient and add WebRTC signaling to it.
- Java
- Kotlin
Manage calls
AddSessionCallbacksListener to your QBRTCClient to define session states. Learn more details about the event listener configuration in the Event listener section.
- Java
- Kotlin
QBRTCClient to process calls. To be sure that your app is ready for calls processing and Activity exists, use the following snippet in the Activity class.
- Java
- Kotlin
Local/remote video view
Set up two video chat layouts for remote and local video tracks to be able to show the video.- A remote video track represents a remote peer video stream from a remote camera app. Specify
userIdfor the remote camera app of the remote peer. - A local video track represents a local peer video stream from a local camera app. Specify
userIdfor the local camera app of the local peer.
XML
QBRTCSurfaceView allows using several views on the screen layout and overlapping each other. This is a good feature for group video calls.
QBRTCSurfaceView is a surface view (it extends org.webrtc.SurfaceViewRenderer class) that renders video track. It has its own lifecycle for rendering. It uses init() method for preparing to render and release() to release resources when the video track does not exist anymore.
QBRTCSurfaceView is automatically initialized after the surface is created (in surfaceCreated() method callback). You can manually initialize QBRTCSurfaceView using EGLContext getting from QBRTCClient. Use this only when Activity is alive and GL resources exist.
- Java
- Kotlin
release() should be called when video track is no more valid, for example, when you receive onConnectionClosedForUser() callback from QBRTCSession or when QBRTCSession is going to close. But you should call release() method before Activity is destroyed and while EGLContext is still valid. If you don’t call this method, the GL resources might leak.
Here are the few methods of the QBRTCSurfaceView:
- Java
- Kotlin
QBRTCSurfaceView, QBRTCVideoTrack and use:
- Java
- Kotlin
- Java
- Kotlin
Initiate a call
To call other users, you should create a call session with the user first usingcreateNewSessionWithOpponents() method. After that, you can start calling using startCall() method.
- Java
- Kotlin
onReceiveNewSession() via QBRTCClientSessionCallbacks (read above).
- Java
- Kotlin
Accept a call
If you accept an incoming call, your opponent receives anonCallAcceptByUser() callback.
- Java
- Kotlin
Reject a call
If you reject an incoming call, your opponent receives anonCallRejectByUser() callback.
- Java
- Kotlin
Ignore a call
If you neither accept nor reject an incoming call, the caller will receive an appropriate callback after a specific period of time. You can set interval usingQBRTCConfig.setAnswerTimeInterval() method.
- Java
- Kotlin
NoteIf you are already in the call, you still can receive other incoming requests. You can handle a current call session and use any logic you like to notify the user about incoming call attempts.
Render video stream to view
For managing video tracks, you should use theQBRTCClientVideoTracksCallbacks interface.
- Java
- Kotlin
- Java
- Kotlin
- Java
- Kotlin
Obtain audio tracks
For managing audio tracks, you should use theQBRTCClientAudioTracksCallback interface.
- Java
- Kotlin
- Java
- Kotlin
End a call
To end a call, use thehangUp()method.
- Java
- Kotlin
onReceiveHangUpFromUser() callback.
- Java
- Kotlin
Release resource
When you don’t want to receive and process video calls, for example, when a user is logged out, you have to destroyQBRTCClient. Call the destroy() method to unregister from receiving any video chat events and close existing signaling channels.
- Java
- Kotlin
Event listener
To process events such as incoming call, call reject, hang up, etc. you need to set up the event listener. The event listener processes various events that happen with call session or peer connection in your app. Using the callbacks provided by the event listener, you can implement and execute the event-related processing code. For example, theonCallAcceptByUser callback of QBRTCClient is received when a call has been accepted. This callback receives information about the call session, user ID who accepted the call, and additional key-value data about the user.
QuickBlox Android SDK persistently interacts with the server via XMPP connection that works as a signaling transport for establishing a call between two or more peers. It receives the callbacks of the asynchronous events which happen with the call and peer connection. This allows you to track these events and build your own video calling features around them.
To track call session events, you should use SessionCallbacksListener. The inherited event listeners for a call session are QBRTCClientSessionCallback and QBRTCSessionConnectionCallbacks.
QBRTCClientSessionCallback
The supported call session event callbacks of QBRTCClientSessionCallback along with their parameters as well as shows how to add the listener.
The following code lists all supported event callbacks for a call session along with their parameters as well as shows how to add the listener.
- Java
- Kotlin
QBRTCSessionConnectionCallbacks listener are listed in the table below.
The following code lists all supported event callbacks for a call session along with their parameters as well as shows how to add the listener.
- Java
- Kotlin
Call session states
The following table lists all supported call session connection states.Peer connection states
To get peer connection state for a particular peer, use the code snippet below.- Java
- Kotlin
Resources
A regular call workflow.