Skip to content
Adnan Arnautović edited this page Sep 12, 2022 · 16 revisions

id()

Description

Returns a unique call identifier on Infobip RTC platform.

Arguments

  • none

Returns

Example

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



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

  • none

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
call.on('established', _ => {
    call.hangup();
});



on(eventName, eventHandler)

Description

Configures the event handler for call events.

Arguments

  • eventName: string - Name of the call event. Allowed values are: ringing, early-media, established, updated , hangup, error, network-quality-changed, remote-network-quality-changed, user-muted and user-unmuted. ringing and early-media events are for OutgoingCall only. early-media event is used for phone number calls only. It is emitted when other side is sending ringback tone.

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

    • ringing - No additional fields will be passed.

      event = {}
    • early-media - localStream and remoteStream fields (media streams of both parties of the call) will be provided.

      event = {localStream: streamObject, remoteStream: streamObject}
    • established - localStream and remoteStream fields (media streams of both parties of the call) will be provided.

      event = {localStream: streamObject, remoteStream: streamObject}
    • updated - localStream and remoteStream fields (media streams of both parties of the call) will be provided.

      event = {localStream: streamObject, remoteStream: streamObject}
    • hangup - Call status field (instance of HangupStatus class), describing the reason why the call was hung up will be provided.

      event = {id: 0, description: 'No error.', name: 'NO_ERROR'}
    • error - Contains call status field (instance of HangupStatus class), describing the reason why the error occurred, will be provided.

      event = {id: 5002, description: 'The end user is currently busy and can not receive a call.', name: '
          EC_VOICE_USER_BUSY'}
    • network-quality-changed - NetworkQuality enum value which corresponds to the local network quality will be provided.

      event = {networkQuality: networkQualityObject}
    • remote-network-quality-changed - NetworkQuality enum value which corresponds to the remote network quality will be provided.

      event = {networkQuality: networkQualityObject}
    • user-muted - Fires when user mutes themselves. No additional fields will be passed.

      event = {}
    • user-unmuted - Fires when user unmutes themselves. No additional fields will be passed.

      event = {}

Returns

  • none

Example

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

When you receive the established event from our SDK, you will have local and remote video streams in this event (if they exist), which you need to set as a source on your corresponding HTML elements.

In case some changes occurred during the call (e.g. a participant toggles video), you will receive updated event with updated video streams, both local and remote.

For instance, let's consider a participant toggles video or screen share, then:

  • In case it's an audio call, when a local participant starts sending video or initiates screen share, they should display the HTML element with the id localVideo snd attach the local stream received in this event on it. The remote participant should start displaying the HTML element with the id remoteVideo and attach the remote stream received in this event on it.

  • In a video call where both participants already have video, when one participant starts sharing their screen, the local participant should update their local stream received in this event, while the remote participant doesn't have to perform any actions as they are already displaying the remote stream.

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

call.on('ringing', () => _ => {
    console.log('Ringing....');
});
call.on('early-media', () => _ => {
    console.log('Ringing....');
});
call.on('established', (event) => {
    $('#localVideo').srcObject = event.localStream;
    $('#remoteVideo').srcObject = event.remoteStream;
});
call.on('updated', (event) => {
    $('#localVideo').srcObject = event.localStream;
    $('#remoteVideo').srcObject = event.remoteStream;
});
call.on('network-quality-changed', (event) => {
});
call.on('remote-network-quality-changed', (event) => {
});
call.on('user-muted', () => _ => {
    console.log('User muted');
});
call.on('user-unmuted', () => _ => {
    console.log('User unmuted');
});
call.on('hangup', function (event) {
    console.log(`Call finished. Status: ${event.name}`);
});
call.on('error', function (event) {
    console.log(`Call finished. Error: ${event.name}`);
});



mute(shouldMute)

Description

Toggles mute option.

Arguments

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

Returns

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
call.on('established', _ => {
    call.mute(true)
        .catch(error => console.log("Error: {}", error));
});



sendDTMF(dtmf)

Description

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

Arguments

  • dtmf: string - One of the allowed DTMF characters (digits from 0 to 9, letters from A to D, symbols * and #).

Returns

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
call.on('established', _ => {
    call.sendDTMF('1')
        .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 = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
call.on('established', _ => {
    call.mute(true);
    let muted = call.muted() ? "muted" : "not muted";
    console.log(`Audio is ${muted}`);
});



status()

Description

Returns current call status.

Arguments

  • none

Returns

Example

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



correlationId()

Description

Returns a unique conversation identifier shared for every call leg included in a single conversation.

Arguments

  • none

Returns

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
console.log(`Correlation ID: ${call.correlationId()}`);



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 = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
call.on('hangup', _ => {
    let durationInSeconds = call.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 = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
console.log(`Start time: ${call.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 = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
call.on('established', _ => {
    console.log(`Establish time: ${call.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 = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');

call.on('established', _ => {
    call.hangup();
});

call.on('hangup', _ => {
    console.log(`End time: ${call.endTime()}`);
});



localVideo(localVideo)

Description

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

Arguments

  • localVideo: boolean - Whether local video should be enabled.

Returns

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
call.on('established', _ => {
    call.localVideo(true)
        .catch(error => console.log("Error: {}", error));
});



hasLocalVideo()

Description

Returns information whether the current call has local video.

Arguments

  • none

Returns

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

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let callOptions = CallOptions.builder().setVideo(true).build();
let outgoingCall = infobipRTC.call('alice', callOptions);
let callType = outgoingCall.hasLocalVideo() ? 'video' : 'audio';
console.log(`Making ${callType} outgoing call.`);



hasRemoteVideo()

Description

Returns information whether the current call has remote video.

Arguments

  • none

Returns

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

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.on('incoming-call', function (incomingCallEvent) {
    let incomingCall = incomingCallEvent.incomingCall;
    let callType = incomingCall.hasRemoteVideo() ? 'video' : 'audio';
    console.log(`Received ${callType} incoming 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 = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
call.on('established', _ => {
    call.screenShare(true)
        .catch(error => console.log("Error: {}", error));
});
call.on('updated', _ => {
    console.log('Started sharing screen');
})



hasScreenShare()

Description

Returns information whether screen is being shared with remote peer.

Arguments

  • none

Returns

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

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
call.on('established', _ => {
    call.screenShare(true);
});
call.on('updated', _ => {
    if (call.hasScreenShare()) {
        console.log('Sharing screen...');
    }
})



source()

Description

Returns the user who originated the call.

Arguments

  • none

Returns

  • User - User who initiated the call.

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
infobipRTC.on('incoming-call', function (incomingCallEvent) {
    const incomingCall = incomingCallEvent.incomingCall;
    console.log(`Received incoming call from: ${incomingCall.source().identity()}`);
});



destination()

Description

Returns the user who is receiving the call.

Arguments

  • none

Returns

  • User - User who received the call.

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let outgoingCall = infobipRTC.call('alice');
console.log(`Calling ${outgoingCall.destination().identity()}`);



getRecordingOptions()

Description

Returns call recording options indicating whether audio and/or video stream is being recorded.

Arguments

  • none

Returns

Example

let infobipRTC = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
call.on('established', _ => {
    console.log(`Call audio is being recorded: ${call.getRecordingOptions().audio()}`);
});



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 = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice');
call.on('established', _ => {
    call.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 = new InfobipRTC('2e29c3a0-730a-4526-93ce-cda44556dab5', {debug: true});
let call = infobipRTC.call('alice', CallOptions.Builder.setVideo(true).build());
call.on('established', _ => {
    call.setVideoInputDevice('videoDeviceId')
        .catch(error => console.log("Error: {}", error));
});



cameraOrientation()

Description

Returns current camera orientation.

Arguments

  • none

Returns

Example

let videoOptions = VideoOptions.builder().setCameraOrientation(CameraOrientation.BACK).build();
let callOptions = CallOptions.builder().setVideo(true).setVideoOptions(videoOptions).build();
let call = infobipRTC.call('alice', callOptions);
console.log(`Camera orientation is: ${call.cameraOrientation()}`);



setCameraOrientation(cameraOrientation)

Description

Sets a local camera orientation to the given enum value.

Arguments

Returns

Example

let call = infobipRTC.call('alice', CallOptions.Builder.setVideo(true).build());
call.on('established', _ => {
    call.setCameraOrientation(CameraOrientation.BACK)
        .catch(error => console.log("Error: {}", error));
});

Tutorials

Migration guides

Reference documentation

Clone this wiki locally