INFO! Android Toolkit 1.4.2 support an advance version of Public & Private Messaging API. Therefore, you are discouraged to use this Stream based Messaging. It will be deprecated in future version.
You may implement basic text-chat communication using Video API. The Text-Data is carried on a separate data track in a published Stream and received by all subscribers of the stream.
- Notes to send message:
- You must initiate your stream with data track enabled using the JSON Payload as
{data: true}
- You must publish your stream into the room before you can use the
Enx.sendData()
method.
- You must initiate your stream with data track enabled using the JSON Payload as
- Notes to receive message:
- You must subscribe to the remote stream
- User Observer
receiveData
to receive any incoming message.
Method: Enx.sendData(localStreamId, messageObject)
Parameter:
localStreamId
– Local Stream ID on which the message to be sentmessageObject
– This object has following keys:from
: Sender Namemessage
: Message Bodytimestamp
: Time Stamp in UTC – when the message was originated
Callback: receiveData
– To all participants in the room with messageObject
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" } } */ }