zhukov / webogram

Telegram web application, GPL v3
https://web.telegram.org
GNU General Public License v3.0
7.94k stars 2.36k forks source link

[mobile] Suspend service worker client ping when idle #1602

Open TitanNano opened 6 years ago

TitanNano commented 6 years ago

When the app is idle on mobile, the long-poll is put to sleep. At the same time though the ping from an open client to the service worker keeps going. This creates a situation in which the service worker ignores pushes because it thinks there is an active client, and the client is disconnected because it stopped long polling.

It would be best to also suspend the ping to the service worker when the app is idle. This way the open client is ignored until it's used again. This would help keeping battery usage down.

TitanNano commented 6 years ago

@zhukov from /app/js/lib/push_worker.js#L22-L34 it apears that lastAliveTime is not used anymore. Therefor I suggest to remove it and the client to service-worker ping completely.

To resolve the initial issue it would be in this case best to notify the active client about the push and reactivate the long-poll. /app/js/lib/mtproto.js#L730-L736 already exists but is never used.

azzimuth commented 6 years ago

Is this the reason for the notification popups to appear even if I close the tab with Webogram?

zhukov commented 6 years ago

@TitanNano indeed. thanks for the research.

zhukov commented 6 years ago

@azzimuth hmm.. is wording correct? notification popups appear when tab is closed due to Push API support.

azzimuth commented 6 years ago

@zhukov I was just guessing.