Skip to content

Integration with Calls API

Lejla Solak edited this page Aug 5, 2024 · 6 revisions

Before utilizing RTC SDK, please ensure you've gone through the following tutorials as prerequisites:

  • First-time setup

  • Getting the SDK

  • Authentication

  • Permissions

    Prior to integrating with the Calls API, we recommend reading the Calls product documentation for a comprehensive understanding of this product.

    To utilize the Calls API, you'll first have to do some additional setup:

  • Create Calls Configuration: Create your Calls Configuration along with its corresponding Event Subscription.

  • Configure Event Subscription: Set up your Event Subscription to include a Notification Profile with a reference to your Event Webhook.

  • Handle Calls Events: Develop your backend application to handle the Calls Events using the Calls API. Whenever a new event occurs on the platform that your application needs to handle, the Event Webhook will be triggered, allowing your backend to respond accordingly.

    The Calls API provides you with ultimate freedom to incorporate your own business logic when managing calls, dialogs and conferences. These are some examples of more intricate use cases that can be implemented using the Calls API:

  • Comprehensive and granular control of WebRTC calls from your backend application

  • Easily join and remove WebRTC calls to and from conferences

  • Mix WebRTC calls into the same conferences with any other supported endpoints (Phone, SIP)

  • Implement routing logic for inbound WebRTC calls in your backend applications

  • Play text-to-speech, collect and send DTMF, or play audio files in WebRTC calls

Calls Configuration concept

Before starting to use the Calls API with WebRTC SDK, you'll need to create your own backend application and host it in your own environment, whether on premise or at your cloud hosting services.

Your backend application will be represented on our platform as a Calls Configuration, which is a logical entity containing:

  • a declaration of webhooks exposed by your application and their related authentication scheme, which Infobip will use to send real-time events about your calls and conferences and what happens in these,
  • a list of real-time events to which your application subscribes.

The following image provides a clear overview of your application integrated into the whole ecosystem.

Calls_Overview

Create your Calls Configuration identifier

To use your backend application as mentioned earlier, you will need to create the Calls Configuration logical entity through our Calls API. This Calls Configuration will be identified by the callsConfigurationId unique identifier on our platform, which you'll use when sending Calls API requests and setting up calls to define which application is interacting with the system.

To create your Calls Configuration on Infobip's platform, you can read our Calls API documentation for the /calls/1/configurations endpoint.

Using RTC SDK with Calls API

When utilizing the Calls API it is up to you to design your voice and video scenarios and implement them within your backend application. Your use cases can range from simple to complex, tailored to meet your specific requirements.

It's important to note that any Calls method you call through RTC SDK will trigger an event on your application's event webhook. Similarly, any HTTP request you send to the Calls platform from your application will trigger an event on your web application (through our SDK).

To make a call towards your backend application, the application using our Android SDK should call the callApplication method with the correct callsConfigurationId specified in the CallApplicationRequest.

String token = obtainToken();
InfobipRTC infobipRTC = InfobipRTC.getInstance();

CallApplicationRequest callApplicationRequest = new CallApplicationRequest(token, getApplicationContext(), "45g2gql9ay4a2blu55uk1628", new DefaultApplicationCallEventListener());
ApplicationCall applicationCall = infobipRTC.callApplication(callApplicationRequest);

When this code is triggered, your backend application will receive the CALL_RECEIVED event on its event webhook (provided you've subscribed to this event during Calls Configuration setup). Your backend application can handle it, and act accordingly using the Calls API.

You can also use the Calls API to initiate a call to a certain user by using the /calls/1/calls endpoint.

When receiving such a call on your web application as an incoming call, you can use the SDK's accept method to answer the call.

IncomingApplicationCallEventListener incomingApplicationCallEventListener = new IncomingApplicationCallEventListener() {
    @Override
    public void onIncomingApplicationCall(IncomingApplicationCallEvent incomingApplicationCallEvent) {
        IncomingApplicationCall incomingApplicationCall = incomingApplicationCallEvent.getIncomingApplicationCall();
        Log.d("WebRTC", "Received incoming application call from:  " + incomingApplicationCall.from());
        incomingApplicationCall.setEventListener(new DefaultApplicationCallEventListener());
        incomingApplicationCall.accept();
    }
};

Shortly after answering the call, you'll receive a CALL_ESTABLISHED event on your event webhook (provided you've subscribed to this event during Calls Configuration setup). At this moment, the call has been successfully established with your application.

Whenever you want to hang up the call, as earlier, you can do it both from the SDK and through the Calls API.

From the Calls API side, this is done by sending an HTTP POST request to our platform to the /calls/1/calls/:id/hangup endpoint. This will result in a CallHangupEvent on the SDK side, to inform you that the call has been hung up.

From the SDK side, you can use the hangup method to perform the hang-up action.

String token = obtainToken();
InfobipRTC infobipRTC = InfobipRTC.getInstance();

CallApplicationRequest callApplicationRequest = new CallApplicationRequest(
        token,
        getApplicationContext(),
        "45g2gql9ay4a2blu55uk1628",
        new DefaultApplicationCallEventListener()
);

ApplicationCall applicationCall = infobipRTC.callApplication(callApplicationRequest);
applicationCall.setEventListener(new DefaultApplicationCallEventListener() {
    @Override 
    public void onEstablished (CallEstablishedEvent callEstablishedEvent) {
        applicationCall.hangup();
    }
});

This will trigger the CALL_FINISHED event, which your event webhook will receive (provided you've subscribed to this event during Calls Configuration setup).

To check out which methods you can use through our SDK to control application calls, you can take a look at the ApplicationCall class.

To find a list of all the Calls API methods you can use, you can reference our Calls API documentation.

Tutorials

Migration guides

Reference documentation

Clone this wiki locally