In-Session Communication
The React Native SDK provides the following methods for obtaining information about the in-session communication:
- sendData(): To send or receive messages.
- sendMessage(): To send private, public, or group messages.
- sendUserData(): To send a message to all or selected participants in a room.
- sendFiles(): To initiate a file transfer to the EnableX server.
- getAvailableFiles(): To return a JSON object with the details of all the files available for download.
- downloadFile(): To initiate a file download.
- cancelUpload(): To cancel an ongoing file upload job.
- cancelAllUploads(): To cancel all ongoing file uploads.
- cancelDownload(): To cancel an ongoing file download job.
- cancelAllDownloads(): To cancel all ongoing file downloads.
- startAnnotation(): To start annotations on a specific stream object.
- stopAnnotation(): To stop annotations.
Send Chat Data
Note: EnableX Android Toolkit 1.4.2 supports an advanced version of Public & Private Messaging API. Therefore, you are discouraged from using this stream based messaging. It will be deprecated in a future version.
You can implement a basic text-chat communication using the EnableX API. The text data is carried on a separate data track in a published stream and is received by all the subscribers.
-
To send a message, you must initiate your stream with data tracking enabled using the JSON payload as
{data: true}
;. The stream must be published into the room before theEnx.sendData()
method is used. -
To receive a message, you must subscribe to the remote stream from where you will receive the message. The
receiveData
User Observer will send the incoming messages.
Method: Enx.sendData(localStreamId, messageObject)
Parameters | Data Type | Description |
---|---|---|
localStreamId |
String | The Local Stream ID on which the message is to be sent |
messageObject |
String | messageObject.from : Sender Name messageObject.message : Message Body messageObject.timestamp : Time stamp in UTC when the message was originated. |
Callback: receiveData
: JSON Object. To all participants in the room with messageObject
.
Sample Code
messageJSON: {message: "Test chat",from: "React-Native",timestamp: Date.now()}Enx.sendData(localStreamId, messageJSON); // Send message// Participants receive messagereceiveData : event=>{/* event ={ id : 12345,msg : {from: "", message: "",timestamp: 12345, type: "public"}} */}
Messaging
Chat is an advanced feature that enables session participants to communciate with each other. Participants can use the following types of messaging:
- Public Messaging: To send messages to all the connected participants.
- Private Messaging: To send messages to a specific participant.
- Group Messaging: To send messages to more than one specified participant.
The Messaging feature does not need senders or publishers to publish their streams.
Method: Enx.sendMessage(message, isBroadcast, clientIds)
Parameters
Parameter | Data Type | Description |
---|---|---|
message | String | Need to type the message |
IsBroadcast | Boolean | Set it to true for public broadcast. Set it to false to send a private message to one or more participants. |
clientIDs | Array | List of ClientIDs to whom a participant needs to send a private message. |
Callbacks
Callback | Data Type | Description |
---|---|---|
receiveChatDataAtRoom | JSON Object | Receives the message in a JSON object. |
acknowledgeSendData | JSON Object | Sender of the message is acknowledged. |
Sample Code
Enx.sendMessage(message, true, null); // Public MessagingEnx.sendMessage(message, false, [ClientID]); // Private/Group Messaging// Users Receive Message through CallbackreceiveChatDataAtRoom: event => {// event =// { "source_id":"XXX", "type":"chat", "msg":"hello"}}// Sender is acknowledgedacknowledgeSendData: event => {}
Custom Signalling
Your application might require you to send instructions and data to one or more recipients connected in a session to deploy new features and business workflow. For example, create a polling mechanism among participants. EnableX supports the Custom Signalling method through which you can build a utility that supports passing messages among participants.
Using the Custom Signaling method, you can send a message to all or selected participants in a room. You can define your custom data structure to pass to meet your business requirement.
Method: Enx.sendUserData(message, isBroadcast, clientIds)
Parameters
Parameter | Data Type | Description |
---|---|---|
message | String | Need to enter the message. |
IsBroadcast | Boolean | Set it to true for public broadcast. Set it to false to send a private message to one or more participants. |
clientIDs | Array | List of ClientIDs to whom the participant needs to send a private message. |
Callbacks
Callback | Data Type | Description |
---|---|---|
receiveChatDataAtRoom | JSON Object | Receives the message in a JSON object. |
acknowledgeSendData | JSON Object | The sender of the message is acknowledged. |
Sample Code
Enx.sendUserData(message, true, null); // Send to allEnx.sendUserData(message, false, [ClientID]); // Send to few clients// Users Receive through CallbackreceiveChatDataAtRoom: event => {// event =// { "source_id":"XXX", "type":"chat", "msg":"hello"}}// Sender is acknowledgedacknowledgeSendData: event => {}
File Sharing
The following APIs allow users in an RTC session to send and receive files with each other. Using these APIs, you can initiate a file transfer, cancel a file transfer, be notified when a file is available for download, and receive/download a shared file.
Uploading a File for Sharing
The Enx.sendFiles()
method initiates a file transfer to the EnableX server.
Method: Enx.sendFiles(isBroadcast,clientIdList)
Parameters
Parameter | Data Type | Description |
---|---|---|
isBroadcast | Boolean | Set it to true to share a file with all the participants in a session. Set it to false to share a file with the intended participant. |
clientIdList | Array | List of Client IDs intended to receive the file. This parameter is not applicable if the isBroadcast parameter is set to true. |
Callbacks
Callback | Data Type | Description |
---|---|---|
initFileUpload | JSON Object | When the file upload process initiates, the sender receives a notification. |
fileUploaded | JSON Object | When the file upload process finishes, the sender receives a notification. |
fileUploadFailed | JSON Object | When the file is ready to download, the intended receiver receives a notification. |
Sample Code
Enx.sendFiles(isBroadcast,clientIdList)initFileUpload:event=>{// To sender - File upload process started}fileUploaded:event=>{// To sender - File upload is complete}fileUploadFailed:event=>{// To sender - File upload has failed}fileUploadStarted:event=>{// To intended receiver - A new file upload started}fileAvailable:event=>{// To intended receiver - A file is available for download}
Downloading a Shared File
Use the followng steps to download a shared file:
Know Files Available for Download
The Enx.getAvailableFiles()
method returns a JSON Object with all the files available for download.
Method: Enx.getAvailableFiles()
Callback: fileAvailable
: The intended receiver is notified when a file is available for download.
Sample Code
Enx.getAvailableFiles()fileAvailable:event=>{// To intended receiver - A file is available for download}
Initiating a File Download
The Enx.downloadFile()
method initiates the file download using the information received about the file.
Method: Enx.downloadFile(fileInfo,isAutoSave)
Parameters
Parameter | Data Type | Description |
---|---|---|
fileInfo | JSON Object | The file that is available for download. |
isAutoSave | Boolean | Set it to true to save the file automatically, in which case you receive the path where the file is saved. Set it to false to receive Base64 encoded RAW data to handle the file saving process manually. |
Callbacks
Callback | Data Type | Description |
---|---|---|
fileDownloaded | JSON Object | Notification sent when the file has been downloaded with or without automatically saving it. |
fileDownloadFailed | JSON Object | Notification sent when the file download fails. |
Sample Code
Enx.downloadFile(fileInfo,isAutoSave)fileDownloaded:event=>{// To receiver - File has been downloaded}fileDownloadFailed:event=>{// To receiver - File download has failed}
Canceling a File Upload
The Enx.cancelUpload()
method allows you to cancel an ongoing file upload job initiated by you.
Method: Enx.cancelUpload(upJobId)
Parameter: upJobId
: Numeric. The ID of the file upload job.
Callback: fileUploadCancelled
: JSON Object. Acknowledgment to the participant when the file upload is canceled.
Sample Code
Enx.cancelUpload(upJobId)fileUploadCancelled:event=>{// Acknowledgment to the participant when the file upload is cancelled.}
Canceling all File Uploads
The Enx.cancelAllUploads()
method allows you to cancel all the ongoing file uploads initiated by you.
Method: Enx.cancelAllUploads()
Callback: fileUploadCancelled
: Acknowledgment to the participant when the file upload is canceled.
Sample Code
Enx.cancelAllUploads()fileUploadCancelled:event=>{// Acknowledgment to the user when the file upload is cancelled.}
Error Codes and Exceptions
Code | Decription |
---|---|
5089 | Storage access is denied. |
5090 | Failed to save the file. |
5091 | File sharing is not available in this context. |
5092 | Too many files to upload. A maximum of one file is allowed per request. |
1185 | The file size exceeds the maximum allowed size. |
1182 | Failed to upload the file. |
5098 | Unable to cancel file upload after the file upload is complete. |
5099 | Failed to cancel file upload as an invalid Upload ID is passed as a parameter. |
5100 | Failed to upload a possibly corrupt file. |
5102 | Canceling an upload option is not available without Web View. Non-contextual method call. |
Canceling a File Download
The Enx.cancelDownload()
allows you to cancel an ongoing file download job running at your endpoint.
Method: Enx.cancelDownload(JobId)
Parameter: JobId
: Numeric. The ID of the file download job.
Callback: fileDownloadCancelled
: JSON Object. Acknowledgment to the participant when the file download is canceled.
Sample Code
Enx.cancelDownload(JobId)fileDownloadCancelled:event=>{// Acknowledgment to the user when the file download is canceled.}
Canceling All File Downloads
The Enx.cancelAllDownloads()
method allows you to cancel all the ongoing file downloads at your endpoint.
Method: Enx.cancelAllDownloads()
Callback: fileDownloadCancelled
: Acknowledgment to the user when the file download is canceled.
Sample Code
Enx.cancelAllDownloads()fileDownloadCancelled:event=>{// Acknowledgment to the user when the file download is cancelled.}
Error Codes and Exceptions
Code | Description |
---|---|
5089 | Storage access is denied. |
5090 | Failed to save the file. |
1183 | Failed to download the file. |
1181 | File download is not available. Non-contextual method call. |
5101 | The file is already downloaded. |
Screen Sharing
When a user starts or stops screen sharing, all the connected users of the room are notified with screenShareStarted
and screenShareStopped
callbacks. As screen sharing is also a stream, you can play it using a video player.
Note: Screen sharing is carried on Stream ID# 101. Client endpoints must subscribe to this Stream ID to receive and play the stream locally.
Callbacks
Callback | Description |
---|---|
screenShareStarted | To know that screen sharing has started. |
screenShareStopped | To know that screen sharing has stopped. |
Sample Code
// You are notified that Screen Share has startedscreenShareStarted : event=>{/* event ={ clientId : "xxx", name : "XXX",result : 0, streamId : 101}*/// Handle UI to play Screen Share}// You are notified that Screen Share has stoppedscreenShareStopped: event=>{/* event ={ clientId : "xxx", name : "XXX",result : 0, streamId : 101}*/// Handle UI to stop playing Screen Share}
Canvas Streaming
A client endpoint application developed using the Android toolkit cannot initiate HTML5-based canvas streaming. However, it can receive canvas streaming initiated by other client endpoint applications developed using Web toolkit that runs on web browsers. When a user starts or stops HTML5-based canvas streaming, all the connected users of the room are notified with canvasStarted
and canvasStopped
. As canvas streaming is a stream, you can play it using a video player.
Note: Canvas streaming is carried on Stream ID# 102. Client endpoints must subscribe to this Stream ID to receive and play the stream locally.
Observers
Observer | Description |
---|---|
canvasStarted | To know that canvas streaming has started. |
canvasStopped | To know that canvas streaming has stopped. |
Sample Code
// You are notified that Canvas Streaming has startedcanvasStarted : event=>{/* event ={ clientId : "xxx", name : "XXX",result : 0, streamId : 102}*/// Handle UI to play Canvas Streaming}// You are notified that Canvas Streaming has stoppedcanvasStopped: event=>{/* event ={ clientId : "xxx", name : "XXX",result : 0, streamId : 102}*/// Handle UI to stop playing Canvas Streaming}
Annotation
The Annotation feature allows you to annotate on a remote stream. To support annotations, enable canvas streaming during Room Creation by setting: { canvas: true; }
in the JSON payload. Before starting annotations, add the Annotation toolbar.
Add Annotation Toolbar
Start Annotation
The Enx.startAnnotation()
method is used to start annotation on a specific stream object.
Method: Enx.startAnnotation(streamId)
Parameter: streamId
: String. Stream ID of the stream object to annotate.
Callbacks
Callback | Description |
---|---|
startAnnotationAck | JSON Object |
annotationStarted | JSON Object |
Stop Annotation
The Enx.stopAnnotation()
method is used to stop Annotations.
Method: Enx.stopAnnotation()
Callbacks
Callback | Description |
---|---|
stoppedAnnotationAck | JSON Object |
annotationStopped | JSON Object |
Sample Code
Enx.startAnnotation(streamId); // Start AnnotationEnx.stopAnnotation(); // Stop AnnotationstartAnnotationAck:event=>{// Acknowlegement to Annotator - Annotation started}annotationStarted:event=>{// Notification to all - Annotation started}stoppedAnnotationAck:event=>{// Acknowlegement to Annotator - Annotation stopped}annotationStopped:event=>{// Notification to all - Annotation stopped}
Error codes and Exceptions
Code | Description |
---|---|
5093 | Annotation access is denied. |
5106 | Repeated startAnnotation() call is made when a previous request is in process. |
5108 | An invalid stream is passed to startAnnotation(). |
5109 | Failed to publish the annotation stream. |
5112 | Annotation support is available in Landscape mode only. |
5094 | Repeated stopAnnotation() call is made when a previous request is in process. |