Skip to content

ApplicationCall

Ajša Terko edited this page Feb 22, 2023 · 30 revisions



id()

Description

Returns a unique call identifier.

Arguments

  • none

Returns

Example

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



on(eventName, eventHandler)

Description

Configures the event handler for application call events.

Arguments

  • eventName: CallsApiEvent - Name of the application call event. Allowed values are shown in 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 - Error code data is received in the event object containing three string values that describe why the call hung up.

      event = {id: string, name: string, description: string}
    • ERROR - Error code data is received in the event object containing three string values that describe what caused the error.

      event = {id: string, name: string, description: string}
    • CAMERA_VIDEO_ADDED - A MediaStream object representing the media in the call is received in the event object.

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

      event = {stream: MediaStream}
    • CAMERA_VIDEO_REMOVED - No additional data is provided in the event object.

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

      event = {stream: MediaStream}
    • SCREEN_SHARE_REMOVED - No additional data is provided in the event object.

      event = {}
    • CONFERENCE_JOINED - Data containing conference information is received in the event object. It contains conference id, name and array of Participant objects representing the participants that are already in the conference.

      event = {id: string, name: string, participants: Participant[]}
    • CONFERENCE_LEFT - Error code data is received in the event object containing three string values that describe why the participant left the conference.

      event = {id: string, name: string, description: string}
    • PARTICIPANT_JOINING - A Participant object representing the participant joining the conference.

      event = {participant: Participant}
    • PARTICIPANT_JOINED - A Participant object representing the participant that joined the conference.

      event = {participant: Participant}
    • PARTICIPANT_MUTED - A Participant object representing the participant that was muted.

      event = {participant: Participant}
    • PARTICIPANT_UNMUTED - A Participant object representing the participant that was unmuted.

      event = {participant: Participant}
    • PARTICIPANT_DEAF - A Participant object representing the participant that was deafened.

      event = {participant: Participant}
    • PARTICIPANT_UNDEAF - A Participant object representing the participant that was undeafened.

      event = {participant: Participant}
    • PARTICIPANT_STARTED_TALKING - A Participant object representing the participant that started talking.

      event = {participant: Participant}
    • PARTICIPANT_STOPPED_TALKING - A Participant object representing the participant that stopped talking.

      event = {participant: Participant}
    • PARTICIPANT_LEFT - A Participant object representing the participant that left the conference.

      event = {participant: Participant}
    • PARTICIPANT_CAMERA_VIDEO_ADDED - A Participant and MediaStream object representing the participant and their camera video stream.

      event = {participant: Participant, stream: MediaStream}
    • PARTICIPANT_CAMERA_VIDEO_REMOVED - A Participant object representing the participant that removed their camera video.

      event = {participant: Participant}
    • PARTICIPANT_SCREEN_SHARE_ADDED - A Participant and MediaStream object representing the participant and their screen share stream.

      event = {participant: Participant, stream: MediaStream}
    • PARTICIPANT_SCREEN_SHARE_REMOVED - A Participant object representing the participant that removed their screen share.

      event = {participant: Participant}

Returns

  • N/A

Example

Let's assume you have an audio HTML element with the id callAudio and video HTML elements with the ids localVideo and remoteVideo.

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

applicationCall.on(CallsApiEvent.RINGING, () => {
    console.log('Ringing...');
});

applicationCall.on(CallsApiEvent.EARLY_MEDIA, (event) => {
    console.log('Ringtone playing...');
    $('#callAudio').srcObject = event.stream;
});

applicationCall.on(CallsApiEvent.ESTABLISHED, (event) => {
    $('#callAudio').srcObject = event.stream;
});

applicationCall.on(CallsApiEvent.CAMERA_VIDEO_ADDED, (event) => {
    $('#localVideo').srcObject = event.stream;
});

applicationCall.on(CallsApiEvent.PARTICIPANT_CAMERA_VIDEO_ADDED, (event) => {
    console.log(`Participant: ${event.participant.endpoint.identifier} turned on their camera`);
    $('#remoteVideo').srcObject = event.stream;
});

applicationCall.on(CallsApiEvent.PARTICIPANT_MUTED, (event) => {
    console.log(`Participant: ${event.participant.endpoint.identifier} is muted`);
});

applicationCall.on(CallsApiEvent.PARTICIPANT_UNMUTED, (event) => _ => {
    console.log(`Participant: ${event.participant.endpoint.identifier} is unmuted`);
});

applicationCall.on(CallsApiEvent.HANGUP, (event) => {
    console.log(`Call finished. Status: ${event.name}`);
});

applicationCall.on(CallsApiEvent.ERROR, (event) => {
    console.log(`An error has occurred. Error: ${event.name}`);
});



status()

Description

Returns current call status.

Arguments

  • none

Returns

Example

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



duration()

Description

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

Arguments

  • N/A

Returns

  • number - Call duration in seconds.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
applicationCall.on(CallsApiEvent.HANGUP, _ => {
    let durationInSeconds = applicationCall.duration();
    let seconds = ('0' + Math.floor(durationInSeconds % 60)).slice(-2);
    let minutes = ('0' + (Math.floor(durationInSeconds / 60) % 60)).slice(-2);
    let hours = ('0' + Math.floor(durationInSeconds / 3600)).slice(-2);
    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 applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
console.log(`Start time: ${applicationCall.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 applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    console.log(`Establish time: ${applicationCall.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 applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');

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

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



applicationId()

Description

Returns a unique application identifier associated with your backend application.

Arguments

  • none

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
console.log(`Application ID: ${applicationCall.applicationId()}`);



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 applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    applicationCall.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 applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    applicationCall.mute(true);
    let muted = applicationCall.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 applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    applicationCall.sendDTMF('1')
        .catch(error => console.log("Error: {}", error));
});



pauseIncomingVideo()

Description

Stop receiving the video media of other participants.

Arguments

  • none

Returns

  • N/A

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    document.addEventListener("visibilitychange", () => {
        if (document.visibilityState !== 'visible') {
            console.log('Browser lost focus, stop showing remote video media.');
            applicationCall.pauseIncomingVideo();
        }
    });
});



resumeIncomingVideo()

Description

Start receiving the video media of other participants.

Arguments

  • none

Returns

  • N/A

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    document.addEventListener("visibilitychange", () => {
        if (document.visibilityState === 'visible') {
            console.log('Browser got focus back, start showing remote video media again.');
            applicationCall.resumeIncomingVideo();
        }
    });
});



cameraVideo(cameraVideo)

Description

Controls whether the local camera video should be enabled. For video calls it is enabled by default.

Arguments

  • cameraVideo: boolean - Whether local camera video should be enabled.

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    applicationCall.cameraVideo(true)
        .catch(error => console.log("Error: {}", error));
});



hasCameraVideo()

Description

Returns information whether the current call has local camera video.

Arguments

  • none

Returns

  • boolean - true if the call has local camera video, otherwise false.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let applicationCallOptions = ApplicationCallOptions.builder().setVideo(true).build();
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628', applicationCallOptions);
let callType = applicationCall.hasLocalVideo() ? 'video' : 'audio';
console.log(`Making ${callType} application call.`);



screenShare(screenShare)

Description

Toggles sharing the screen during the call.

After one participant in the call toggles this option and starts sharing their screen, the updated event will be triggered on both sides.

This method is not available in mobile versions of browsers.

Arguments

  • screenShare: boolean - Controls whether the screen sharing should be started or stopped.

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    applicationCall.screenShare(true)
        .catch(error => console.log("Error: {}", error));
});
applicationCall.on(CallsApiEvent.SCREEN_SHARE_ADDED, _ => {
    console.log('Started sharing screen');
})



hasScreenShare()

Description

Returns information whether screen is being shared with remote peer.

Arguments

  • none

Returns

  • boolean - true if the screen is being shared, otherwise false.

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    applicationCall.screenShare(true);
});
applicationCall.on(CallsApiEvent.SCREEN_SHARE_ADDED, _ => {
    if (applicationCall.hasScreenShare()) {
        console.log('Sharing screen...');
    }
})



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 applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    applicationCall.setAudioInputDevice('audioDeviceId')
        .catch(error => console.log("Error: {}", error));
});



setVideoInputDevice(deviceId)

Description

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

Arguments

  • deviceId: string - Video input device identifier.

Returns

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628', ApplicationCallOptions.builder().setVideo(true).build());
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    applicationCall.setVideoInputDevice('videoDeviceId')
        .catch(error => console.log("Error: {}", error));
});



setAudioFilter(audioFilter)

Description

Sets the audio filter to be used during the call.

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 applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628');
let audioFilter = createAudioFilterImplementation();
applicationCall.setAudioFilter(audioFilter);



setVideoFilter(videoFilter)

Description

Sets the video filter to be used during the video call.

Arguments

  • videoFilter: VideoFilter - An object instance which implements the VideoFilter interface.

Returns

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

Example

let infobipRTC = createInfobipRtc('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628', ApplicationCallOptions.builder().setVideo(true).build());
let videoFilter = createVideoFilterImplementation();
applicationCall.setVideoFilter(videoFilter);



cameraOrientation()

Description

Returns current camera orientation.

Arguments

  • none

Returns

Example

let videoOptions = VideoOptions.builder().setCameraOrientation(CameraOrientation.BACK).build();
let applicationCallOptions = ApplicationCallOptions.builder().setVideo(true).setVideoOptions(videoOptions).build();
let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628', applicationCallOptions);
console.log(`Camera orientation is: ${applicationCall.cameraOrientation()}`);



setCameraOrientation(cameraOrientation)

Description

Sets a local camera orientation to the given enum value.

Arguments

Returns

Example

let applicationCall = infobipRTC.callApplication('45g2gql9ay4a2blu55uk1628', ApplicationCallOptions.builder().setVideo(true).build());
applicationCall.on(CallsApiEvent.ESTABLISHED, _ => {
    applicationCall.setCameraOrientation(CameraOrientation.BACK)
        .catch(error => console.log("Error: {}", error));
});



hangup()

Description

Hangs up a call, which ends up in the party receiving a CallsApiEvent.HANGUP event, after the hangup is processed by Infobip's platform.

Arguments

  • none

Returns

  • N/A

Example

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

Tutorials

Migration guides

Reference documentation

Clone this wiki locally