Utilities

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

Dialing Out to Phone and SIP Endpoint from a Video Room

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

Method: makeOutboundCall(number,callerId)

Parameters

ParameterData TypeDescription
numberStringIt can be either a PSTN number or a SIP URI to dial-out.
callerIdStringThe Calling Line Identification (CLI) Number to be added as the originator of the call.
In the case of PSTN phone numbers, this is validated against your purchased number or the opted shared number.
If the CLI does not match, the call fails with the "CLI mismatch" error.

Callbacks

CallbackData TypeDescription
dialStateEventsJSON ObjectNotifying the call initiator about the status of the dial-out process as received from the gateway.
The JSON response returns status codes as initiated, calling, connecting, connected, and terminated.
dTMFCollectedJSON ObjectNotification when DTMF input is collected. The input is collected in the form of a string of digits.

Error Codes and Exceptions

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

Audio Only Mode for a Video Room

The Enx.changeToAudioOnly() 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 does not affect video streams of others in the room.

Method: changeToAudioOnly( audioOnlyState )

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

Sample Code

Enx.changeToAudioOnly(true); // Switched to Audio-Only call
Enx.changeToAudioOnly(false); // Switched back to Audio-Video call

Handle Application Switch

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

Switch Application to Background

The following method switches the application to the background.

Method: Enx.onPause(localMuteState, remoteMuteState)

Parameters

ParameterData TypeDescription
localMuteStateBooleanSet it to false to pause publishing local video streams.
Set it to true to continue publishing local video streams.
remoteMuteStateBooleanSet it to false to pause receiving remote video streams.
Set it to true to continue receiving remote video streams.

Sample Code

// When application goes to Background
this.setState({localMuteState : false});
this.setState({remoteMuteState : false});
Enx.onPause( localMuteState, remoteMuteState );

Switch Application to Foreground

The following method switches the application to the foreground:

Method: Enx.onResume(localUnmuteState, remoteUnmuteState)

Parameters

ParameterData TypeDescription
localUnmuteStateBooleanSet it to true to resume sending local video streams if they were stopped while switching to the background.
remoteUnmuteStateBooleanSet it to true to resume receiving remote video streams if they stopped while switching to the background.

Sample Code

// When application comes back to Foreground
this.setState({localUnmuteState : true});
this.setState({remoteUnmuteState : true});
Enx.onResume( localUnmuteState, remoteUnmuteState);

Take Image Snapshot of a Video Stream

The Enx.captureScreenShot() method takes a snapshot of a video stream in your application. The image is returned as a bitmap image to the callback.

Method: Enx.captureScreenShot(streamId)

Parameter: streamId: String. ID of the stream from which the snapshot is to be taken.

Callback: capturedView: String. Receives base64 encoded string for the captured raw bitmap.

Sample Code

Enx.captureScreenShot(localStreamId);
capturedView: event => {
this.setState({
base64Icon: event
});
}
// To show captured snapshot
<Image
style={{ width: 50, height: 50 }}
source={{ uri: `data:image/png;b ase64,${this.state.base64Icon}`}}
/>

Share Log with EnableX

The Enx.postClientLogs() method is used to share console log with EnableX tech team for audit. The method sends 200KB of the most recent console log to EnableX.

Method: postClientLogs()

Callback: logsUploaded: When logs are posted to EnableX.

Note: You must enable console logging to share console logs. The Enx.enableLogs() method enables logging.

Method: enableLogs(loggingState)

Parameter: loggingState: Boolean. Set it to true to enable logging. Otherwise, set it to false.

Sample Code

Enx.enableLogs(true); // Enable Logging
Enx.postClientLogs(); // Post Log to EnableX
logsUploaded : event =>{
// Logs uploaded
// event = { msg:'success', result:0 }
}

Pre-Call Test (WebRTC Diagnostic API)

The Enx.clientDiagnostics() method acts as a diagnostic tool to detect any issue causing the RTC to fail. The API runs through predefined test cases related to WebRTC issues and reports asynchronously through an event as it passes through each test. These test cases are organized in "Test Groups" as listed below.

Microphone*Audio capture
Camera*Check supported resolutions.
Check resolution: 320×240
Check resolution: 640×480
Check resolution: 1280×720
NetworkUDP enabled with the TURN server
TCP enabled with the TURN server
IPv6 enabled with the TURN server
UDP enabled with the STUN server
TCP enabled with the STUN server
IPv6 enabled with the STUN server
ConnectivityRelay connectivity with the TURN server
Reflexive connectivity with the TURN server
Host connectivity with the TURN server
Reflexive connectivity with the STUN server
Host connectivity with the STUN server
ThroughputData throughput with the TURN server
Bandwidth*Video bandwidth with the TURN server
Audio bandwidth with the TURN server
SignalingSignaling connectivity with the TURN server

Note: Camera, Microphone, and Bandwidth test groups marked with * are not available in SDK v1.9.6.

You can also build a UI using the following API to initiate the tests and generate a diagnostic report.

Method: clientDiagnostics(clientOptions)

Parameters Keys Data Type Description
clientOptions testNames Array

Array of Test Group names. For example, [ "microphone", "camera", "network", "connectivity", "throughput", "bandwidth", "signalling"]
To test only selected Test Groups, add selected Test Group names. e.g.,["microphone", "camera"]


To test all the Test Groups, use ["all"].

audioDeviceId String

Optional
Device ID of the input audio device.

videoDeviceId String

Optional
Device ID of the input video device.

regionId String

Optional
Array of region Ids of the ICE servers. For example, ["IN", "SG", "US", "DE"].
You can get the list of region Ids from the EnableX portal.

testDurationDataThroughput String

Optional
Test duration of data throughput in seconds.
The default value is 2 seconds. The allowed range is from 1-30 seconds.

testDurationVideoBandwidth String

Optional
Test duration of video bandwidth in seconds.
The default value is 10 seconds. The allowed range is from 1-30 seconds.

testDurationAudioBandwidth String

Optional
Test duration of audio bandwidth in seconds.
The default value is 10 seconds. The allowed range is from 1-30 seconds.

stop Boolean Optional
Set to true to stop the test cases that are already in execution.

Delegate Methods

Delegate Method Data Type Description
clientDiagnosisFailed JSON Object Notification of Diagnosis failure when the API is called with the wrong parameter or a repeated attempt to call the API is made while the previous request is under process.
clientDiagnosisStopped JSON Object Notification sent when the API execution is stopped explicitly through the method call.
clientDiagnosisFinished JSON Object Notification is sent when the API completes the execution of all the test cases. A JSON object with a complete test result of all the test cases is returned.
clientDiagnosisStatus JSON Object Notification is sent with the test result of each test case as the API passes through the execution of each test till the completion or till stopped explicitly. A JSON object with test results is returned.

Explanation of Test Results

Test Group Test Case Server Result Message
Microphone Audio Capture Not Applicable Success Audio track created using device #device#.
Success Active audio input #channel# channels.
Failure Web audio run failure.
Failure No audio track is found in the returned stream.
Failure No active input channels are detected.
Failure No active input channels are detected. Microphone is most likely muted or broken. Check if it is muted in the sound settings or physically on the device, then re-run the test.
Failure Microphone input level is low. Increase the input volume or move closer to the microphone.
Failure getUserMedia failed with the #error# error.
Camera check resolution 240 Not Applicable Success The video is captured using the expected resolution.
Success Average FPS is above threshold.
Failure getUserMedia failed with the #error# error.
Failure No video track is found in the returned stream.
Failure Video track has ended and the camera has stopped working.
Failure Low average is sent to FPS.
Failure The video is captured using the incorrect resolution.
Failure Could not analyze any video frames.
Failure Camera is delivering lots of black frames.
Failure Camera is delivering lots of frozen frames.
Camera Check resolution 480 Not Applicable Success The captured video has the expected resolution.
Success Average FPS is above threshold.
Failure getUserMedia failed with the #error# error.
Failure No video track is found in the returned stream.
Failure Video track has ended and the camera has stopped working.
Failure Low average is sent FPS.
Failure The video is captured using the incorrect resolution.
Failure Could not analyze any video frames.
Failure Camera is delivering lots of black frames.
Failure Camera is delivering lots of frozen frames.
Camera check resolution 720 Not Applicable Success The captured video has the expected resolution.
Success Average FPS is above threshold.
Failure getUserMedia failed with the #error# error.
Failure No video track is found in the returned stream.
Failure The video track has ended and the camera has stopped working.
Failure Low average is sent to FPS.
Failure The video is captured with incorrect resolution.
Failure Could not analyze any video frames.
Failure Camera is delivering lots of black frames.
Failure Camera is delivering lots of frozen frames.
Camera check supported resolutions. Not Applicable Success Success Supported resolution #resolution#.
Failure No video track is found in the returned stream.
Failure The video track has ended and the camera has stopped working.
Network udp enabled TURN Success Supported resolution #resolution#.
Failure No video track is found in the returned stream.
Failure The video track has ended and the camera has stopped working.
Network udp enabled STUN Success Gathered candidate of Type: relay Protocol: udp Address: #IP#.
Failure Failed to gather the specified candidates.
Failure Failed to create peer connection: #error#.
Network tcp enabled TURN Success Gathered candidate of Type: relay Protocol: udp Address: #IP#.
Failure Failed to gather the specified candidates.
Failure Failed to create peer connection: #error#.
Network tcp enabled STUN Success Gathered candidate of Type: relay Protocol: udp Address: #IP#.
Failure Failed to gather the specified candidates.
Failure Failed to create peer connection: #error#.
Network ipv6 enabled TURN Success Gathered candidate of Type: relay Protocol: udp Address: #IP#.
Failure Failed to gather IPv6 candidates. They might not be set up/supported on the network.
Failure Failed to gather IPv6 candidates. They might not be set up/supported on the network.
Network ipv6 enabled STUN Success Gathered candidate of Type: relay Protocol: udp Address: #IP#.
Failure Failed to gather IPv6 candidates. They might not be set up/supported on the network.
Failure Failed to gather IPv6 candidates. They might not be set up/supported on the network.
Connectivity relay connectivity TURN Success Data successfully transmitted between peers.
Failure Invalid data transmitted.
Failure Time out
Connectivity relay connectivity STUN Success Data is successfully transmitted between peers.
Failure Invalid data is transmitted.
Failure Time out
Connectivity reflexive connectivity TURN Success Data is successfully transmitted between peers.
Failure Invalid data is transmitted.
Failure Time out
Connectivity reflexive connectivity STUN Success Data is successfully transmitted between peers.
Failure Invalid data is transmitted.
Failure Time out
Connectivity host connectivity TURN Success Data is successfully transmitted between peers.
Failure Invalid data is transmitted.
Failure Time out
Connectivity host connectivity STUN Success Data is successfully transmitted between peers.
Failure Invalid data is transmitted.
Failure Time out
Throughput Data Throughput TURN Success Total transmitted: #n# kilo-bits in #t# seconds.
Failure Timed out
Bandwidth Video Bandwidth TURN Success Video resolution: #Width# x #Height#
Failure Camera failure: #Width# x #Height#. Cannot test bandwidth without a working camera.
Failure getUserMedia failed with error #error#.
Failure Frame rate mean is 0, cannot test bandwidth without a working camera.
Failure Could not gather statistics.
Failure Only Firefox and Chrome getStats implementations are supported.
Bandwidth Audio Bandwidth TURN Subject to quality Average Audio bandwidth #value#
Subject to quality Packets lost: #value#
Subject to quality RTT Average: #value#
Failure getUserMedia() failed with the #error# error.
Failure Only Firefox and Chrome getStats() implementations are supported.
Signaling Signaling Connectivity Not Applicable Success Token is successfully created.
Failure Token creation has failed due to the : #error# error.
Failure Room is not joined due to the : #error# error.
Success Room is successfully joined.

EnableX Proximity Sensor

The Enx.enableProximitySensor() 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 value.
  • 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.

Method: enableProximitySensor(boolean status)

Parameter: status: Boolean. Set it to true to enable Proximity Sensor.
Otherwise, set it to false.

Sample Code

Enx.enableProximitySensor(true); // Enable Sensor