Utilities

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

Audio Only Mode for Video Rooms

The window.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 does not affect video streams from others or the ability to publish/receive screen sharing in the room.

  • Method: setAudioOnlyMode( audioOnly, successCallback, errorCallback )
  • Paramters:
    • audioOnly : Boolean. Set it to true for an audio-only call.
      Set it to false for an audio-video call.
    • successCallback: Callable Function. Success Notification.
    • errorCallback: Callable Function. Error Notification.

Sample Code

window.EnxRtc.setAudioOnlyMode(audioOnly ,function (data) {
console.log('Excelsior success! ' + JSON.stringify(data.data));
}, function (err) {
console.log('Uh oh… error' + JSON.stringify(err));
}
);

Handle Application Switch

Users may switch to different applications pushing your RTC Application to background and vice versa.

To Switch to Background

  • Method: stopVideoTracksOnApplicationBackground( localMuteState, remoteMuteState , successCallback, errorCallback )
  • Parameters:
    • localMuteState: Boolean. Set it to true to pause local video streams. Set it to false to continue with publishing.
    • remoteMuteState: Boolean. Set it to true to pause receiving remote video streams. Set it to false to continue receiving.
    • successCallback: Callable Function. Success Notification.
    • errorCallback: Callable Function. Error Notification.

Sample Code

// To pause
window.EnxRtc.stopVideoTracksOnApplicationBackground(true, true, function(data) {
console.log('Excelsior success! ' + JSON.stringify(data.data));
}, function (err) {
console.log('Uh oh… error' + JSON.stringify(err));
}
);

To Switch to Foreground

  • Method: startVideoTracksOnApplicationForeground( localUnMuteState, remoteUnMuteState , successCallback, errorCallback )
  • Parameters:
    • localMuteState: Boolean. Set it to true to resume sending of local video streams if they were stopped while getting to background.
    • remoteMuteState: Set it to true to resume receiving remote video streams if they were stopped while getting to background.
    • successCallback: Callable Function. Success Notification.
    • errorCallback: Callable Function. Error Notification.

Sample Code

// To Resume
window.EnxRtc.startVideoTracksOnApplicationForeground(true, true, function(data) {
console.log('Excelsior success! ' + JSON.stringify(data.data));
}, function (err) {
console.log('Uh oh… error' + JSON.stringify(err));
}
);

Enable Proximity Sensor

EnxProximitySensor manages functions related to the "proximity sensor". On most devices, the proximity sensor is implemented as a boolean sensor.

  • It returns just two values, NEAR or FAR.

  • Thresholding is done on the LUX value, i.e., the light sensor's LUX value is compared with a threshold.

  • A LUX value more than the threshold means the proximity sensor returns FAR.

  • Anything less than the threshold value, the sensor returns NEAR.

  • Method: enableProximitySensor ( isEnabled, successCallback, errorCallback )

  • Parameters:

    • isEnabled: Boolean. Set it to true to enable proximity sensor. Set it to false to disable proximity sensor.
    • successCallback: Callable Function. Success Notification.
    • errorCallback: Callable Function. Error Notification.

Dialing Out to Phone and SIP Endpoint from a Video Room

Dial a Phone

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

  • Method: makeOutboundCall( dialout_number )
  • Parameters:
    • dialout_number: String. Phone number with Country Code to be dialed.
  • Event Listeners:
  • onOutBoundCallInitiated : The user is acknowledged that the call has been initiated |
  • onDialStateEvents : The status of the dial-out process is notified as and when it is received from the gateway. The JSON response returns the following status codes: initiated, calling, connecting, connected, terminated, failed, and disconnected.

Sample Code

// To enable stats
window.EnxRtc.makeOutboundCall(dialout_number);
// Add Event Listener: Call initiated
window.EnxRtc.addEventListner("onOutBoundCallInitiated", function(data) {
console.log(JSON.stringify(data.data));
});
// Add Event Listener: Call State updates
window.EnxRtc.addEventListner("onDialStateEvents",function (data)
console.log(JSON.stringify(data.data));
});

Error Codes

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

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

Send DTMF Response

The window.EnxRtc.sendDTMF() method allows send DTMF response to pass through an IVR if dialed out PSTN Call is connected to IVR. This method can be executed repeatedly to pass single digit or multiple digits in a single call.

An outbound PSTN Call must have been answered first to make use of sendDTMF() method to pass DTMF digits on the same PSTN channel.

  • Method: sendDTMF( dialout_number, digit )
  • Parameters:
    • dialout_number: String. It’s the same dialout_number used with makeOutboundCall() method. It can be either a PSTN Number or a SIP URI to dial out. For Phone Number, use country code without “00” or “+”.
    • digit: String. Digit(s) to pass on to Voice Service as DTMF digits.
  • Event Listeners:
  • onOutBoundCallSendDtmf : Success and failure notifications are given with error codes.

Sample Code

// To enable stats
window.EnxRtc.sendDTMF(dialout_number, digit);
// Add Event Listener: DTMF Sent/Failed
window.EnxRtc.addEventListner("onOutBoundCallSendDtmf", function(data) {
console.log(JSON.stringify(data.data));
});

Take Image Snapshot of Video Stream

The window.EnxRtc.captureScreenShot() method allows you to take a snapshot of video streams in your application. The image from a video stream is captured as a raw bitmap data into the Canvas DOM element.

  • Method: window.EnxRtc.captureScreenShot(streamId)
  • Parameters:
    • streamId: String. Stream ID of the stream for which snapshot is to be taken.
  • Event Listeners:
  • OnCapturedView : Receives the bitmap image.

Sample Code

// Capture Snapshot
window.EnxRtc.captureScreenShot(streamId);
// Add Event Listener: Snapshot captured
window.EnxRtc.addEventListner("OnCapturedView", function (data) {
// data is Bitmap data
});

Manage Log

The Cordova SDK writes different types of logs to the browser console to help with debugging during the development phase. EnableX provides two methods to access and control these log entries.

Enable Log

The IO operations to write logs may be a considerably time-consuming task. Therefore, you may like to have control to enable or disable logging.

  • Method: enableLogs(enable)
  • Parameters:
    • enable: Boolean. Set it to true to enable logging.
      Set it to false to disable logging.

Sample Code

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

Share Log with EnableX to Audit

The window.EnxRtc.postClientLogs() method is used to share console logs with EnableX tech team. This method sends the latest 500 console log lines to EnableX using HTTP post. You may need to build your UI around it. Please request the user's consent before you post logs to EnableX.

You must enable logging before you can share it.

  • Method: postClientLogs()
  • Listeners:
    • onLogUploaded: Notification when log upload finishes

Sample Code

/ To post logs
window.EnxRtc.postClientLogs();
// Add Event Listener: Log upload finished
window.EnxRtc.addEventListner("onLogUploaded", , function (data) {
console.log(JSON.stringify(data.data));
});