In spite of you do not have direct access to the source code and to work around the problem of cross-origin we used a framework called easyXDM for sharing javascript events between your site and our servers through socket messages exchange. So you have the possibility to capture some MQTT chat events in your JavaScript code.
Below list of events that you can use : data of each event are encapsulated in mqttchat_data
variable.
Name | Description |
mqttchat-load-complete | Event fires when chat iframe is completely loaded. |
mqttchat-incoming-message | Event fires when currently user receives a message from another user. |
mqttchat-not-read-messages-count-update | Event fires when the number of unread messages changes. |
mqttchat-error | Event fire when an error has occurred |
mqttchat-load-complete
telifounJQ(document).ready(function() {telifounJQ(document).on("mqttchat-load-complete",function(e){console.log("chat load is complete");})});
No data returned.
mqttchat-incoming-message
telifounJQ(document).ready(function() {telifounJQ(document).on("mqttchat-incoming-message",function(e){console.log(e.mqttchat_data);});});
mqttchat_data
contains the userid
of user who sent the message and the the received message
.
{fromUserid: "1",message: {"cid":"85", //channel id"id":138729, //message id"m":"hi", //message content"p1":"undefined", // parameter 1"p2":"undefined", // parameter 2"p3":"undefined", // parameter 3"t":1601749085, //message timestamp"type":0}//message type}
mqttchat-not-read-messages-count-update
telifounJQ(document).ready(function() {telifounJQ(document).on("mqttchat-not-read-messages-count-update",function(e){console.log(e.mqttchat_data);});});
mqttchat_data
contains the number of unread message .
{n: 1}
mqttchat-error
telifounJQ(document).on("mqttchat-error",function(e){console.log(e.mqttchat_data);});​
mqttchat_data
contains error message.
{error: "A name at least is required to add user!"}
If you want to start conversation with a specific user automatically just after chat load you can use __initChatWithUser()
function like this:
telifounJQ(document).ready(function() {telifounJQ(document).on("mqttchat-load-complete",function(e){telifounJQ.MQTTchat_Cloud.__initChatWithUser(122);});});