Skip to content

PhoneCall

Lejla Solak edited this page Feb 9, 2026 · 5 revisions

extends Call



options()

Description

Returns the options this call was started with.

Arguments

  • none

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let phoneCall = infobipRTC.callPhone('41793026727', PhoneCallOptions.builder()
    .setAutoReconnect(true) // Required in order to receive RECONNECTING and RECONNECTED events
    .setFrom('33712345678')
    .build());
console.log(`Call options: ${JSON.stringify(phoneCall.options())}`);



on(eventName, eventHandler)

Description

Configures the event handler for phone 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 that provides details on the network quality of a local participant and its corresponding media stats.

      event = { networkQuality: NetworkQuality, currentMediaStats: CurrentMediaStats }
    • CALL_RECORDING_STARTED - An event that is triggered once a call recording starts. It includes RecordingType enum value which corresponds to the type of recording initiated.

      event = { recordingType: RecordingType }
    • RECONNECTING - No additional data is provided in the event object.

      event = {}
    • RECONNECTED - No additional data is provided in the event object.

      event = {}
    • TALKING_WHILE_MUTED - No additional data is provided in the event object.

      event = {}
    • MACHINE_DETECTION_FINISHED - An event containing the detection result and ConfidenceRating.

      event = { detectionResult: string, confidenceRating: ConfidenceRating }
    • MACHINE_DETECTION_FAILED - An event containing the reason for the failure.

      event = { reason: string }

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 machineDetectionOptions = MachineDetectionOptions.builder().setEnabled(true).build();
let phoneCall = infobipRTC.callPhone('41793026727', PhoneCallOptions.builder()
        .setAutoReconnect(true) // Required in order to receive RECONNECTING and RECONNECTED events
        .setFrom('33712345678')
        .setMachineDetectionOptions(machineDetectionOptions)
        .build());

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]}`);
});

phoneCall.on(CallsApiEvent.CALL_RECORDING_STARTED, (event) => {
    console.log(`Call recording started with type ${event.recordingType}`);
});

phoneCall.on(CallsApiEvent.RECONNECTING, (event) => {
    console.log('Call is being reconnected, hang tight!');
});

phoneCall.on(CallsApiEvent.RECONNECTED, (event) => {
    console.log('You have successfully reconnected the call!');
});

phoneCall.on(CallsApiEvent.TALKING_WHILE_MUTED, (event) => {
    console.log('You are talking while muted. Do you want to unmute?');
});

phoneCall.on(CallsApiEvent.MACHINE_DETECTION_FINISHED, (event) => {
    console.log(`Machine detection finished. Result: ${event.detectionResult}`);
    console.log(`Confidence ratings: ${JSON.stringify(event.confidenceRating)}`);
});

phoneCall.on(CallsApiEvent.MACHINE_DETECTION_FAILED, (event) => {
    console.log(`Machine detection failed. Reason: ${event.reason}`);
});

Tutorials

Migration guides

Reference documentation

Clone this wiki locally