Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

InfobipRTC

Adnan Arnautović edited this page Jan 26, 2023 · 1 revision

Call:

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);



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', CallOptions.builder().setAudio(true).build());
  • 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());
Clone this wiki locally