Skip to content

InfobipRTC

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

registerForActiveConnection(token, context, incomingCallEventListener)

Description

Starts listening for incoming calls using active WebSocket connection to Infobip WebRTC platform.

Arguments

  • token: String - Authentication token generated by client's app via Infobip's HTTP /webrtc/1/token endpoint.
  • context: Context - Instance of the android.content.Context class.
  • incomingCallEventListener: IncomingCallEventListener - Interface defining a method that will be executed once an incoming call event is received.

Returns

  • N/A

Example

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

InfobipRTC infobipRTC = infobipRTC.getInstance();
infobipRTC.registerForActiveConnection(
    token,
    getApplicationContext(),
    new IncomingCallEventListener() {
        @Override
        public void onIncomingCall(IncomingCallEvent incomingCallEvent) {
            IncomingCall incomingCall = incomingCallEvent.getIncomingCall();
            Log.d("WebRTC", "Received incoming call from:  " + incomingCall.source());
            incomingCall.setEventListener(new DefaultCallEventListener());
            incomingCall.accept(); // or incomingCall.decline();
        }
    }
);



registerForActiveConnection(token, context, incomingApplicationCallEventListener)

Description

Starts listening for incoming application calls using active WebSocket connection to Infobip WebRTC platform.

Arguments

  • token: String - Authentication token generated by client's app via Infobip's HTTP /webrtc/1/token endpoint.
  • context: Context - Instance of the android.content.Context class.
  • incomingApplicationCallEventListener: IncomingApplicationCallEventListener - Interface defining a method that will be executed once an incoming application call event is received.

Returns

  • N/A

Example

String token = obtainToken();
InfobipRTC infobipRTC = InfobipRTC.getInstance();
infobipRTC.registerForActiveConnection(
    token,
    getApplicationContext(),
    new IncomingApplicationCallEventListener() {
        @Override
        public void onIncomingApplicationCall(IncomingApplicationCallEvent incomingApplicationCallEvent) {
            IncomingApplicationCall incomingApplicationCall = incomingApplicationCallEvent.getIncomingApplicationCall();
            Log.d("WebRTC", "Received incoming call from:  " + incomingApplicationCall.from());
            incomingApplicationCall.setEventListener(new DefaultApplicationCallEventListener());
            incomingApplicationCall.accept(); // or incomingApplicationCall.decline();
        }
    }
);



enablePushNotification(token, context, pushConfigId)

Description

Enable push notifications on a physical device for receiving incoming call events.

Arguments

Returns

  • N/A

Example

String token = obtainToken();
InfobipRTC infobipRTC = InfobipRTC.getInstance();
infobipRTC.enablePushNotification(token, getApplicationContext(), "454d142b-a1ad-239a-d231-227fa335aadc3");



enablePushNotification(token, context, pushConfigId, listener)

Description

Enable push notifications on a physical device for incoming call events. Event listener passed as the last parameter is used to observe whether the registration for push notifications was successful or not.

Arguments

Returns

  • N/A

Example

String token = obtainToken();
InfobipRTC infobipRTC = InfobipRTC.getInstance();
infobipRTC.enablePushNotification(
    token,
    getApplicationContext(),
    "454d142b-a1ad-239a-d231-227fa335aadc3",
    result -> Log.d("WebRTC", String.format("Push registration result: %s", result.getStatus()))
);



disablePushNotification(token, context)

Description

Disable push notifications for the device. After this, the device will no longer be able to receive push notifications.

Arguments

  • token: String - Authentication token generated by client's app via Infobip's HTTP /webrtc/1/token endpoint.
  • context: Context - Instance of the android.content.Context class.

Returns

  • N/A

Example

String token = obtainToken();
InfobipRTC infobipRTC = InfobipRTC.getInstance();
infobipRTC.disablePushNotification(token, getApplicationContext());



callWebrtc(callWebrtcRequest)

Description

Makes an outgoing call to another user of Infobip's WebRTC platform.

Arguments

  • callWebrtcRequest: CallWebrtcRequest - Object containing all information needed to make an outgoing call.

Returns

Throws

  • MissingPermissionsException - Error thrown when the required permission is not accepted. It contains a message describing the issue.
  • IllegalStatusException - Error thrown when required conditions are not fulfilled. It contains a message describing the issue. This exception can be thrown in the following scenarios:
    • the internet connection is not available
    • destination number / identity is invalid
    • there is already a call / conference in progress
    • token used for authentication has expired or is invalid
    • token needed for authentication was not provided

Example

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

CallWebrtcRequest callWebrtcRequest = new CallWebrtcRequest(token, getApplicationContext(), "Alice", new DefaultWebrtcCallEventListener());
WebrtcCall webrtcCall = infobipRTC.callWebrtc(callWebrtcRequest);



callWebrtc(callWebrtcRequest, webrtcCallOptions)

Description

Makes an outgoing call to another user of Infobip's WebRTC platform, using additional options.

Arguments

  • callWebrtcRequest: CallWebrtcRequest - Object containing all information needed to make an outgoing call.
  • webrtcCallOptions: WebrtcCallOptions - Additional options used to configure an outgoing call.

Returns

Throws

  • MissingPermissionsException - Error thrown when the required permission is not accepted. It contains a message describing the issue.
  • IllegalStatusException - Error thrown when required conditions are not fulfilled. It contains a message describing the issue. This exception can be thrown in the following scenarios:
    • the internet connection is not available
    • destination number / identity is invalid
    • there is already a call / conference in progress
    • token used for authentication has expired or is invalid
    • token needed for authentication was not provided

Example

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

CallWebrtcRequest callWebrtcRequest = new CallWebrtcRequest(token, getApplicationContext(), "Alice", new DefaultWebrtcCallEventListener());
WebrtcCallOptions webrtcCallOptions = WebrtcCallOptions.builder().video(true).build();
WebrtcCall webrtcCall = infobipRTC.callWebrtc(callWebrtcRequest, webrtcCallOptions);



callPhone(callPhoneRequest)

Description

Makes an outgoing call to a given phone number (physical device, connected to Public Switched Telephone Network, mobile or landline).

Arguments

  • callPhoneRequest: CallPhoneRequest - Object containing all information needed to make an outgoing call.

Returns

Throws

  • MissingPermissionsException - Error thrown when the required permission is not accepted. It contains a message describing the issue.
  • IllegalStatusException - Error thrown when required conditions are not fulfilled. It contains a message describing the issue. This exception can be thrown in the following scenarios:
    • the internet connection is not available
    • destination number / identity is invalid
    • there is already a call / conference in progress
    • token used for authentication has expired or is invalid
    • token needed for authentication was not provided

Example

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

CallPhoneRequest callPhoneRequest = new CallPhoneRequest(token, getApplicationContext(), "41793026727", new DefaultPhoneCallEventListener());
PhoneCall phoneCall = infobipRTC.callPhone(callPhoneRequest);



callPhone(callPhoneRequest, phoneCallOptions)

Description

Makes an outgoing call to a given phone number (physical device, connected to Public Switched Telephone Network, mobile or landline), using additional options.

Arguments

  • callPhoneRequest: CallPhoneRequest - Object containing all information needed to make an outgoing call.
  • phoneCallOptions: PhoneCallOptions - Additional options used to configure an outgoing call.

Returns

Throws

  • MissingPermissionsException - Error thrown when the required permission is not accepted. It contains a message describing the issue.
  • IllegalStatusException - Error thrown when required conditions are not fulfilled. It contains a message describing the issue. This exception can be thrown in the following scenarios:
    • the internet connection is not available
    • destination number / identity is invalid
    • there is already a call / conference in progress
    • token used for authentication has expired or is invalid
    • token needed for authentication was not provided

Example

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

CallPhoneRequest callPhoneRequest = new CallPhoneRequest(token, getApplicationContext(), "41793026727", new DefaultPhoneCallEventListener());
PhoneCallOptions phoneCallOptions = PhoneCallOptions.builder().from("33755531044").build();
PhoneCall phoneCall = infobipRTC.callPhone(callPhoneRequest, phoneCallOptions);



callViber(callViberRequest)

Description

Makes an outgoing call to a given Viber phone number.

Arguments

  • callViberRequest: CallViberRequest - Object containing all information needed to make an outgoing call.

Returns

Throws

  • MissingPermissionsException - Error thrown when the required permission is not accepted. It contains a message describing the issue.
  • IllegalStatusException - Error thrown when required conditions are not fulfilled. It contains a message describing the issue. This exception can be thrown in the following scenarios:
    • the internet connection is not available
    • destination number / identity is invalid
    • there is already a call / conference in progress
    • token used for authentication has expired or is invalid
    • token needed for authentication was not provided

Example

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

CallViberRequest callViberRequest = new CallViberRequest(token, getApplicationContext(), "41727620397", "41793026727", new DefaultViberCallEventListener());
ViberCall viberCall = infobipRTC.callViber(callViberRequest);



callViber(callViberRequest, viberCallOptions)

Description

Makes an outgoing call to a given Viber phone number, using additional options.

Arguments

  • callViberRequest: CallViberRequest - Object containing all information needed to make an outgoing call.
  • viberCallOptions: ViberCallOptions - Additional options used to configure an outgoing call.

Returns

Throws

  • MissingPermissionsException - Error thrown when the required permission is not accepted. It contains a message describing the issue.
  • IllegalStatusException - Error thrown when required conditions are not fulfilled. It contains a message describing the issue. This exception can be thrown in the following scenarios:
    • the internet connection is not available
    • destination number / identity is invalid
    • there is already a call / conference in progress
    • token used for authentication has expired or is invalid
    • token needed for authentication was not provided

Example

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

CallViberRequest callViberRequest = new CallViberRequest(token, getApplicationContext(), "41727620397", "41793026727", new DefaultViberCallEventListener());
ViberCallOptions viberCallOptions = ViberCallOptions.builder().audio(true).build();
ViberCall viberCall = infobipRTC.callViber(callViberRequest, viberCallOptions);



joinRoom(roomRequest)

Description

Joins a room on Infobip's WebRTC platform.

Arguments

  • roomRequest: RoomRequest - Object containing all information needed to join a room.

Returns

Throws

  • MissingPermissionsException - Error thrown when the required permission is not accepted. It contains a message describing the issue.
  • IllegalStatusException - Error thrown when required conditions are not fulfilled. It contains a message describing the issue. This exception can be thrown in the following scenarios:
    • the internet connection is not available
    • there is already a call / conference in progress
    • token used for authentication has expired or is invalid
    • token needed for authentication was not provided

Example

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

RoomRequest roomRequest = new RoomRequest(token, getApplicationContext(), "room-test", new DefaultRoomCallEventListener());
RoomCall roomCall = infobipRTC.joinRoom(roomRequest);



joinRoom(roomRequest, roomCallOptions)

Description

Joins a room on Infobip's WebRTC platform, using additional options.

Arguments

  • roomRequest: RoomRequest - Object containing all information needed to join a room.
  • roomCallOptions: RoomCallOptions - Additional options used to configure a room call

Returns

Throws

  • MissingPermissionsException - Error thrown when the required permission is not accepted. It contains a message describing the issue.
  • IllegalStatusException - Error thrown when required conditions are not fulfilled. It contains a message describing the issue. This exception can be thrown in the following scenarios:
    • the internet connection is not available
    • there is already a call / conference in progress
    • token used for authentication has expired or is invalid
    • token needed for authentication was not provided

Example

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

RoomRequest roomRequest = new RoomRequest(token, getApplicationContext(), "room-test", new DefaultRoomCallEventListener());
RoomCallOptions roomCallOptions = new RoomCallOptions.builder().video(true).build();
RoomCall roomCall = infobipRTC.joinRoom(roomRequest, roomCallOptions);



callApplication(callApplicationRequest)

Description

Makes an outgoing application call through Infobip's Calls platform to your application.

Arguments

  • callApplicationRequest: CallApplicationRequest - Object containing all information needed to make an application call.

Returns

Throws

  • MissingPermissionsException - Error thrown when the required permission is not accepted. It contains a message describing the issue.
  • IllegalStatusException - Error thrown when required conditions are not fulfilled. It contains a message describing the issue. This exception can be thrown in the following scenarios:
    • the internet connection is not available
    • destination number / identity is invalid
    • there is already a call / conference in progress
    • token used for authentication has expired or is invalid
    • token needed for authentication was not provided

Examples

  • example of initiating an application call
String token = obtainToken();
InfobipRTC infobipRTC = InfobipRTC.getInstance();

CallApplicationRequest callApplicationRequest = new CallApplicationRequest(token, getApplicationContext(), "45g2gql9ay4a2blu55uk1628", new DefaultApplicationCallEventListener());
ApplicationCall applicationCall = infobipRTC.callApplication(callApplicationRequest);
  • example of initiating a call towards Infobip Conversations
String token = obtainToken();
InfobipRTC infobipRTC = InfobipRTC.getInstance();

CallApplicationRequest callApplicationRequest = new CallApplicationRequest(
       token, 
       getApplicationContext(),
       InfobipCallsConfiguration.CONVERSATIONS.getCallsConfiguration(), 
       new DefaultApplicationCallEventListener()
);
           
ApplicationCall applicationCall = infobipRTC.callApplication(callApplicationRequest);



callApplication(callApplicationRequest, applicationCallOptions)

Description

Makes an outgoing application call through Infobip's Calls platform to your application.

Arguments

  • callApplicationRequest: CallApplicationRequest - Object containing all information needed to make an application call.
  • applicationCallOptions: ApplicationCallOptions - Additional options used to configure an outgoing application call.

Returns

Throws

  • MissingPermissionsException - Error thrown when the required permission is not accepted. It contains a message describing the issue.
  • IllegalStatusException - Error thrown when required conditions are not fulfilled. It contains a message describing the issue. This exception can be thrown in the following scenarios:
    • the internet connection is not available
    • destination number / identity is invalid
    • there is already a call / conference in progress
    • token used for authentication has expired or is invalid
    • token needed for authentication was not provided

Examples

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

CallApplicationRequest callApplicationRequest = new CallApplicationRequest(token, getApplicationContext(), "45g2gql9ay4a2blu55uk1628", new DefaultApplicationCallEventListener());
ApplicationCallOptions applicationCallOptions = ApplicationCallOptions.builder().customData(Map.of("userId", "bgxy-as45-ddf3")).build();
ApplicationCall applicationCall = infobipRTC.callApplication(callApplicationRequest, applicationCallOptions);



getActiveCall()

Description

Get currently active call if it exists.

Arguments

  • none

Returns

  • Call - Instance of the currently active call. null if there is no active call.

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
Call activeCall = infobipRTC.getActiveCall();



getActiveRoomCall()

Description

Get currently active room call if it exists.

Arguments

  • none

Returns

  • RoomCall - Instance of the currently active room call. null if there is no active room.

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
RoomCall roomCall = infobipRTC.getActiveRoomCall();



getActiveApplicationCall()

Description

Get currently active application call if it exists.

Arguments

  • none

Returns

  • ApplicationCall - Instance of the currently active application call. null if there is no active application call.

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
ApplicationCall applicationCall = infobipRTC.getActiveApplicationCall();



isIncomingCall(payload)

Description

Check if received push notification is incoming call.

Arguments

Returns

  • boolean - true if push notification contains incoming call data, otherwise false.

Example

class FcmService extends FirebaseMessagingService {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Map<String, String> payload = remoteMessage.getData();
        if (infobipRTC.isIncomingCall(payload)) {
            // handle incoming call (see 'handleIncomingCall' method)
        }
    }
}



handleIncomingCall(payload, context, incomingCallEventListener)

Description

Handle received push notification with InfobipRTC in order to receive an incoming call. You should use FirebaseMessagingService to listen for push notifications. Upon receiving a message, make sure to check the message type before calling this method.

Arguments

  • payload: Map<String, String> - Payload received in push notification.
  • context: Context - Instance of the android.content.Context class.
  • incomingCallEventListener: IncomingCallEventListener - Interface defining method that will be executed once an incoming call event has been received.

Returns

  • N/A

Example

class FcmService extends FirebaseMessagingService {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Map<String, String> payload = remoteMessage.getData();
        if (infobipRTC.isIncomingCall(payload)) {
            infobipRTC.handleIncomingCall(
                payload,
                getAplicationContext(),
                new IncomingCallEventListener() {
                    @Override
                    public void onIncomingCall(IncomingCallEvent incomingCallEvent) {
                        IncomingCall incomingCall = incomingCallEvent.getIncomingCall();
                        Log.d("WebRTC", "Received an incoming call from:  " + incomingCall.source());
                        incomingCall.setEventListener(new DefaultCallEventListener());
                        incomingCall.accept(); // or incomingCall.decline();
                    }
                }
            );
        }
    }
}



isIncomingApplicationCall(payload)

Description

Check if received push notification is an incoming application call.

Arguments

Returns

  • boolean - true if push notification contains incoming application call data, otherwise false.

Example

class FcmService extends FirebaseMessagingService {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Map<String, String> payload = remoteMessage.getData();
        if (infobipRTC.isIncomingApplicationCall(payload)) {
            // handle incoming application call (see 'handleIncomingApplicationCall' method)
        }
    }
}



handleIncomingApplicationCall(payload, context, incomingApplicationCallEventListener)

Description

Handle received push notification with InfobipRTC in order to receive an incoming application call. You should use FirebaseMessagingService to listen for push notifications. Upon receiving a message, make sure to check the message type before calling this method.

Arguments

  • payload: Map<String, String> - Payload received in push notification.
  • context: Context - Instance of the android.content.Context class.
  • incomingApplicationCallEventListener: IncomingApplicationCallEventListener - Interface defining method that will be executed once an incoming application call event is received.

Returns

  • N/A

Example

class FcmService extends FirebaseMessagingService {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Map<String, String> payload = remoteMessage.getData();
        if (infobipRTC.isIncomingApplicationCall(payload)) {
            infobipRTC.handleIncomingApplicationCall(
                payload,
                getAplicationContext(),
                new IncomingApplicationCallEventListener() {
                    @Override
                    public void onIncomingApplicationCall(IncomingApplicationCallEvent incomingApplicationCallEvent) {
                        IncomingApplicationCall incomingApplicationCall = incomingApplicationCallEvent.getIncomingApplicationCall();
                        Log.d("WebRTC", "Received an incoming application call from:  " + incomingApplicationCall.from());
                        incomingApplicationCall.setEventListener(new DefaultApplicationCallEventListener());
                        incomingApplicationCall.accept(); // or incomingApplicationCall.decline();
                    }
                }
            );
        }
    }
}



getInstance()

Description

Gets a current instance of InfobipRTC if it exists, if not, creates a new InfobipRTC instance

Arguments

  • none

Returns

  • InfobipRTC - Instance of the InfobipRTC interface.

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();

Tutorials

Migration guides

Reference documentation

Clone this wiki locally