EnableX File Share API allows users of a RTC session to send and receive file(s) to/from each other. Using the available APIs, you can initiate file transfer to share, cancel a file transfer, get notified about a shared file and receive/download a shared file.

Table of Contents

Upload File to Share

The file sharing process starts with a user initiating a file transfer to EnableX Server. To initiate a file transfer use window.EnxRtc.sendFiles() method.

Method: sendFiles( isBroadcast, recipientIDs)

Parameters:

  • @param {boolean} isBroadcast – This is to share file among all participants in the Session. If you need to target the file share to a specific user, then set it to false.
  • @param {Array} recipientIDs – Array of Client IDs. This is to share the file among specified Clients only. If broadcast is set to true, recipientIDs is ignored.

Event Listeners at Sender End:

  • onInitFileUpload – To notify the sender that the file upload process is initiated
  • OnFileUploaded – To notify the sender that the file has been uploaded
  • OnFileUploadFailed – To notify the sender that the file upload process has failed

Event Listeners at Receiver End:

  • OnFileUploadStarted – To notify the intended receiver that a file is being uploaded
  • OnFileAvailable – To notify the intended received that a file is ready to download
window.EnxRtc. sendFiles ( broadcast, array);
// Add Event Listeners
// To intended receiver - A new file upload started
window.EnxRtc.addEventListner("onFileUploadStarted", function
(data)
{
console.log(JSON.stringify(data.data));
});
// To intended receiver – A file is avilable for download
window.EnxRtc.addEventListner("onFileAvailable", function
(data)
{
console.log(JSON.stringify(data.data));
});
// To intended receiver – File upload process has initialized.
window.EnxRtc.addEventListner("onInitFileUpload", function
(data)
{
console.log(JSON.stringify(data.data));
});
// To intended receiver – File upload is complete.
window.EnxRtc.addEventListner("onFileUploaded", function
(data)
{
console.log(JSON.stringify(data.data));
});
// To intended receiver – File upload has failed.
window.EnxRtc.addEventListner("onFileUploadFailed", function
console.log(JSON.stringify(data.data));
});

Error Codes: Upload process may encounter error.

Error CodeError Description
5089Storage Access denied
5091 File-Sharing not available in this context
1185Too large file. Max allowed Size: NNNN
1182Failed to upload file

Cancel a File Upload

Sender of a file may like to cancel an ongoing file upload. To do so use cancelUpload() method.

Method: cancelUpload(jobId)

Parameters: @param {Number} jobId – ID of the Job to be canceled

Event Listeners: onFileUploadCancelled – It notifies when the file upload has been canceled successfully

// To cancel single uploading file
window.EnxRtc.cancelUpload(jobId);

// Add Event Listeners
// To intended receiver – File uploading is canceled.
window.EnxRtc.addEventListner(" onFileUploadCancelled ", function
(data)
{
console.log(JSON.stringify(data.data));
});

Cancel all Files Upload

The Sender of multiple files may like to cancel an ongoing files upload. To do so use cancelAllUploads() method.

Method: cancelAllUploads() – No parameters required

Event Listeners: onFileUploadCancelled – It notifies when the file upload has been canceled successfully

// To cancel all uploading file
window.EnxRtc.cancelAllUploads();

// Add Event Listeners
// To intended receiver – File uploading is cancelled.
window.EnxRtc.addEventListner(" onFileUploadCancelled ", function
(data)
{
console.log(JSON.stringify(data.data));
});

Download a Shared File

Intended Recipients need to download each file shared with them individually. Therefore, recipients need to know the information about the available files to download to initiate a download process.

Know Files to Download

Room Lookup: To know what all files are available for download, you may call window.EnxRtc.getAvailableFiles() method. It returns list of File data.

Method: getAvailableFiles( successCallback, errorCallback )

Parameters:

  • @param {CallableFunction} successCallback
  • @param {CallableFunction} errorCallback
window.EnxRtc.getAvailableFiles(function (data) {
console.log('Excelsior success! ' + JSON.stringify(data.data));
}, function (err) {
console.log('Uh oh… error' + JSON.stringify(err));
});

When New File is available: The receiving endpoint is notified as and when a file is made available for download using Event Listener onFileAvailable

Initiate File Download

As you know about the file(s) to download, you need to initiate download individually using window.EnxRtc.downloadFile() method.

Method: downloadFile( fileInfo, isAutoSave )

Parameters:

  • @param {JSON} fileInfo – Map of the file to be downloaded.
  • @param {boolean} isAutoSave – Whether to save the file automatically. If not to be saved automatically, you would receive Base64 encoded RAW data to handle file saving processes manually. If auto-saving is on, you would receive the saved file path.

Event Listeners at Receiver End:

  • onInitFileDownload – To notify that file download process has been initiated
  • onFileDownloaded – To notify file has been downloaded with either Base64 Raw data to be saved (When auto-saving is false) or saved file path.
  • OnFileDownloadFailed – To notify download failure
window.EnxRtc.downloadFile(JSON, isAutoSave);
// Add Event Listeners
// To intended receiver – File download process has initialized.
window.EnxRtc.addEventListner(" onInitFileDownload ", function
console.log(JSON.stringify(data.data));
});
(data)
{// To receiver - File download has failed
window.EnxRtc.addEventListner("onFileDownloadFailed", function
(data)
{
console.log(JSON.stringify(data.data));
});
// To intended receiver – File has been downloaded.
window.EnxRtc.addEventListner("onFileDownloaded", function
(data)
{
console.log(JSON.stringify(data.data));
});

Error Codes: Download process may encounter error that shall send notification with JSON object containing one of the following error code:

Error CodeError Description
5089Storage Access denied
5090Failed to save file
1183Failed to download file
1181File Download not available in this context

Cancel Downloading a File

The receiver of a file may like to cancel an ongoing download of a file by using window.EnxRtc.cancelDownload() method.

Method: cancelDownload (jobId)

Parameters: @param {Number} jobId – Job ID which is to be canceled.

Event Listeners: onFileDownloadCancelled – Notifies when the file download is canceled.

// To cancel single downloading file
window.EnxRtc.cancelDownload(jobId);

// Add Event Listeners
// To intended receiver – File downloading is cancelled.
window.EnxRtc.addEventListner("onFileDownloadCancelled", function
(data)
{
console.log(JSON.stringify(data.data));
});

Cancel Downloading of all Files

The receiver of files may like to cancel the ongoing download of all files by using window.EnxRtc.cancelAllDownloads() method.

Method: cancelAllDownloads()

Event Listeners: onFileDownloadCancelled – Notifies when the file download is canceled.

// To cancel all downloading file
window.EnxRtc.cancelAllDownloads();

// Add Event Listeners
// To intended receiver – File downloading is cancelled.
window.EnxRtc.addEventListner("onFileDownloadCancelled", function
(data)
{
console.log(JSON.stringify(data.data));
});