-
Notifications
You must be signed in to change notification settings - Fork 2
WebrtcCall
extends Call
WebrtcCallOptions options()Map<String, String> customData()void setEventListener(WebrtcCallEventListener webrtcCallEventListener)WebrtcCallEventListener getEventListener()void cameraVideo(boolean cameraVideo) throws ActionFailedExceptionvoid startScreenShare(ScreenCapturer screenCapturer) throws ActionFailedExceptionvoid resetScreenShare()void stopScreenShare() throws ActionFailedExceptionboolean hasCameraVideo()boolean hasScreenShare()boolen hasRemoteCameraVideo()boolean hasRemoteScreenShare()RTCVideoTrack localCameraTrack()RTCVideoTrack localScreenShareTrack()RTCVideoTrack remoteCameraTrack()RTCVideoTrack remoteScreenShareTrack()void cameraOrientation(VideoOptions.CameraOrientation cameraOrientationVideoOptions.CameraOrientation cameraOrientation()void pauseIncomingVideo() throws ActionFailedExceptionvoid resumeIncomingVideo() throws ActionFailedExceptionvoid setRemoteNetworkQualityEventListener(RemoteNetworkQualityEventListener remoteNetworkQualityEventListener)RemoteNetworkQualityEventListener getRemoteNetworkQualityEventListener()DataChannel dataChannel()VideoFilter getVideoFilter()void setVideoFilter(VideoFilter videoFilter)void clearVideoFilter()void hangup()
Returns call options used to construct a Viber call.
none
-
WebrtcCallOptions- Call options.
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
WebrtcCallOptions webrtcCallOptions = webrtcCall.options();Getter for the customData field.
none
-
Map<String, String>- The value of thecustomDatafield.
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
Map<String, String> customData = webrtcCall.customData();Configures event handler for webrtc call events.
-
webrtcCallEventListener:WebrtcCallEventListener- Interface with event methods that should be implemented, method per WebRTC call event to be handled.
N/A
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);
}
});
}Returns event handler for WebRTC call events.
none
-
WebrtcCallEventListener- Interface that should be implemented in order to handle WebRTC call events properly.
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
WebrtcCallEventListener webrtcCallEventListener = webrtcCall.getEventListener();Toggles whether camera video should be enabled or not. For video calls it is enabled by default.
-
cameraVideo:boolean- Whether camera video should be enabled or not.
N/A
-
ActionFailedException- if toggling camera video fails for any reason.
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()));
}
}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.
-
screenCapturer:ScreenCapturer- Screen capturer used for sharing.
N/A
-
ActionFailedException- if starting screen share fails for any reason.
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);
}
}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.
none
N/A
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();
}
}
}
}Stops sharing screen with the remote peer.
none
N/A
-
ActionFailedException- if stopping screen share fails for any reason.
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()));
}
}Returns information whether the current WebRTC call has local camera video or not.
none
-
boolean- Represents whether the WebRTC call has camera video.trueif it does, otherwisefalse.
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
boolean hasCameraVideo = webrtcCall.hasCameraVideo();Returns information whether the current WebRTC call has local screen share.
none
-
boolean- Whether the screen is being shared or not
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
boolean hasScreenShare = webrtcCall.hasScreenShare();Returns information whether the current WebRTC call has remote camera video or not.
none
-
boolean- Represents whether the WebRTC call has remote camera video.trueif it does, otherwisefalse.
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
boolean hasRemoteCameraVideo = webrtcCall.hasRemoteCameraVideo();Returns information whether the current WebRTC call has remote screen share.
none
-
boolean- Whether the remote screen is being shared or not
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
boolean hasRemoteScreenShare = webrtcCall.hasRemoteScreenShare();Returns video track for local camera video.
none
-
RTCVideoTrack- Video track representing local camera stream.nullif there is no local camera video.
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);
}
}Returns video track for local screen share.
none
-
RTCVideoTrack- Video track representing local screen share stream.nilif there is no local screen share.
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);
}
}Returns video track for remote camera video.
none
-
RTCVideoTrack- Video track representing remote camera stream.nullif there is no remote camera video.
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);
}
}Returns video track for remote screen share.
none
-
RTCVideoTrack- Video track representing remote screen share stream.nullif there is no remote
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);
}
}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.
-
cameraOrientation:VideoOptions.CameraOrientation- Camera orientation.
N/A
private void example() {
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
webrtcCall.cameraOrientation(VideoOptions.CameraOrientation.BACK);
}Returns the current camera facing mode.
none
-
VideoOptions.CameraOrientation- Camera orientation.
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
VideoOptions.CameraOrientation cameraOrientation = webrtcCall.cameraOrientation();Pauses incoming video media.
none
N/A
-
ActionFailedException- if a method is called while the call is in the process of reconnecting
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()));
}
}Resumes incoming video media.
none
N/A
-
ActionFailedException- if a method is called while the call is in the process of reconnecting
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()));
}
}Configures event handler for remote participant's network quality events.
-
remoteNetworkQualityEventListener:RemoteNetworkQualityEventListener- Interface that should be implemented in order to handle remote participant's network quality events properly.
N/A
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()));
});
}Returns event handler for remote participant's network quality events.
none
-
RemoteNetworkQualityEventListener- An interface that should be implemented in order to handle remote participant's network quality events properly.
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
RemoteNetworkQualityEventListener remoteNetworkQualityEventListener = webrtcCall.getRemoteNetworkQualityEventListener();Returns the instance of DataChannel that should be used to send and receive data during the current
call.
none
-
DataChannel- An instance ofDataChannelspecifically designed for handling actions on data channel.nullif data channel is not enabled in call options.
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
DataChannel dataChannel = webrtcCall.dataChannel();This method returns the instance of VideoFilter currently in use.
none
-
VideoFilter- An instance ofVideoFilter.
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
VideoFilter videoFilter = webrtcCall.getVideoFilter();This method sets the video filter to be used during the video call. Passing null will remove and release any already
existing video filter.
-
videoFilter:VideoFilter- An instance ofVideoFilter.
N/A
private void example() {
VideoFilter videoFilter = createVideoFilter();
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
webrtcCall.setVideoFilter(videoFilter);
}This convenience method removes the video filter if it is present.
none
N/A
private void example() {
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
webrtcCall.clearVideoFilter();
}Hangs up call.
none
N/A
private void example() {
InfobipRTC infobipRTC = InfobipRTC.getInstance();
WebrtcCall webrtcCall = (WebrtcCall) infobipRTC.getActiveCall();
webrtcCall.hangup();
}