Skip to content

WebrtcCall

Lejla Solak edited this page Mar 31, 2025 · 11 revisions

extends Call



options()

Description

Returns call options used to construct a Viber call.

Arguments

  • none

Returns

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
WebrtcCallOptions webrtcCallOptions = webrtcCall.options();



customData()

Description

Getter for the customData field.

Arguments

  • none

Returns

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
Map<String, String> customData = webrtcCall.customData();



setEventListener(webrtcCallEventListener)

Description

Configures event handler for webrtc call events.

Arguments

  • webrtcCallEventListener: WebrtcCallEventListener - Interface with event methods that should be implemented, method per WebRTC call event to be handled.

Returns

  • N/A

Example

private void example() {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    webrtcCall.setEventListener(new DefaultWebrtcCallEventListener() {
        @Override
        public void onRinging(CallRingingEvent callRingingEvent) {
            Toast.makeText(getApplicationContext(), "Ringing!", Toast.LENGTH_LONG);
        }

        @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(ErrorEvent errorEvent) {
            Toast.makeText(getApplicationContext(), "Error!", Toast.LENGTH_LONG);
        }
    });
}



webrtcCallEventListener()

Description

Returns event handler for WebRTC call events.

Arguments

  • none

Returns

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
WebrtcCallEventListener webrtcCallEventListener = webrtcCall.getEventListener();



cameraVideo(cameraVideo)

Description

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

Arguments

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

Returns

  • N/A

Throws

Example

private void example() {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    try {
        webrtcCall.cameraVideo(true);
    } catch (ActionFailedException e) {
        Log.w("WebRTC", String.format("Failed to execute action. Error: %s", e.getErrorCode().getDescription()));
    }
}



startScreenShare(screenCapturer)

Description

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

Note: Starting from Android 14, screen share must be started from a foreground service. For more information, please refer to the Screen Share tutorial.

Arguments

Returns

  • N/A

Throws

Example

private void startScreenShare(int resultCode, Intent data) {
    try {
        ScreenCapturer screenCapturer = new ScreenCapturer(resultCode, data);
        Call call = InfobipRTC.getInstance().getActiveCall();
        if (call instanceof WebrtcCall) {
            WebrtcCall webrtcCall = (WebrtcCall) call;
            webrtcCall.startScreenShare(screenCapturer);
        }
    } catch (ActionFailedException e) {
        Log.e("ScreenShareService", "Failed to start screen share", e);
    }
}



resetScreenShare()

Description

The size of the media projection can change when the device is rotated or the user selects an app window as the capture region in app screen sharing. The media projection might be letterboxed if the captured content differs from the window size obtained when screen sharing started.

To prevent this and ensure the projection matches the captured content’s size and aspect ratio, use this method to resize the capture whenever the content changes - whether due to rotation or a different windowing mode.

Note: On Android 14 and later, the system automatically handles resizing, so you only need to call this method on earlier versions. If called on Android 14 or later, it has no effect as it is ignored.

Arguments

  • none

Returns

  • N/A

Example

Specify the configuration changes your app handles by setting the android:configChanges attribute of the <activity> element in your AndroidManifest.xml file.

Note: Android handles any configuration changes you don't specify in configChanges; that is, the system destroys and recreates your app's activities.

For example, enable your app to handle screen size and orientation changes:

<activity
        android:name=".MainActivity"
        android:configChanges="orientation|screenSize"/>
public class MainActivity extends AppCompatActivity {
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Check for screen size or orientation changes
        if ((newConfig.configChanges & (Configuration.CONFIG_SCREEN_SIZE | Configuration.CONFIG_ORIENTATION)) != 0) {
            Call call = InfobipRTC.getInstance().getActiveCall();
            if (call instanceof WebrtcCall) {
                WebrtcCall webrtcCall = (WebrtcCall) call;
                webrtcCall.resetScreenShare();
            }
        }
    }
}



stopScreenShare()

Description

Stops sharing screen with the remote peer.

Arguments

  • none

Returns

  • N/A

Throws

Example

private void example() {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    try {
        webrtcCall.stopScreenShare();
    } catch (ActionFailedException e) {
        Log.w("WebRTC", String.format("Failed to execute action. Error: %s", e.getErrorCode().getDescription()));
    }
}



hasCameraVideo()

Description

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

Arguments

  • none

Returns

  • boolean - Represents whether the WebRTC call has camera video. true if it does, otherwise false.

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
boolean hasCameraVideo = webrtcCall.hasCameraVideo();



hasScreenShare()

Description

Returns information whether the current WebRTC call has local screen share.

Arguments

  • none

Returns

  • boolean - Whether the screen is being shared or not

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
boolean hasScreenShare = webrtcCall.hasScreenShare();



hasRemoteCameraVideo()

Description

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

Arguments

  • none

Returns

  • boolean - Represents whether the WebRTC call has remote camera video. true if it does, otherwise false.

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
boolean hasRemoteCameraVideo = webrtcCall.hasRemoteCameraVideo();



hasRemoteScreenShare()

Description

Returns information whether the current WebRTC call has remote screen share.

Arguments

  • none

Returns

  • boolean - Whether the remote screen is being shared or not

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
boolean hasRemoteScreenShare = webrtcCall.hasRemoteScreenShare();



localCameraTrack()

Description

Returns video track for local camera video.

Arguments

  • none

Returns

  • RTCVideoTrack - Video track representing local camera stream. null if there is no local camera video.

Example

private void example() {
    VideoRenderer localCameraVideoRenderer = findViewById(R.id.local_camera_video);
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    RTCVideoTrack localCamera = webrtcCall.localCameraTrack();
    if (localCamera != null) {
        localCamera.addSink(localCameraVideoRenderer);
    }
}



localScreenShareTrack()

Description

Returns video track for local screen share.

Arguments

  • none

Returns

  • RTCVideoTrack - Video track representing local screen share stream. nil if there is no local screen share.

Example

private void example() {
    VideoRenderer localScreenShareVideoRenderer = findViewById(R.id.local_screen_share_video);
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    RTCVideoTrack localScreenShare = webrtcCall.localScreenShareTrack();
    if (localScreenShare != null) {
        localScreenShare.addSink(localScreenShareVideoRenderer);
    }
}



remoteCameraTrack()

Description

Returns video track for remote camera video.

Arguments

  • none

Returns

  • RTCVideoTrack - Video track representing remote camera stream. null if there is no remote camera video.

Example

private void example() {
    VideoRenderer remoteCameraVideoRenderer = findViewById(R.id.remote_camera_video);
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    RTCVideoTrack remoteCamera = webrtcCall.remoteCameraTrack();
    if (remoteCamera != null) {
        remoteCamera.addSink(remoteCameraVideoRenderer);
    }
}



remoteScreenShareTrack()

Description

Returns video track for remote screen share.

Arguments

  • none

Returns

  • RTCVideoTrack - Video track representing remote screen share stream. null if there is no remote

Example

private void example() {
    VideoRenderer remoteScreenShareVideoRenderer = findViewById(R.id.remote_screen_share_video);
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    RTCVideoTrack remoteScreenShare = webrtcCall.remoteScreenShareTrack();
    if (remoteScreenShare != null) {
        remoteScreenShare.addSink(remoteScreenShareVideoRenderer);
    }
}



cameraOrientation(cameraOrientation)

Description

Change the local camera facing mode. No action will be performed if the current camera facing mode is the same as the requested one. Default value is FRONT.

Arguments

Returns

  • N/A

Example

private void example() {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    webrtcCall.cameraOrientation(VideoOptions.CameraOrientation.BACK);
}



cameraOrientation()

Description

Returns the current camera facing mode.

Arguments

  • none

Returns

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
VideoOptions.CameraOrientation cameraOrientation = webrtcCall.cameraOrientation();



pauseIncomingVideo()

Description

Pauses incoming video media.

Arguments

  • none

Returns

  • N/A

Throws

Example

private void example() {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    try {
        webrtcCall.pauseIncomingVideo();
    } catch (ActionFailedException e) {
        Log.w("WebRTC", String.format("Failed to execute action. Error: %s", e.getErrorCode().getDescription()));
    }
}



resumeIncomingVideo()

Description

Resumes incoming video media.

Arguments

  • none

Returns

  • N/A

Throws

Example

private void example() {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    try {
        webrtcCall.resumeIncomingVideo();
    } catch (ActionFailedException e) {
        Log.w("WebRTC", String.format("Failed to execute action. Error: %s", e.getErrorCode().getDescription()));
    }
}



setRemoteNetworkQualityEventListener(remoteNetworkQualityEventListener)

Description

Configures event handler for remote participant's network quality events.

Arguments

  • remoteNetworkQualityEventListener: RemoteNetworkQualityEventListener - Interface that should be implemented in order to handle remote participant's network quality events properly.

Returns

  • N/A

Example

private void example() {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    webrtcCall.setRemoteNetworkQualityEventListener(remoteNetworkQualityChangedEvent -> {
        NetworkQuality networkQuality = remoteNetworkQualityChangedEvent.getNetworkQuality();
        Log.d("WebRTC", String.format("Remote participant's network quality changed to %s (value %s)", networkQuality, networkQuality.getScore()));
    });
}



getRemoteNetworkQualityEventListener()

Description

Returns event handler for remote participant's network quality events.

Arguments

  • none

Returns

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
RemoteNetworkQualityEventListener remoteNetworkQualityEventListener = webrtcCall.getRemoteNetworkQualityEventListener();



dataChannel()

Description

Returns the instance of DataChannel that should be used to send and receive data during the current call.

Arguments

  • none

Returns

  • DataChannel - An instance of DataChannel specifically designed for handling actions on data channel. null if data channel is not enabled in call options.

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
DataChannel dataChannel = webrtcCall.dataChannel();



getVideoFilter()

Description

This method returns the instance of VideoFilter currently in use.

Arguments

  • none

Returns

Example

InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
VideoFilter videoFilter = webrtcCall.getVideoFilter();



setVideoFilter(videoFilter)

Description

This method sets the video filter to be used during the video call. Passing null will remove and release any already existing video filter.

Arguments

  • videoFilter: VideoFilter - An instance of VideoFilter.

Returns

  • N/A

Example

private void example() {
    VideoFilter videoFilter = createVideoFilter();
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    webrtcCall.setVideoFilter(videoFilter);
}



clearVideoFilter()

Description

This convenience method removes the video filter if it is present.

Arguments

  • none

Returns

  • N/A

Example

private void example() {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    webrtcCall.clearVideoFilter();
}



hangup()

Description

Hangs up call.

Arguments

  • none

Returns

  • N/A

Example

private void example() {
    InfobipRTC infobipRTC = InfobipRTC.getInstance();
    WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
    webrtcCall.hangup();
}

Tutorials

Migration guides

Reference documentation

Clone this wiki locally