Skip to content
Adnan Arnautović edited this page May 25, 2022 · 12 revisions

id()

Description

Returns ID of a call, unique identifier for every call on Infobip RTC platform.

Arguments

none

Returns

String - Call ID.

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
Toast.makeText(getApplicationContext(), "Call ID: " + call.id(), Toast.LENGTH_LONG);



correlationId()

Description

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

Arguments

none

Returns

String - Correlation ID.

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
Toast.makeText(getApplicationContext(), "Correlation ID: " + call.correlationId(), Toast.LENGTH_LONG);



callOptions()

Description

Returns call options used to construct a call.

Arguments

none

Returns

CallOptions - Call options.

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);
CallOptions callOptions = CallOptions.builder().build();

OutgoingCall call = InfobipRTC.call(callRequest, callOptions);
Toast.makeText(getApplicationContext(), "Call options: " + call.callOptions(), Toast.LENGTH_LONG);



recordingOptions()

Description

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

Arguments

none

Returns

RecordingOptions - Recording options.

Example

Call call = InfobipRTC.getActiveCall();
RecordingOptions recordingOptions = call.getRecordingOptions();
Toast.makeText(getApplicationContext(),
    String.format("Call audio stream recorded: %s, video stream recored: %s", recordingOptions.isAudio(), recordingOptions.isVideo()),
    Toast.LENGTH_LONG);



status()

Description

Returns current call status.

Arguments

none

Returns

CallStatus - Call status.

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
Toast.makeText(getApplicationContext(), "Call status: " + call.status(), Toast.LENGTH_LONG);



hangup()

Description

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

Arguments

none

Returns

none

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
call.setEventListener(new DefaultCallEventListener() {
    @Override
    public void onEstablished(CallEstablishedEvent callEstablishedEvent) {
        call.hangup();
    }
});



setEventListener(callEventListener)

Description

Configures event handler for call events.

Arguments

  • callEventListener: CallEventListener - Interface with event methods that should be implemented, method per call event to be handled.

Returns

none

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
call.setEventListener(new CallEventListener() {
    @Override
    public void onEstablished(CallEstablishedEvent callEstablishedEvent) {
        Toast.makeText(getApplicationContext(), "Established!", Toast.LENGTH_LONG);
    }

    @Override
    public void onHangup(CallHangupEvent callHangupEvent) {
        Toast.makeText(getApplicationContext(), "Hangup!", Toast.LENGTH_LONG);
    }

    @Override
    public void onError(CallErrorEvent callErrorEvent) {
        Toast.makeText(getApplicationContext(), "Error!", Toast.LENGTH_LONG);
    }

    @Override
    public void onRinging(CallRingingEvent callRingingEvent) {
        Toast.makeText(getApplicationContext(), "Ringing!", Toast.LENGTH_LONG);
    }
});



setNetworkQualityListener(networkQualityListener)

Description

Configures event handler for network quality events.

Arguments

  • networkQualityListener: networkQualityListener - Interface that should be implemented in order to handle network events properly.

Returns

none

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);

call.setNetworkQualityListener(new NetworkQualityListener() {
    @Override
    public void onNetworkQualityChanged(NetworkQualityChangedEvent networkQualityChangedEvent) {
        runOnUiThread(() -> {
            NetworkQuality networkQuality = networkQualityChangedEvent.getNetworkQuality();
            Log.d("WebRTC", String.format("Local network quality is: %s (score: %s)", networkQuality, networkQuality.getScore()));
        });
    }

    @Override
    public void onRemoteNetworkQualityChanged(NetworkQualityChangedEvent remoteNetworkQualityChangedEvent) {
        runOnUiThread(() -> {
            NetworkQuality networkQuality = remoteNetworkQualityChangedEvent.getNetworkQuality();
            Log.d("WebRTC", String.format("Remote network quality is: %s (score: %s)", networkQuality, networkQuality.getScore()));
        });
    }
});



mute(shouldMute)

Description

Toggles mute option.

Arguments

shouldMute: boolean - Whether call should be muted after action or not.

Returns

none

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
call.setEventListener(new DefaultCallEventListener() {
    @Override
    public void onEstablished(CallEstablishedEvent callEstablishedEvent) {
        call.mute(true);
    }
});



sendDTMF(dtmf) throws ActionFailedException

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, * and #).

Returns

none

Throws

ActionFailedException - if sending fails for any reason.

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
call.setEventListener(new DefaultCallEventListener() {
    @Override
    public void onEstablished(CallEstablishedEvent callEstablishedEvent) {
        call.sendDTMF("1");
    }
});



speakerphone(enabled)

Description

Toggles whether sound should be played on the speakerphone or not. When call is started, it is disabled by default.

Arguments

enabled: boolean - Whether sound should be played on the speakerphone or not.

Returns

none

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
call.setEventListener(new DefaultCallEventListener() {
    @Override
    public void onEstablished(CallEstablishedEvent callEstablishedEvent) {
        call.speakerphone(true);
    }
});



muted()

Description

Returns information whether audio is muted or not.

Arguments

none

Returns

boolean - Is audio muted

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
String muted = call.muted() ? "muted" : "not muted";
Toast.makeText(getApplicationContext(), "Audio is " + muted , Toast.LENGTH_LONG);



speakerphone()

Description

Returns information whether speakerphone is enabled or not.

Arguments

none

Returns

boolean - Is speakerphone on

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
String speakerphoneOn = call.speakerphone() ? "on" : "off";
Toast.makeText(getApplicationContext(), "Speakerphone is " + speakerphoneOn, Toast.LENGTH_LONG);



duration()

Description

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

Arguments

none

Returns

int - Call duration

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
call.setEventListener(new CallEventListener() {
    @Override
    public void onHangup(CallHangupEvent callHangupEvent) {
        int durationInSeconds = call.duration();
        int seconds = durationInSeconds % 60;
        long minutes = durationInSeconds / 60 % 60;
        long hours = durationInSeconds / 3600;
        String duration = String.format(Locale.getDefault(), "%02d:%02d:%02d", hours, minutes, seconds);
        Toast.makeText(getApplicationContext(), "Duration: " + duration, Toast.LENGTH_LONG);
    }
});



startTime()

Description

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

Arguments

none

Returns

Date - Time when the call started

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
Date startTime = call.startTime();
Toast.makeText(getApplicationContext(), "Start time: " + call.startTime(), Toast.LENGTH_LONG).show();



endTime()

Description

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

Arguments

none

Returns

Date - Time when the call finished

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
call.setEventListener(new CallEventListener() {
    @Override
    public void onEstablished(CallEstablishedEvent callEstablishedEvent) {
        call.hangup();
    }

    @Override
    public void onHangup(CallHangupEvent callHangupEvent) {
        Toast.makeText(getApplicationContext(), "End time: " + call.endTime(), Toast.LENGTH_LONG);
    }
});



establishTime()

Description

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

Arguments

none

Returns

Date - Time when the call was established

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
call.setEventListener(new CallEventListener() {
    @Override
    public void onEstablished(CallEstablishedEvent callEstablishedEvent) {
        Toast.makeText(getApplicationContext(), "Establish time: " + call.establishTime(), Toast.LENGTH_LONG);
    }
});



hasLocalVideo()

Description

Returns information whether the current call has local video or not.

Arguments

none

Returns

boolean - Call has local video

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);
CallOptions callOptions = CallOptions.builder()
                          .video(true)
                          .build();

OutgoingCall call = InfobipRTC.call(callRequest, callOptions);
String hasLocalVideo = call.hasLocalVideo() ? "has" : "doesn't have";
Toast.makeText(getApplicationContext(), "Call " + hasLocalVideo + " local video", Toast.LENGTH_LONG);



hasRemoteVideo()

Description

Returns information whether the current call has remote video or not.

Arguments

none

Returns

boolean - Call has remote video

Example

IncomingCallEventListener incomingCallEventListener = new IncomingCallEventListener() {
    @Override
    public void onIncomingCall(IncomingCallEvent incomingCallEvent) {
        IncomingCall incomingCall = incomingCallEvent.getIncomingCall();
        String hasRemoteVideo = incomingCall.hasRemoteVideo() ? "has" : "doesn't have";
        Log.d("WebRTC", "Call " + hasRemoteVideo + " remote video");
    }
};



localVideo(localVideo)

Description

Toggles whether local video should be enabled or not. For video calls it is enabled by default.

Arguments

localVideo: boolean - Whether local video should be enabled or not.

Returns

none

Example

Call call = InfobipRTC.getActiveCall();
call.localVideo(true); // Start sending local video stream to remote peer



source()

Description

Returns User who originated call.

Arguments

none

Returns

User - User who originated call.

Example

IncomingCallEventListener incomingCallEventListener = new IncomingCallEventListener() {
    @Override
    public void onIncomingCall(IncomingCallEvent incomingCallEvent) {
        IncomingCall incomingCall = incomingCallEvent.getIncomingCall();
        Log.d("WebRTC", incomingCall.destination().getIdentity() + " received incoming call from:  " + incomingCall.source().getIdentity());
    }
};



destination()

Description

Returns destination User which was called.

Arguments

none

Returns

User - Destination to which call was placed.

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

OutgoingCall call = InfobipRTC.call(callRequest);
Toast.makeText(getApplicationContext(), call.source().getIdentity() + " is calling " + call.destination().getIdentity(), Toast.LENGTH_LONG);



startScreenShare(ScreenCapturer screenCapturer)

Description

Starts sharing screen with the remote peer. Needs to be called after CallEstablishedEvent is received.

Arguments

ScreenCapturer - Screen capturer used for sharing.

Returns

none

Example

public class Foo extends AppCompatActivity {
    private Call call;
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode != 1) {
            return;
        }

        ScreenCapturer screenCapturer = new ScreenCapturer(resultCode, data);
        
        Call call = InfobipRTC.getActiveCall();
        call.startScreenShare(screenCapturer);
    }

    public void startScreenShare() {
        MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getApplication().getSystemService(Context.MEDIA_PROJECTION_SERVICE);
        startActivityForResult(mediaProjectionManager.createScreenCaptureIntent(), 1);
    }
}



stopScreenShare()

Description

Stops sharing screen with the remote peer.

Arguments

none

Returns

none

Example

Call call = InfobipRTC.getActiveCall();
call.stopScreenShare();



hasScreenShare()

Description

Returns true if screen is being shared with remote peer, else false.

Arguments

none

Returns

boolean - Whether screen is being shared with remote peer or not

Example

Call call = InfobipRTC.getActiveCall();
Log.d("WebRTC", String.format("Call %s is sharing screen: %s", call.id(), call.hasScreenShare()));



cameraOrientation(VideoOptions.CameraOrientation cameraOrientation

Description

Change local video orientation.

Arguments

Returns

none

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);
VideoOptions videoOptions = VideoOptions.builder()
                            .cameraOrientation(VideoOptions.CameraOrientation.FRONT)
                            .build();

CallOptions callOptions = CallOptions.builder()
                          .video(true)
                          .videoOptions(videoOptions)
                          .build();

OutgoingCall call = InfobipRTC.call(callRequest, callOptions);
call.setEventListener(new DefaultCallEventListener() {
    @Override
    public void onEstablished(CallEstablishedEvent callEstablishedEvent) {
        call.cameraOrientation(VideoOptions.CameraOrientation.BACK);
    }
});



VideoOptions.CameraOrientation cameraOrientation()

Description

Get current camera orientation.

Arguments

none

Returns

VideoOptions.CameraOrientation - Camera orientation.

Example

String token = obtainToken();
CallRequest callRequest = new CallRequest(
    token,
    getApplicationContext(),
    "Alice",
    new DefaultCallEventListener()
);

VideoOptions videoOptions = VideoOptions.builder()
                            .cameraOrientation(VideoOptions.CameraOrientation.FRONT)
                            .build();

CallOptions callOptions = CallOptions.builder()
                          .video(true)
                          .videoOptions(videoOptions)
                          .build();

OutgoingCall call = InfobipRTC.call(callRequest, callOptions);
String cameraOrientation = call.cameraOrientation().name();
Toast.makeText(getApplicationContext(), "Camera orientation is " + cameraOrientation, Toast.LENGTH_LONG);
});

Tutorials

Migration guides

Reference documentation

Clone this wiki locally