-
Notifications
You must be signed in to change notification settings - Fork 0
InfobipRTC
constructor(token: string, rtcOptions: any = {})
connect()
disconnect()
on(eventName: string, eventHandler: any)
call(identity: string, options?: CallOptions): OutgoingCall
callPhoneNumber(phoneNumber: string, options?: CallPhoneNumberOptions): OutgoingCall
callSIP(destination: string, options?: CallOptions): OutgoingCall
callDynamicDestination(options?: CallOptions): OutgoingCall
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
andincoming-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
anduser-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
anduser-video-removed
.
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.
-
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:
none
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
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
.
none
none
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
Disconnects from Infobip's WebSocket API (WebRTC platform), if connected. Throws an error if status is not ONLINE
.
none
none
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.disconnect();
Configures the event handler for RTC events, ones that are configured globally, per connection basis.
-
eventName
:string
- Name of the RTC event. Name of RTC event. Allowed values are:connected
,disconnected
,reconnecting
,reconnected
andincoming-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 ofIncomingCallEvent
class), containing incoming call (instance ofCall
class) and custom data, will be provided.event = {incomingCall: callObject, customData: {}}
-
none
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}`);
});
Makes an outgoing call to another user of Infobip's WebRTC platform.
-
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.
-
OutgoingCall
- Instance of theOutgoingCall
.
- 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);
Makes an outgoing call to a given phone number (physical device, connected to Public Switched Telephone Network, mobile or landline).
-
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.
-
OutgoingCall
- Instance of theOutgoingCall
.
- 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);
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).
-
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.
-
OutgoingCall
- Instance of theOutgoingCall
.
- 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);
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"
}
-
options
:CallOptions
- Optional additional options used to configure an outgoing call.
-
OutgoingCall
- Instance of theOutgoingCall
.
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
let call = infobipRTC.callDynamicDestination(CallOptions.builder().setCustomData({myUserId: 'MyAlice'}).build());
Makes an outgoing call to Infobip Conversations platform.
-
options
:CallOptions
- Optional additional options used to configure an outgoing call.
-
OutgoingCall
- Instance of theOutgoingCall
.
- 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);
Returns available audio input devices.
none
-
Promise<MediaDeviceInfo[]>
- Promise that resolves to an array containing available audio input devices info.
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));
Returns available audio output devices.
none
-
Promise<MediaDeviceInfo[]>
- Promise that resolves to an array containing available audio output devices info.
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));
Returns available video input devices.
none
-
Promise<MediaDeviceInfo[]>
- Promise that resolves to an array containing available video input devices info.
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));
Sets the audio input device with the given id as the default option for all subsequent calls.
-
deviceId
:string
- Audio input device identifier.
none
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.setAudioInputDevice('audioDeviceId');
Sets the video input device with the given id as the default option for all subsequent calls.
-
deviceId
:string
- Video input device identifier.
none
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.setVideoInputDevice('videoDeviceId');
Clears the specified audio input device as the default device. Instead, the system default will be used for subsequent calls.
-
deviceId
:string
- Audio input device identifier.
none
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.unsetAudioInputDevice('audioDeviceId');
Clears the specified video input device as the default device. Instead, the system default will be used for subsequent calls.
-
deviceId
:string
- Video input device identifier.
none
let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.connect();
infobipRTC.unsetVideoInputDevice('videoDeviceId');
Joins a conference call on Infobip's WebRTC platform.
-
conferenceId
:string
- A unique identifier for every conference room on Infobip RTC platform. -
options
:ConferenceOptions
- Optional additional options used to configure a conference call.
-
Conference
- Instance of theConference
.
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());
Makes an outgoing application call through Infobip's Calls platform to your application.
-
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.
-
ApplicationCall
- Instance of theApplicationCall
.
- 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());