Skip to content
Ajša Terko edited this page Feb 15, 2024 · 14 revisions



id()

Description

Returns a unique call identifier on Infobip RTC platform.

Arguments

  • none

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.callWebrtc('alice');
console.log(`Call ID: ${call.id()}`);



options()

Description

Returns the call options this call was started with.

Arguments

  • none

Returns

  • CallOptions - Call options the call was started with.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice', WebrtcCallOptions.builder().build());
console.log(`Call options: ${JSON.stringify(webrtcCall.options())}`);



status()

Description

Returns current call status.

Arguments

  • none

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
console.log(`Call status: ${webrtcCall.status()}`);



duration()

Description

Returns call duration in seconds calculated from the time call was established. Initially, duration is 0.

Arguments

  • none

Returns

  • number - Call duration in seconds.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.HANGUP, _ => {
    let durationInSeconds = webrtcCall.duration();
    let seconds = `${String(Math.floor(durationInSeconds % 60)).padStart(2, '0')}`;
    let minutes = `${String(Math.floor(durationInSeconds / 60) % 60).padStart(2, '0')}`;
    let hours = `${String(Math.floor(durationInSeconds / 3600)).padStart(2, '0')}`;
               
    console.log(`Duration: ${hours}:${minutes}:${seconds}`);
});



startTime()

Description

Returns the time when the call started (but not yet established). Initially, startTime is undefined.

Arguments

  • none

Returns

  • Date - Time when the call started.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
console.log(`Start time: ${webrtcCall.startTime()}`);



establishTime()

Description

Returns the time when the call was established. Initially, establishTime is undefined.

Arguments

  • none

Returns

  • Date - Time when the call was established.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
    console.log(`Establish time: ${webrtcCall.establishTime()}`);
});



endTime()

Description

Returns the time when the call finished. Initially, endTime is undefined.

Arguments

  • none

Returns

  • Date - Time when the call finished.

Example

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

webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
    webrtcCall.hangup();
});

webrtcCall.on(CallsApiEvent.HANGUP, _ => {
    console.log(`End time: ${calwebrtcCalll.endTime()}`);
});



mute(shouldMute)

Description

Toggles mute option.

Arguments

  • shouldMute: boolean - Whether the audio should be muted after this action.

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
    webrtcCall.mute(true)
        .catch(error => console.log(`Error: ${error}`));
});



muted()

Description

Returns information whether the audio is muted.

Arguments

  • none

Returns

  • boolean - true if audio is muted, otherwise false.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
    webrtcCall.mute(true);
    let muted = webrtcCall.muted() ? 'muted' : 'not muted';
    console.log(`Audio is ${muted}`);
});



sendDTMF(dtmf)

Description

Simulates key-press by sending DTMF (Dual-Tone Multi-Frequency) entry.

Arguments

  • dtmf: String - One of the allowed DTMF characters:
    • digits: 0 to 9
    • letters: A to D
    • symbols: * and #

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
    webrtcCall.sendDTMF('1')
        .catch(error => console.log(`Error: ${error}`));
});



source()

Description

Returns the endpoint from which the call originated.

Arguments

  • none

Returns

  • Endpoint - Endpoint which initiated the call.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
    console.log(`Source of the currently established call: ${webrtcCall.source().identifier}`);
});



destination()

Description

Returns the endpoint that received the call.

Arguments

  • none

Returns

  • Endpoint - Endpoint which received the call.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
    console.log(`Destination of the currently established call: ${webrtcCall.destination().identifier}`);
});



counterpart()

Description

Returns the remote endpoint relating to this call. This isn't dependent on where the call originated, but who is calling this method.

Arguments

  • none

Returns

  • Endpoint - Remote endpoint with which the user is connected

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
    console.log(`Remote side of the currently established call: ${webrtcCall.counterpart().identifier}`);
});



hangup()

Description

Hangs up a call, which ends up in both parties receiving a hangup event, after the hangup is processed by Infobip WebRTC platform.

Arguments

  • none

Returns

  • N/A

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
    webrtcCall.hangup();
});



setAudioInputDevice(deviceId)

Description

Sets the audio input device with the given id to be used during the call.

Arguments

  • deviceId: string - Audio input device identifier.

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
    webrtcCall.setAudioInputDevice('audioDeviceId')
        .catch(error => console.log(`Error: ${error}`));
});



setAudioFilter(audioFilter)

Description

Sets the audio filter to be used during the call. Passing null will remove and release any already existing audio filter.

Arguments

  • audioFilter: AudioFilter - An object instance which implements the AudioFilter interface.

Returns

  • Promise<void> - Promise that resolves once the filter has been applied to the current audio stream.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
let audioFilter = createAudioFilterImplementation();
webrtcCall.setAudioFilter(audioFilter);



audioFilter()

Description

Returns the audio filter that is used during the call.

Arguments

  • none

Returns

  • AudioFilter - An object instance which implements the AudioFilter interface.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.setAudioFilter(createAudioFilterImplementation());
let audioFilter = webrtcCall.audioFilter();



clearAudioFilter()

Description

Convenience method that is used to remove the audio filter if it is present.

Arguments

  • none

Returns

  • Promise<void> - Promise that resolves once the filter has been removed.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.setAudioFilter(createAudioFilterImplementation());

webrtcCall.clearAudioFilter();



audioQualityMode(audioQualityMode)

Description

Sets the audio quality mode to a given enum value.

Arguments

Returns

  • N/A

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let webrtcCall = infobipRTC.callWebrtc('alice');
webrtcCall.on(CallsApiEvent.ESTABLISHED, _ => {
    webrtcCall.audioQualityMode(AudioQualityMode.LOW_DATA)
});



on(eventName, eventHandler)

Description

Configures the event handler for call events.

Arguments

  • eventName: CallsApiEvent - Name of the application call event. Allowed values are a subset of CallsApiEvent.

  • eventHandler: CallsEventHandlers - 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:

    • RINGING - No additional data is provided in the event object.

      event = {}
    • EARLY_MEDIA - A MediaStream object representing the media being played is received in the event object.

      event = { stream: MediaStream }
    • ESTABLISHED - A MediaStream object representing the media in the call is received in the event object.

      event = { stream: MediaStream }
    • HANGUP - A received ErrorCode object provides details about the reason for the call hang-up, along with a TotalMediaStats object that offers a comprehensive summary of the call's audio statistics.

      event = { errorCode: ErrorCode, totalMediaStats: TotalMediaStats }
    • ERROR - A received ErrorCode object provides details about the reason for the error occurrence.

      event = { errorCode: ErrorCode }
    • NETWORK_QUALITY_CHANGED - An event containing a NetworkQuality and a CurrentMediaStats objects provides details on the network quality of a local participant and its corresponding media stats.

      event = { networkQuality: NetworkQuality, currentMediaStats: CurrentMediaStats }

Returns

  • N/A

Example

Let's assume you have an audio HTML element with the id callAudio.

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

phoneCall.on(CallsApiEvent.RINGING, () => {
    console.log('Ringing...');
});
phoneCall.on(CallsApiEvent.EARLY_MEDIA, (event) => {
    console.log('Ringtone playing...');
    $('#callAudio').srcObject = event.stream;
});
phoneCall.on(CallsApiEvent.ESTABLISHED, (event) => {
    $('#callAudio').srcObject = event.stream;
});
phoneCall.on(CallsApiEvent.HANGUP, (event) => {
    console.log(`Call finished. Status: ${event.errorCode.name}`);
});
phoneCall.on(CallsApiEvent.ERROR, (event) => {
    console.log(`An error has occurred. Error: ${event.errorCode.name}`);
});
phoneCall.on(CallsApiEvent.NETWORK_QUALITY_CHANGED, (event) => {
  console.log(`Local network quality is: ${NetworkQuality[event.networkQuality]}`);
});

Tutorials

Migration guides

Reference documentation

Clone this wiki locally