In-Session Communication

The React Native SDK provides the following methods for obtaining information about the in-session communication:

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 the Enx.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 message
receiveData : 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

ParameterData TypeDescription
messageStringNeed to type the message
IsBroadcastBooleanSet it to true for public broadcast.
Set it to false to send a private message to one or more participants.
clientIDsArrayList of ClientIDs to whom a participant needs to send a private message.

Callbacks

CallbackData TypeDescription
receiveChatDataAtRoomJSON ObjectReceives the message in a JSON object.
acknowledgeSendDataJSON ObjectSender of the message is acknowledged.

Sample Code

Enx.sendMessage(message, true, null); // Public Messaging
Enx.sendMessage(message, false, [ClientID]); // Private/Group Messaging
// Users Receive Message through Callback
receiveChatDataAtRoom: event => {
// event =
// { "source_id":"XXX", "type":"chat", "msg":"hello"}
}
// Sender is acknowledged
acknowledgeSendData: 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

ParameterData TypeDescription
messageStringNeed to enter the message.
IsBroadcastBooleanSet it to true for public broadcast.
Set it to false to send a private message to one or more participants.
clientIDsArrayList of ClientIDs to whom the participant needs to send a private message.

Callbacks

CallbackData TypeDescription
receiveChatDataAtRoomJSON ObjectReceives the message in a JSON object.
acknowledgeSendDataJSON ObjectThe sender of the message is acknowledged.

Sample Code

Enx.sendUserData(message, true, null); // Send to all
Enx.sendUserData(message, false, [ClientID]); // Send to few clients
// Users Receive through Callback
receiveChatDataAtRoom: event => {
// event =
// { "source_id":"XXX", "type":"chat", "msg":"hello"}
}
// Sender is acknowledged
acknowledgeSendData: 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

ParameterData TypeDescription
isBroadcastBooleanSet 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.
clientIdListArrayList of Client IDs intended to receive the file.
This parameter is not applicable if the isBroadcast parameter is set to true.

Callbacks

CallbackData TypeDescription
initFileUploadJSON ObjectWhen the file upload process initiates, the sender receives a notification.
fileUploadedJSON ObjectWhen the file upload process finishes, the sender receives a notification.
fileUploadFailedJSON ObjectWhen 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

ParameterData TypeDescription
fileInfoJSON ObjectThe file that is available for download.
isAutoSaveBooleanSet 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

CallbackData TypeDescription
fileDownloadedJSON ObjectNotification sent when the file has been downloaded with or without automatically saving it.
fileDownloadFailedJSON ObjectNotification 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

CodeDecription
5089Storage access is denied.
5090Failed to save the file.
5091File sharing is not available in this context.
5092Too many files to upload. A maximum of one file is allowed per request.
1185The file size exceeds the maximum allowed size.
1182Failed to upload the file.
5098Unable to cancel file upload after the file upload is complete.
5099Failed to cancel file upload as an invalid Upload ID is passed as a parameter.
5100Failed to upload a possibly corrupt file.
5102Canceling 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

CodeDescription
5089Storage access is denied.
5090Failed to save the file.
1183Failed to download the file.
1181File download is not available. Non-contextual method call.
5101The 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

CallbackDescription
screenShareStartedTo know that screen sharing has started.
screenShareStoppedTo know that screen sharing has stopped.

Sample Code

// You are notified that Screen Share has started
screenShareStarted : event=>{
/* event =
{ clientId : "xxx", name : "XXX",
result : 0, streamId : 101
}
*/
// Handle UI to play Screen Share
}
// You are notified that Screen Share has stopped
screenShareStopped: 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

ObserverDescription
canvasStartedTo know that canvas streaming has started.
canvasStoppedTo know that canvas streaming has stopped.

Sample Code

// You are notified that Canvas Streaming has started
canvasStarted : event=>{
/* event =
{ clientId : "xxx", name : "XXX",
result : 0, streamId : 102
}
*/
// Handle UI to play Canvas Streaming
}
// You are notified that Canvas Streaming has stopped
canvasStopped: 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

CallbackDescription
startAnnotationAckJSON Object
annotationStartedJSON Object

Stop Annotation

The Enx.stopAnnotation() method is used to stop Annotations.

Method: Enx.stopAnnotation()

Callbacks

CallbackDescription
stoppedAnnotationAckJSON Object
annotationStoppedJSON Object

Sample Code

Enx.startAnnotation(streamId); // Start Annotation
Enx.stopAnnotation(); // Stop Annotation
startAnnotationAck: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

CodeDescription
5093Annotation access is denied.
5106Repeated startAnnotation() call is made when a previous request is in process.
5108An invalid stream is passed to startAnnotation().
5109Failed to publish the annotation stream.
5112Annotation support is available in Landscape mode only.
5094Repeated stopAnnotation() call is made when a previous request is in process.