I am using Eclipse Paho - Mqtt javascript library.
Trying to access onMessageArrived
from outside function:
mqttConnect(){
var client = new Paho.MQTT.Client("wss://test.mqtt.address", "myClientId");
this.connectionInfo = client;
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
client.connect({onSuccess:onConnect});
function onConnect() {
client.subscribe("some/path/to/subscribe/");
}
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost:"+responseObject.errorMessage);
}
}
function onMessageArrived(message) {
console.log("onMessageArrived: "+message.payloadString);
return message.payloadString; //this does not work of course.
}
}
Trying to access messages from outside like:
_constract(){
var message = mqttConnect();
console.log(message);
}
Maybe register some global variable and put it there like this.global = message.payloadString
?