Skip to content

InfobipRTC

Adnan Arnautović edited this page May 24, 2022 · 16 revisions

Call:

- [`callConversations(options?: CallOptions): OutgoingCall`](#callConversations) - [`getAudioInputDevices(): Promise`](#getAudioInputDevices) - [`getAudioOutputDevices(): Promise`](#getAudioOutputDevices) - [`getVideoInputDevices(): Promise`](#getVideoInputDevices) - [`setAudioInputDevice(deviceId: string)`](#setAudioInputDevice) - [`setVideoInputDevice(deviceId: string)`](#setVideoInputDevice) - [`unsetAudioInputDevice(deviceId: string)`](#unsetAudioInputDevice) - [`unsetVideoInputDevice(deviceId: string)`](#unsetVideoInputDevice)

Conference:

Calls API:

Event handlers:

There are three types of events in Infobip RTC API:

  • RTC events - Ones that are configured globally, per connection basis. Allowed values are: connected , disconnected, reconnecting, reconnected and incoming-call.
  • Call events - Ones that are configured per call basis. Allowed values are: ringing , early-media, established, updated, hangup, error, network-quality-changed , remote-network-quality-changed, user-muted and user-unmuted.
  • Conference events - Ones that are configured per conference basis. Allowed values are: joined, left, error, user-joined, user-left, user-muted, user-unmuted, local-video-added , local-video-removed, local-video-updated, user-video-added and user-video-removed.

constructor(token, rtcOptions = {})

Description

Creates a new instance of InfobipRTC, used to make all requests to Infobip WebRTC platform. This method is only used for creating the instance, while connecting to WebSocket API is done via connect method.

Arguments

  • token: string - Authentication token generated by client's app via Infobip's HTTP /webrtc/1/token endpoint.
  • rtcOptions: any - Optional object containing options used to configure InfobipRTC. The following fields are supported:
    • debug: boolean - Influences the log level. false by default. false will result in the log level being set to ERROR, while true will set it to DEBUG.
    • statsUrl: string - The URL of Infobip WebRTC platform to connect to.

Returns

  • none

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});



connect()

Description

Connects to Infobip's WebSocket API (WebRTC platform), using authentication and options supplied through the constructor. If any temporary errors occur (e.g. network issue), the connection will be reattempted with an exponential backoff with an initial delay of 50 ms, up to 1000 ms, over 50 attempts. In case the retries fail, or a permanent error occurs (e.g. authentication error), an error is thrown. Also throws in case the status isn't OFFLINE.

Arguments

  • none

Returns

  • none

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();



disconnect()

Description

Disconnects from Infobip's WebSocket API (WebRTC platform), if connected. Throws an error if status is not ONLINE.

Arguments

  • none

Returns

  • none

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.disconnect();



on(eventName, eventHandler)

Description

Configures the event handler for RTC events, ones that are configured globally, per connection basis.

Arguments

  • eventName: string - Name of the RTC event. Name of RTC event. Allowed values are: connected, disconnected, reconnecting, reconnected and incoming-call.

  • eventHandler: any - Function that will be called when specified event occurs, with exactly one parameter being passed to the function containing event information. Depending on the event, the passed parameter will contain a set of fields that will describe the event, namely:

    • connected - identity field (identity set by Infobip client's app, when generating token via Infobip's HTTP /webrtc/1/token endpoint) will be provided.

      event = {identity: 'alice'}
    • disconnected - reason field will be provided, describing the reason why Infobip's WebSocket got disconnected.

      event = {reason: 'Connection error.'}
    • reconnecting - No additional fields will be passed.

      event = {}
    • reconnected - No additional fields will be passed.

      event = {}
    • incoming-call - Incoming call event (instance of IncomingCallEvent class), containing incoming call (instance of Call class) and custom data, will be provided.

      event = {incomingCall: callObject, customData: {}}

Returns

  • none

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.on('connected', function (event) {
    console.log(`Connected with identity: ${event.identity}`);
});
infobipRTC.on('incoming-call', function (event) {
    console.log(`Incoming call from: ${event.incomingCall.source().identity}`);
});



call(identity, options?)

Description

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

Arguments

  • identity: string - Destination identity to call. If the identity does not exist, the call will be hung up with the proper reason.
  • options: CallOptions - Optional additional options used to configure an outgoing call.

Returns

Examples

  • Example of initiating audio call:
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let call = infobipRTC.call('alice');
  • Example of initiating video call:
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let call = infobipRTC.call('alice', CallOptions.builder().setVideo(true).build());
  • Example of initiating call with video and recording turned on
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let recordingOptions = RecordingOptions.builder()
                        .setAudio(true)
                        .setVideo(true)
                        .build();
let callOptions = CallOptions.builder()
                        .setVideo(true)
                        .setRecording(recordingOptions)
                        .build();
let call = infobipRTC.call('alice', callOptions);



callPhoneNumber(phoneNumber, options?)

Description

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

Arguments

  • phoneNumber: string - Destination phone number to call. If the phone number does not exist, the call will be hung up with the proper reason.
  • options: CallPhoneNumberOptions - Optional additional options used to configure an outgoing call.

Returns

Example

  • Example of initiating call to a phone number
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let call = infobipRTC.callPhoneNumber('41793026727', CallPhoneNumberOptions.builder().setFrom('33712345678').build());
  • Example of initiating call to a phone number with recording turned on
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let recordingOptions = RecordingOptions.builder()
                        .setAudio(true)
                        .build();
let callPhoneNumberOptions = CallPhoneNumberOptions.builder()
                        .setFrom('33712345678')
                        .setRecording(recordingOptions)
                        .build();
let call = infobipRTC.callPhoneNumber('41793026727', callPhoneNumberOptions);



callSIP(destination, options?)

Description

Makes an outgoing call to a SIP server. Before you can use this type of call, you first need to set up a SIP Trunk through the Infobip Portal (contact your account manager for this).

Arguments

  • destination: string - Destination to call. It will be forwarded through the Request-URI of the SIP call.
  • options: CallOptions - Optional additional options used to configure an outgoing call.

Returns

Example

  • Example of initiating SIP call
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let call = infobipRTC.callSIP('alice');
  • Example of initiating a SIP call with recording turned on
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let recordingOptions = RecordingOptions.builder()
                        .setAudio(true)
                        .build();
let callOptions = CallOptions.builder()
                        .setRecording(recordingOptions)
                        .build();
let call = infobipRTC.callSIP('alice', callOptions);



callDynamicDestination(options?)

Description

Makes an outgoing call to destination specified by client-defined API. Before you can use this type of call, you first need to set up a Dynamic Destination through the Infobip Portal (contact your account manager for this). Before the actual call is made, we will call your API to resolve destination (and source number to be sent to destination). Also, you can control whether the call will be placed to another WebRTC user or to a phone number.

Request that is being sent to your API will have JSON body with the following fields:

  • source - original identity of the user who initiated the call
  • hasVideo - whether the call contains video
  • customData - optional JSON serialized object containing additional information passed to this method

Also, Authorization header will be sent, if Basic auth is configured with your account manager.

Request example:

POST example.com/webrtc HTTP/1.1
Authorization:  Basic QWxpY2U6QWxpY2U=

{
  "source": "alice",
  "customData": {
    "myUserId": "MyAlice"
  }
}

In response, we expect the Content-Type header to be present with the application/json value, and JSON body with the following fields:

  • action- should contain one of the two possible values:
    • call - indicating we should place the call to another WebRTC user
    • call_phone_number- indicating we should place the call to a phone number
  • source - should contain a value that will be displayed as the caller when placing the call
  • destination- should contain the actual destination where you want the call to be placed

Response example:

HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8

{
  "action": "call_phone_number",
  "source": "33712345678",
  "destination": "41793026727"
}

Arguments

  • options: CallOptions - Optional additional options used to configure an outgoing call.

Returns

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let call = infobipRTC.callDynamicDestination(CallOptions.builder().setCustomData({myUserId: 'MyAlice'}).build());



callConversations(options?)

Description

Makes an outgoing call to Infobip Conversations platform.

Arguments

  • options: CallOptions - Optional additional options used to configure an outgoing call.

Returns

Examples

  • Example of initiating audio call:
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let call = infobipRTC.callConversations();
  • Example of initiating video call:
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let call = infobipRTC.callConversations(CallOptions.builder().setVideo(true).build());
  • Example of initiating video call with recording turned on
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let recordingOptions = RecordingOptions.builder()
                        .setAudio(true)
                        .setVideo(true)
                        .build();
let callOptions = CallOptions.builder()
                        .setVideo(true)
                        .setRecording(recordingOptions)
                        .build();
let call = infobipRTC.callConversations(callOptions);



getAudioInputDevices()

Description

Returns available audio input devices.

Arguments

  • none

Returns

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.getAudioInputDevices()
    .then(devices => {
        devices.forEach(device => console.log(device.label));
    })
    .catch(error => console.error(error.message));



getAudioOutputDevices()

Description

Returns available audio output devices.

Arguments

  • none

Returns

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.getAudioOutputDevices()
    .then(devices => {
        devices.forEach(device => console.log(device.label));
    })
    .catch(error => console.error(error.message));



getVideoInputDevices()

Description

Returns available video input devices.

Arguments

  • none

Returns

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.getVideoInputDevices()
    .then(devices => {
        devices.forEach(device => console.log(device.label));
    })
    .catch(error => console.error(error.message));



setAudioInputDevice(deviceId)

Description

Sets the audio input device with the given id as the default option for all subsequent calls.

Arguments

  • deviceId: string - Audio input device identifier.

Returns

  • none

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.setAudioInputDevice('audioDeviceId');



setVideoInputDevice(deviceId)

Description

Sets the video input device with the given id as the default option for all subsequent calls.

Arguments

  • deviceId: string - Video input device identifier.

Returns

  • none

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.setVideoInputDevice('videoDeviceId');



unsetAudioInputDevice(deviceId)

Description

Clears the specified audio input device as the default device. Instead, the system default will be used for subsequent calls.

Arguments

  • deviceId: string - Audio input device identifier.

Returns

  • none

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.unsetAudioInputDevice('audioDeviceId');



unsetVideoInputDevice(deviceId)

Description

Clears the specified video input device as the default device. Instead, the system default will be used for subsequent calls.

Arguments

  • deviceId: string - Video input device identifier.

Returns

  • none

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.unsetVideoInputDevice('videoDeviceId');



joinConference(conferenceId, options?)

This method is currently in beta phase.

Description

Joins a conference call on Infobip's WebRTC platform.

Arguments

  • conferenceId: string - A unique identifier for every conference room on Infobip RTC platform.
  • options: ConferenceOptions - Optional additional options used to configure a conference call.

Returns

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let conference = infobipRTC.joinConference('conference-demo', ConferenceOptions.builder().audio(true).video(true).build());



callApplication(applicationId: string, options?: CallOptions): ApplicationCall

Description

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

Arguments

  • applicationId: string - Represents the application ID of your backend application that's set up earlier through the Calls API.
  • options: CallOptions - Optional additional options used to configure an application call.

Returns

Examples

  • Example of initiating audio call:
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
  • Example of initiating video call:
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628', CallOptions.builder().setVideo(true).build());

Tutorials

Migration guides

Reference documentation

Clone this wiki locally