Saving socket.io client on phonegap resume or disconnecting it on pause

◇◆丶佛笑我妖孽 提交于 2019-12-25 05:35:07

问题


I have a phonegap application which uses socket.io as means of communication. When application goes to pause the socket is kept alive in the background apparently, and on resume when the page loads it replaces the old socket with a new one, and creates a new socket. By each resume socket connections are one more.

Is there a way to keep the old socket connection when application resumes? Or to disconnect it when the application pauses? I'm using phonegap-websocket.


回答1:


I have a similar issue. I also have a websocket-connection, that ought to be brought down when the app is sent to the background and reopened once the app is brought to the foreground again.

According to documentation, I'd use the "pause" event to tear down the communication and then reopen the socket when the "resume" event is received. But this only works as long as "keepRunning" is set to true (see keepRunning set to false - what does it really do on Android?).



来源:https://stackoverflow.com/questions/20519427/saving-socket-io-client-on-phonegap-resume-or-disconnecting-it-on-pause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!