In-Session Communication
The Flutter SDK provides the following methods:
- sendMessage(): To enable session participants to exchange messages.
- sendFile(): To initiate a file transfer to the EnableX server.
- cancelUpload(): To cancel an ongoing file upload job.
- cancelAllUploads(): To cancel all ongoing file upload jobs.
- getAvailableFiles(): To get all files that are available for download.
- downloadFile(): To initiate the file downloading process individually.
- cancelDownload(): To cancel the ongoing file download job.
- cancelAllDownloads(): To cancel all the ongoing file download jobs.
- startScreenShare(): To create a screen sharing stream @ 6fps to publish in a room.
- stopScreenShare(): To stop the ongoing screen-sharing.
- sendUserData(): To send customized data adhering to a structure which is not bound by the EnableX message structure.
- startAnnotation(): To start annotation on a given stream object.
- stopAnnotation(): To stop annotation.
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
Parameter | Data Type | Description |
---|---|---|
message | String | Text message to be sent. |
isBroadcast | Boolean | Set it to true for public broadcast. Set it to false for private messaging to one or more recipients. |
clientIds | Array | List of Client IDs to receive messages applicable for group and private messaging. |
onAcknowledgeSendData | String | Notification to everyone when the message is successfully sent to another user or group of users. |
onMessageReceived | String | Notification at the receivers end that a new message has arrived. |
Sample Code
EnxRtc.sendMessage("message",true,[]); // Send Message to allEnxRtc.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
Parameter | Data Type | Description |
---|---|---|
isBroadcast | Boolean | Set 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. |
recipientIDs | String | List of ClientIDs. This is to share the file among specified clients only. If broadcast is set to true, recipientIDs is ignored. |
onInitFileUpload | String | Notification to the sender that the file upload process has been initiated. |
OnFileUploaded | String | Notification to the sender that the file has been uploaded. |
OnFileUploadFailed | String | Notification to the sender that the file upload process has failed. |
OnFileUploadStarted | String | Notification to the intended receiver that a file is being uploaded. |
OnFileAvailable | String | Notification to the intended receiver that a file is ready to download. |
Sample Code
EnxRtc.sendFile(true,[]); // Send FilesEnxRtc.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 Code | Description |
---|---|
5089 | Storage Access denied |
5091 | File-Sharing is not available in this context |
1185 | The file is too large. The maximum allowed size is NNNN. |
1182 | Failed 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
Parameter | Data Type | Description |
---|---|---|
jobId | String | The ID of the job to be canceled. |
onFileUploadCancelled | String | Notification when the file upload has been canceled successfully. |
Sample Code
EnxRtc.cancelFileUpload(jobId); // Cancel File uploadingEnxRtc.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
Parameter | Data Type | Description |
---|---|---|
jobId | String | The ID of the jobs to be canceled. |
onFileUploadCancelled | String | Notification when the file upload has been canceled successfully. |
Sample Code
EnxRtc.cancelAllUploads(); // Cancel Files uploadingEnxRtc.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
Parameter | Data Type | Description |
---|---|---|
fileInfo | String | Map of the file to download. |
autosave | Boolean | Whether 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. |
onFileDownloaded | String | Notification that the file is downloaded with either Base64 raw data to be saved (When auto-saving is false) or saved file path. |
OnFileDownloadFailed | String | Notification to the user that the downloading is failed. |
Sample Code
EnxRtc.downloadFile(fileInfo,true); // Download a FileEnxRtc.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 Code | Description |
---|---|
5089 | Storage access denied. |
5090 | Failed to save file. |
1183 | Failed to download file. |
1181 | File 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
Parameter | Data Type | Description |
---|---|---|
jobId | String | Job ID that is to be canceled. |
onFileDownloadCancelled | String | Notification to the user when the file download is canceled. |
Sample Code
EnxRtc.cancelFileDownload(jobId); // Cancel a download jobEnxRtc.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 jobEnxRtc.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
Callback | Description |
---|---|
onStartScreenShareACK | Acknowledgment to the publisher when screen sharing starts. |
onScreenSharedStarted | Notification 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
Code | Description |
---|---|
5107 | Repeated startScreenShare() call made while the previous request was in process. |
1170 | Screen 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
Callback | Description |
---|---|
onStoppedScreenShareACK | Acknowledgment to the publisher when screen sharing stops. |
onScreenSharedStopped | Notification 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 needsmap message = {"sender": "Sender's Name","message": "Message body","custom_key": "Data"}
Sample Code - To send & receive Custom Signaling
EnxRtc.sendUserData("message",true,[]); // Send Custom SignalingEnxRtc.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
Parameter | Data Type | Description |
---|---|---|
streamId | String | The Stream Id of the stream to be annotated. |
onStartAnnotationAck | String | Acknowledgment to the annotator when annotation starts. |
onAnnotationStarted | String | Notification to everyone in the room when annotation starts. |
Sample Code
EnxRtc.startAnnotation(streamId); // Start Annotation// Acknowlegement to Annotator - Annotation startedEnxRtc.onStartAnnotationAck=(Map<dynamic, dynamic> map) {};// Notification to all - Annotation startedEnxRtc.onAnnotationStarted=(Map<dynamic, dynamic> map) {};
Stop Annotation
The EnxRoom.stopAnnotation()
method is used to stop annotation.
Class: EnxRtc
Method: static Future<void> stopAnnotations()
Callbacks
Callback | Description |
---|---|
onStoppedAnnotationAck | Acknowledgment to the annotator when annotation stops. |
onAnnotationStopped | Notification to everyone in the room when annotation stops. |
Sample Code
EnxRtc.stopAnnotation(); // Stop Annotation// Notification to all - Annotation stoppedEnxRtc.onAnnotationStopped=(Map<dynamic, dynamic> map) {};// Acknowlegement to Annotator - Annotation stoppedEnxRtc.onStoppedAnnotationAck=(Map<dynamic, dynamic> map) {};
Error Codes and Exceptions
Error Code | Description |
---|---|
5093 | Annotation access denied |
5104 | Repeated startAnnotation() call made while annotations are already active in the room. |
5106 | Repeated startAnnotation() call made while a previous request is in process. |
5108 | Invalid stream passed to startAnnotation() . |
5109 | Failed to publish annotation stream. |
5112 | Annotation support available in landscape mode only. |
5094 | Repeated stopAnnotation() call made while a previous request is in process. |