Utilities

The Flutter SDK provides the following methods for managing different aspects of video sessions:

Audio Only Mode for a Video Room

The EnxRtc.setAudioOnlyMode() method allows you to switch to an audio-only call where you can neither receive anybody's video nor publish your video. You can use this method as a toggle to switch between audio-only and audio-video calls. It doesn't affect others' video streams in the room.

Class: EnxRtc

Method: static Future<void> setAudioOnlyMode(bool audioOnly)

Parameter: audioOnly: Boolean. Set it to true to switch to an audio-only call.
Set it to false to switch to an audio-video call.

Sample Code

EnxRtc.setAudioOnlyMode(true); // Move to Audio Only call

Handle Application Switch from Foreground to Background

The following methods switch the RTC application to the background and vice versa. The methods allow you to configure whether to continue streaming or pause it after the switch.

Moving Application to Background

The EnxRtc.stopVideoTracksOnApplicationBackground() method switches the RTC application to the background.

Class: EnxRtc

Parameters

Parameter Data Type Description
videoMuteLocalStream Boolean

Set it to false to pause publishing of local video streams.
Set it to true to continue publishing local video streams.

videoMuteRemoteStream Boolean

Set it to false to pause receiving remote video streams.
Set it to true to continue receiving remote video streams.

Moving Application to Foreground

The EnxRtc.startVideoTracksOnApplicationForeground() method switches the RTC application to the foreground.

Class: EnxRtc

Parameters Data Type Description
restoreVideoLocalStream Boolean

Set it to true to resume sending local video streams if they were stopped while switching to the background.

restoreVideoRemoteStream Boolean

Set it to true to resume receiving remote video streams if they were stopped while switching to the background.

Sample Code

// When application goes to Background
EnxRtc.stopVideoTracksOnApplicationBackground(localMuteState, remoteMuteState);
// When application comes back to Foreground
EnxRtc.startVideoTracksOnApplicationForeground(
remoteUnmuteState,
localUnmuteState
);

Set Video Scaling Type

The EnxRtc.setScalingType() method updates the scaling type EnxPlayerWidget.

Class: EnxRtc

Method: static Future<void>setPlayerScalingType(ScalingType scalingType,int viewId,int uid, bool isLocal)

Parameters

ParameterData TypeDescription
ScalingTypeStringConstants: SCALE_ASPECT_BALANCED
SCALE_ASPECT_FIT
SCALE_ASPECT_FILL
viewIdStringEnxPlayerWidget Id
uidStringEnxPlayerWidget Id
isLocalBooleanSet it to true if the player widget is local.

Sample Code

EnxRtc.setScalingType(type, viewId, uid, true);

Enable Proximity Sensor

The EnxRtc.enableProximitySensor() method enables the camera to detect proximity. On most devices, the proximity sensor is implemented as a boolean sensor.

  • It returns two values, NEAR or FAR.
  • Thresholding is performed on the LUX value, that is, the light Sensor's LUX value is compared with a threshold.
  • A LUX value more than the threshold value means the Proximity Sensor returns FAR.
  • For any value less than the threshold value, the sensor returns NEAR.

Class: EnxRtc

Method: static Future<void> enableProximitySensor (bool isEnabled)

*Parameter: isEnabled: Boolean. Set it to true to enable the proximity sensor.
Set it to false to disable the proximity sensor.

Sample Code

EnxRtc.enableProximitySensor(true); // Enable Sensor

Dialing Out To Phone and SIP Endpoint from a Video Room

The EnxRtc.makeOutboundCall() method initiates an outbound call to a PSTN number or SIP URI while in the session, inviting the called participant to join the session on accepting the call.

Class: EnxRtc

Method: static Future<void> makeOutboundCall(String number)

Parameter: number: String. Phone number to dial-out.

Event Listeners:

Event ListenerDescription
onOutBoundCallInitiatedTo get the call initiation status.
onDialStateEventsNotification for the status of the dial-out process. Possible status codes are initiated, calling, connecting, connected, terminated, failed, and disconnected.

Sample Code

EnxRtc.makeOutboundCall ('9896xxxxxx'); // Dial-Out the Number
EnxRtc.onOutBoundCallInitiated= (Map<dynamic, dynamic> map) {
// Receives Call State
};
EnxRtc.onDialStateEvents= (String state) {
// Receives Call State
};

Error Codes

Error codes for failure conditions to accept a dial-out request:

CodeDescription
1141The dial-out request is already in progress.
1142CLI does not match with configured phone number.

Take Image Snapshot of Video Stream

The EnxRtc.captureScreenShot method captures a snapshot of the video stream. The image from the video stream captures and returns as bitmap image to the callback.

Class: EnxRtc

Method: captureScreenShot(streamId)

Parameters

ParameterData TypeDescription
streamIdStringID of the stream from which the snapshot is to be taken.
OnCapturedViewStringReceives base64 encoded string for the captured raw bitmap.

Sample Code

EnxRtc.captureScreenShot(streamId);
EnxRtc.OnCapturedView=(Map<dynamic,dynamic> map){
};

Console Logging

The Flutter SDK writes different type of logs to the browser console to help in debugging at development phase. EnableX provides two methods to access and control these log entries.

Enable Log

The EnxRtc.enableLogs() method enables logging. IO Operations to write logs may be a considerably time-consuming task.

Class: EnxRtc

Method: static Future<void> enableLogs(bool status)

Parameter: status: Boolean. Set it to true to enable logging.
Set it to false to disable logging.

Sample Code

EnxRtc.enableLogs(true); // To enable logging
EnxRtc.enableLogs(false); // To disable logging

Share Log with EnableX to Audit

The EnxRtc.postClientLogs() method is used to share console log with EnableX tech team for audit. The method sends 500 log lines of the most recent console log to EnableX. Enable log before sharing the log and request the user's consent before you post a log to EnableX.

Class: EnxRtc

Method: static Future<void> postClientLogs()`

Sample Code

EnxRtc.postClientLogs(); // To post log to audit