简体   繁体   中英

Websocket - Disconnection of the user Android/iOS during the app in background and during the eve

I have a Node.JS application that is a generalist chat, the application uses the websocket and I noticed that from time to time there are users who automatically disconnect from the websocket when the application is in the background , while they are on another application and it is the same thing when the Smartphone is in standby.

it apparently affects everyone who has Android and iOS.

Do you have an idea to solve the problems?

On Android you'll need to have a background service that keeps the websocket alive. When onPause is inoked it'll need to submit the service with the non-obviously named startForegroundService command, this tells Android not to kill it.

https://developer.android.com/reference/android/content/Context#startForegroundService(android.content.Intent)

On iOS I'm not so sure, but my guess is that it'll be less straigttforward.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM