Search code examples
mqttprogressive-web-appsmobile-website

MQTT JS don't connect when mobile browser is not active


I am using mqtt and websocket for maintain a realtime comunication with a server, but i am noticed that my client, mqtt.js, don't works when my browser is minimized or tab is not active in my mobile device, any help?????


Solution

  • That's just the way mobile browsers work, they will suspend anything in the background to save battery.

    I suggest you look at something like the page lifecycle events covered in this document from Chrome to see how to handle getting notified when the page is suspended and when it gets focus back and is resumed.