In-Session Communication

The Flutter SDK provides the following methods:

Chat

Messaging is an advanced feature between session participants. It allows to exchange the following types of messages among session participants:

  • Public Messaging: To send messages to all connected users.
  • Private Messaging: To send messages to a specific user.
  • Group Messaging: To send messages to more than one user.

The Messaging feature does not require the sender of a message to publish the local streams or the receiver of the message to subscribe to a remote stream.

Class: EnxRtc

Method: static Future<void> sendMessage(String message, bool isBroadCast, List<dynamic> recipientIDs)essage(String Message, boolean isBroadcast, array RecipientIDs)

Parameters

ParameterData TypeDescription
messageStringText message to be sent.
isBroadcastBooleanSet it to true for public broadcast.
Set it to false for private messaging to one or more recipients.
clientIdsArrayList of Client IDs to receive messages applicable for group and private messaging.
onAcknowledgeSendDataStringNotification to everyone when the message is successfully sent to another user or group of users.
onMessageReceivedStringNotification at the receivers end that a new message has arrived.

Sample Code

EnxRtc.sendMessage("message",true,[]); // Send Message to all
EnxRtc.onAcknowledgeSendData = (Map<dynamic,dynamic> map) {
// Message has been sent
};
EnxRtc.onMessageReceived = (Map<dynamic,dynamic> map) {
// New Message has been received
};

File Sharing

The following APIs allow users in an RTC session to send and receive files with each other. Users can also initiate a file transfer, cancel a file transfer, be notified of the availability of a file for download, and receive and download a shared file.

Uploading a File for Sharing

The sendFiles() method initiates a file transfer to the EnableX server.

Class: EnxRtc.sendFile()

Method: static Future<void> sendFiles(bool isBroadCast, List<dynamic> recipientIDs)

Parameters

ParameterData TypeDescription
isBroadcastBooleanSet it to true to share a file between all the participants in the session.
Set it to false to share a file to the specific user.
recipientIDsStringList of ClientIDs.
This is to share the file among specified clients only.
If broadcast is set to true, recipientIDs is ignored.
onInitFileUploadStringNotification to the sender that the file upload process has been initiated.
OnFileUploadedStringNotification to the sender that the file has been uploaded.
OnFileUploadFailedStringNotification to the sender that the file upload process has failed.
OnFileUploadStartedStringNotification to the intended receiver that a file is being uploaded.
OnFileAvailableStringNotification to the intended receiver that a file is ready to download.

Sample Code

EnxRtc.sendFile(true,[]); // Send Files
EnxRtc.onInitFileUpload = (Map<dynamic,dynamic> map) {
// File upload started
};
EnxRtc.onFileUploaded = (Map<dynamic,dynamic> map) {
// File is uploaded
};
EnxRtc.onFileUploadFailed = (Map<dynamic,dynamic> map) {
// File upload failed
};
EnxRtc.onFileUploadStarted = (Map<dynamic,dynamic> map) {
// File upload started... to recipient
};
EnxRtc.onFileAvailable = (Map<dynamic,dynamic> map) {
// Files available for download... to recipient
};

Note: The upload process may encounter an error. The table below consists of the following error codes:

Error CodeDescription
5089Storage Access denied
5091File-Sharing is not available in this context
1185The file is too large. The maximum allowed size is NNNN.
1182Failed to upload the file

Canceling a File Upload

The cancelUpload() method is used to cancel the file uploading process.

Class: EnxRtc

Method: static Future<void> cancelUpload(int jobId)

Parameters

ParameterData TypeDescription
jobIdStringThe ID of the job to be canceled.
onFileUploadCancelledStringNotification when the file upload has been canceled successfully.

Sample Code

EnxRtc.cancelFileUpload(jobId); // Cancel File uploading
EnxRtc.onFileUploadCancelled = (Map<dynamic,dynamic> map) {
// Upload has been cancelled
};

Canceling all File Uploads

The cancelAllUploads() method is used to cancel all the file uploading processes.

Class: EnxRtc

Method: static Future<void> cancelAllUploads()

Parameters

ParameterData TypeDescription
jobIdStringThe ID of the jobs to be canceled.
onFileUploadCancelledStringNotification when the file upload has been canceled successfully.

Sample Code

EnxRtc.cancelAllUploads(); // Cancel Files uploading
EnxRtc.onFileUploadCancelled = (Map<dynamic,dynamic> map) {
// Upload has been cancelled
};

Download a Shared File

The process of downloading a shared file comprises of two steps:

  • Know about the files available for download.
  • Initiate the download of the available files.

Locate the Files Available for Download

The EnxRoom.getAvailableFiles() method is used to get all files that are available for download. It returns an array of JSON objects carrying file information.

Class: EnxRoom

Method: static Future<List<dynamic> getAvailableFiles()

Sample Code

List<dynamic> list= EnxRtc.getAvailableFiles();

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

Initiating a File Download

The downloadFile() method initiates the file download when the information about the downloadable file is available.

Class: EnxRtc

Method: static Future<void> downloadFile(Map<String,dynamic> file, bool autoSave)

Parameters

ParameterData TypeDescription
fileInfoStringMap of the file to download.
autosaveBooleanWhether to save the file automatically
If the file is not saved automatically then the user receives Base64 encoded raw data to handle file saving processes manually.
If auto-saving is on then the user receives the saved file path.
onFileDownloadedStringNotification that the file is downloaded with either Base64 raw data to be saved (When auto-saving is false) or saved file path.
OnFileDownloadFailedStringNotification to the user that the downloading is failed.

Sample Code

EnxRtc.downloadFile(fileInfo,true); // Download a File
EnxRtc.onFileDownloaded = (Map<dynamic,dynamic> map) {
// File has been downloaded
};
EnxRtc.onFileDownloadFailed = (Map<dynamic,dynamic> map) {
// File Download has failed
};

Note: The upload process may encounter an error:

Error CodeDescription
5089Storage access denied.
5090Failed to save file.
1183Failed to download file.
1181File download not available in this context.

Canceling a File Download

The cancelFileDownload() method allows you to cancel an ongoing file download job running at your endpoint.

Class: EnxRtc

Method: static Future<void> cancelDownload(int jobId)

Parameters

ParameterData TypeDescription
jobIdStringJob ID that is to be canceled.
onFileDownloadCancelledStringNotification to the user when the file download is canceled.

Sample Code

EnxRtc.cancelFileDownload(jobId); // Cancel a download job
EnxRtc.onFileDownloadCancelled=(Map<dynamic,dynamic> map) {
// File download has been cancelled
};

Canceling Downloading of All Files

The cancelAllDownloads() method allows you to cancel all ongoing file download jobs running at your endpoint.

Class: EnxRtc

Method: static Future<void> cancelAllDownloads()

Event Listener: onFileDownloadCancelled: Notification to the user when the file downloading is canceled.

Sample Code

EnxRtc.cancelAllDownloads(); // Cancel download job
EnxRtc.onFileDownloadCancelled=(Map<dynamic,dynamic> map) {
// File download has been cancelled
};

Screen Sharing

To support screen sharing in a room, you need to enable screen sharing in the Room Creation by setting: { "screen_share": true; } in the JSON Payload. To receive shared screens, subscribe to the screen share Stream ID# 101 and play it on the video player.

Start Screen Sharing

The EnxRtc.startScreenShare() method creates a screen-sharing stream @ 6fps to publish in the room. Screen sharing continues even when the application is running in the background.

Class: EnxRtc

Method: static Future<void> startScreenShare();

Callbacks

CallbackDescription
onStartScreenShareACKAcknowledgment to the publisher when screen sharing starts.
onScreenSharedStartedNotification to everyone in a room when screen sharing starts.

Sample Code

EnxRtc.onStartScreenShareACK=(Map<dynamic, dynamic> map) {
// Publisher receives acknowledgement
};
EnxRtc.onScreenSharedStarted=(Map<dynamic, dynamic> map) {
// A new Screen Share Stream is available, receive Information
};

Error codes and exceptions

CodeDescription
5107Repeated startScreenShare() call made while the previous request was in process.
1170Screen sharing is not supported in your subscription.

Stop Screen Sharing

The EnxRtc.stopScreenShare() method stops the ongoing screen sharing.

Class: EnxRtc

Method: static Future<void> stopScreenShare();

Callbacks

CallbackDescription
onStoppedScreenShareACKAcknowledgment to the publisher when screen sharing stops.
onScreenSharedStoppedNotification to all the participants in the room that screen sharing has stopped.

Sample Code

EnxRtc.onStoppedScreenShareACK=(Map<dynamic, dynamic> map) {
// Publisher receives acknowledgement that Screen Share stopped.
};
EnxRtc.onScreenSharedStopped=(Map<dynamic, dynamic> map) {
// Screen Share has stopped. Receive Information
};

Custom Signaling

The EnxRtc.sendUserData() method allows you to send customized data adhering to a structure not bound by EnableX message structure to one or more users connected to a session. It allows your application to send not just messages but also structured instructions, polls, or any data requiring a customized data structure as per your business requirement.

Class: EnxRtc

Method: static Future<void> sendUserData(Map<String,dynamic> message, bool isBroadCast, List<dynamic> recipientIDs)

| Data Type | Description | | -------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | Map message | JSON Object | It is a map containing custom keys. EnableX passes this object to recipients without enforcing EnableX's structure. You should define the keys effectively for your signaling needs. | | isBroadcast | Boolean | Set it to true for public broadcast.
Set it to false for signaling to one or more recipients. | | clientIds | Array | List of Client IDs of recipients of the message when not broadcasting. | | onAcknowledgeSendData | String | Notification of a signaling message being sent to another user or group of users. | | onUserDataReceived | String | Receives signaling in a JSON object. |

Sample Code - Example of custom chat Map

// Example: Important Information you can put with custom keys
// You may define the Map as per your business needs
map message = {
"sender": "Sender's Name",
"message": "Message body",
"custom_key": "Data"
}

Sample Code - To send & receive Custom Signaling

EnxRtc.sendUserData("message",true,[]); // Send Custom Signaling
EnxRtc.onAcknowledgeSendData = (Map<dynamic,dynamic> map) {
// Signaling Message has been sent
};
EnxRtc.onUserDataReceived = (Map<dynamic,dynamic> map) {
// New Signaling Message is received
};

Annotation

The Annotation feature allows you to annotate on a remote stream. To support annotations, you need to enable canvas streaming during Room Creation by setting: { canvas: true; } in the JSON payload. To implement Annotation, you need to add the annotation toolbar before you can start annotations.

Add Annotation Toolbar

Initiate the annotation toolbar using the following code:

EnxToolbarWidget(width:100, height:50);

Start Annotation

The EnxRoom.startAnnotation() method is used to start annotation on a given stream object.

Note: To initiate annotation, you need to set setAnnotationObserver after connecting to a room.

Class: EnxRtc

Method: static Future<void> startAnnotation(String streamId)

Parameters

ParameterData TypeDescription
streamIdStringThe Stream Id of the stream to be annotated.
onStartAnnotationAckStringAcknowledgment to the annotator when annotation starts.
onAnnotationStartedStringNotification to everyone in the room when annotation starts.

Sample Code

EnxRtc.startAnnotation(streamId); // Start Annotation
// Acknowlegement to Annotator - Annotation started
EnxRtc.onStartAnnotationAck=(Map<dynamic, dynamic> map) {
};
// Notification to all - Annotation started
EnxRtc.onAnnotationStarted=(Map<dynamic, dynamic> map) {
};

Stop Annotation

The EnxRoom.stopAnnotation() method is used to stop annotation.

Class: EnxRtc

Method: static Future<void> stopAnnotations()

Callbacks

CallbackDescription
onStoppedAnnotationAckAcknowledgment to the annotator when annotation stops.
onAnnotationStoppedNotification to everyone in the room when annotation stops.

Sample Code

EnxRtc.stopAnnotation(); // Stop Annotation
// Notification to all - Annotation stopped
EnxRtc.onAnnotationStopped=(Map<dynamic, dynamic> map) {
};
// Acknowlegement to Annotator - Annotation stopped
EnxRtc.onStoppedAnnotationAck=(Map<dynamic, dynamic> map) {
};

Error Codes and Exceptions

Error CodeDescription
5093Annotation access denied
5104Repeated startAnnotation() call made while annotations are already active in the room.
5106Repeated startAnnotation() call made while a previous request is in process.
5108Invalid stream passed to startAnnotation().
5109Failed to publish annotation stream.
5112Annotation support available in landscape mode only.
5094Repeated stopAnnotation() call made while a previous request is in process.