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

Class: EnxRoom

Method: EnxRoom.sendUserData(MessageOpt, IsBroadcast, RecipientIDs, Callback)

Parameters:

  • MessageOpt – JSON Object containing custom keys. This object is passed to the Recipients without any structure enforcement. Be advised to define keys effectively for signaling needs.
  • IsBroadcastBoolean. Set to true for Public Broadcast and false for signaling to one or more recipients.
  • RecipientIDs – Array of Client IDs of recipients of the message when not broadcasting.

Notification Event:

user-data-received – Receives signaling in MessageOpt JSONObject as event.message.msg.

MessageOpt Sample JSON:

// Example: Important Information you can put with custom keys

var MessageOpt = {
    "broadcast": false,                // Flag for Private message
    "sender": "Sender's Name",
    "senderId": "Sender's Client ID",  // room.clientId 
    "message": "Message body",
    "timestamp": "Date Timestamp",     // Message sent at
}

To send & receive Custom Signaling

// To send custom data / signal to all (Public Messaging)
room.sendUserData(MessageOpt, true, [], function(data){
    // Message sent
});

// To send custom data / signal to selected Participant (Private Messaging)
room.sendUserData(MessageOpt, false, [Recipient_ClientIds], function(data){
    // Message sent
});

// To receive  custom data / signal notification 
room.addEventListener("user-data-received", function (event) {
     var InMsg = event.message.msg;
     if (InMsg.broadcast === true) {
         // Handle Public Message
     }
     else {
         // Handle Message from InMsg.sender
     }
 });