Skip to content

InfobipRTC

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

Calls

Rooms

Event handlers

There are two types of events in Infobip RTC API:

  • RTC events - Ones that are configured globally, per connection basis. Allowed values are: connected, disconnected, reconnecting, reconnected, incoming-application-call, and incoming-webrtc-call.
  • Calls API events - Ones that are configured per call basis. Allowed values are: ringing, early-media, established, hangup, error, camera-video-added, camera-video-updated, camera-video-removed screen-share-added, screen-share-removed, room-joined, room-left, conference-joined, conference-left, participant-joining, participant-joined, participant-muted, participant-unmuted, participant-deaf, participant-undeaf, participant-started-talking, participant-stopped-talking, participant-left, participant-camera-video-added, participant-camera-video-removed, participant-screen-share-added, participant-screen-share-removed, remote-muted, remote-unmuted, remote-camera-video-added, remote-camera-video-removed, remote-screen-share-added, remote-screen-share-removed, network-quality-changed, remote-network-quality-changed.

For details about which type of call can receive which types of events, please consult their respective reference documentation.



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

  • N/A

Example

let infobipRTC = createInfobipRtc('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

  • N/A

Example

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



connectedUser()

Description

Returns information about the currently connected user.

Arguments

  • none

Returns

  • User - Instance of the User object

Example

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



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, incoming-application-call and incoming-webrtc-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-application-call - Incoming application call event (instance of IncomingApplicationCallEvent class), containing incoming application call ( instance of IncomingApplicationCall class) and custom data, will be provided.

      event = { incomingCall: IncomingApplicationCall, customData: CustomData }
    • incoming-webrtc-call - Incoming WebRTC call event (instance of IncomingWebrtcCallEvent class), containing incoming WebRTC call (instance of IncomingWebrtcCall class) and custom data, will be provided.

      event = { incomingCall: IncomingWebrtcCall, customData: CustomData }

Returns

  • N/A

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.on('connected', function (event) {
    console.log(`Connected with identity: ${event.identity}`);
});

infobipRTC.on('incoming-webrtc-call', function (event) {
    console.log(`Incoming call from: ${event.incomingCall.source().identifier}`);
});



callApplication(callsConfigurationId, options)

Description

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

Arguments

Returns

Examples

  • Example of initiating audio call:
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628', ApplicationCallOptions.builder().setAudio(true).build());
  • Example of initiating video call:
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628', ApplicationCallOptions.builder().setVideo(true).build());
  • Example of initiating a call towards Infobip Conversations:
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let applicationCall = infobipRTC.callApplication(InfobipCallsConfiguration.CONVERSATIONS, ApplicationCallOptions.builder().setAudio(true).build());



callWebrtc(identity, options)

Description

Makes an outgoing WebRTC call through Infobip's Calls platform to another WebRTC identity.

Arguments

  • identity: string - Destination identity to call. If the identity does not exist, the call will be hung up with the proper reason.
  • options: WebrtcCallOptions - Optional additional options used to configure a WebRTC applications call.

Returns

Examples

  • Example of initiating audio call:
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let webrtcCall = infobipRTC.callWebrtc('Alice');
  • Example of initiating video call:
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let webrtcCall = infobipRTC.callWebrtc('Bob', WebrtcCallOptions.builder().setVideo(true).build());



callPhone(phoneNumber, phoneCallOptions)

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.
  • phoneCallOptions: PhoneCallOptions - Optional additional options used to configure the phone call.

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let phoneCall = infobipRTC.callPhone('41793026727', PhoneCallOptions.builder().setFrom('33712345678').build());



callViber(phoneNumber, from, viberCallOptions)

Description

Makes an outgoing call to a Viber application associated with the given phone number.

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.
  • from: string - The field indicating what phone number should be used when making the call.
  • viberCallOptions: ViberCallOptions - Optional additional options used to configure a viber call.

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let viberCall = infobipRTC.callViber('41793026727', '33712345678', PhoneCallOptions.builder().build());



joinRoom(roomName, options)

Description

Joins a room call on Infobip's WebRTC platform.

Arguments

  • roomName: string - Name of the room to join.
  • options: RoomCallOptions - Optional additional options used to configure a room call.

Returns

Examples

  • Example of initiating an audio room call:
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let roomCall = infobipRTC.joinRoom('test_room', RoomCallOptions.builder().build());
  • Example of initiating a video room call:
let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let roomCall = infobipRTC.joinRoom('test_room', RoomCallOptions.builder().setVideo(true).build());



getAudioInputDevices()

Description

Returns available audio input devices.

Arguments

  • none

Returns

Example

let infobipRTC = createInfobipRtc('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: ${error.message}`));



getAudioOutputDevices()

Description

Returns available audio output devices.

Arguments

  • none

Returns

Example

let infobipRTC = createInfobipRtc('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: ${error.message}`));



getVideoInputDevices()

Description

Returns available video input devices.

Arguments

  • none

Returns

Example

let infobipRTC = createInfobipRtc('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: ${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

  • N/A

Example

let infobipRTC = createInfobipRtc('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

  • N/A

Example

let infobipRTC = createInfobipRtc('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

  • N/A

Example

let infobipRTC = createInfobipRtc('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

  • N/A

Example

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

Tutorials

Migration guides

Reference documentation

Clone this wiki locally