eclipse / paho.mqtt.javascript

paho.mqtt.javascript
Other
1.14k stars 468 forks source link

Reconnect on mobile devices #199

Open apapacy opened 5 years ago

apapacy commented 5 years ago

I am using paho-mqtt with react-native on mobile devices. After the application enters the background state, the connection is broken. When the application resumes, the reconnect timeout is at a minimum value 1 seconds. But, missed messages begin to arrive after 60 second as keepAliveInterval default value.

Desired behavior. After determining that the application has left the background or sleep state, immediately connect to the server and receive all pending messages.

corey-mitchell commented 4 years ago

@apapacy Where did you land on this? I am not using react native, but I am using react and am having a similar issue where if the screen is locked from a mobile device, the client's connection is severed and takes a up to a full minute to reconnect. If this is actually tied to the keepAliveInterval, would setting that lower actually help with reconnect time?

Also, digressing a bit, I have noticed that the Python version has a method for customizing the reconnect delay yet I cannot seem to find anything similar in the docs for Javascript. It would be nice to have this feature for JS users as well.

apapacy commented 4 years ago

it depends on the value of the parameter keepAliveInterval and in my opinion controlled by server.

tuan511 commented 4 years ago

Excuse me @apapacy! How can u use paho-mqtt in react-native

marmundo commented 4 years ago

Excuse me @apapacy! How can u use paho-mqtt in react-native

I used this Tutorial

However I'm getting a problem when I'm releasing my apk (https://stackoverflow.com/questions/60895132/app-works-in-android-and-ios-simulator-but-not-after-release)