I'm working on an app using MQTT protocol & react native, I faced one problem which is when I run my app after a few minutes later it connect & disconnect several time after it closed can someone help me to solve this issue please.
Here is the log :
useEffect(() => {
client.onConnect = onConnect;
client.onConnectionLost = onConnectionLost;
client.onPress = onPress;
client.connect({
onSuccess : onConnect,
userName: process.REACT_APP_DB_NAME,
password: process.REACT_APP_PASSWORD,
onFailure : onConnectionLost,
});
if (isMounted.current) {
fetchData();
}
return () => {
isMounted.current = false;
}
}, [client])
const onConnect = () => {
console.log("Connected!!!!home screen");
setIsConnected(true);
};
const onConnectionLost = (responseObject)=> {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost : "+responseObject.errorMessage);
setIsConnected(false);
}
}