Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keeping socket while app pauses and resumes #33

Open
s1na opened this issue Dec 14, 2013 · 3 comments
Open

Keeping socket while app pauses and resumes #33

s1na opened this issue Dec 14, 2013 · 3 comments

Comments

@s1na
Copy link

s1na commented Dec 14, 2013

I'm using socket.io, when the user closes the application(pause) and then resumes, the old socket is replaced with a new one, and another socket is created also.

Is there some way I could keep the socket in the background?
Or even destroy it before pause?

@mkuklis
Copy link
Owner

mkuklis commented Dec 14, 2013

You could use http://docs.phonegap.com/en/3.2.0/cordova_events_events.md.html#pause to detect when the app is pausing and disconnect then.

@s1na
Copy link
Author

s1na commented Dec 15, 2013

Tried that but failed.
The actual websockets are created in the java plugin, right? That's why when app goes to pause they're still alive. If I were to change the plugin and provide an api for getting the active socket, that'd do it?

@mkuklis
Copy link
Owner

mkuklis commented Dec 15, 2013

By default when your app goes to pause the socket will stay open (it should not be closed if it is then there is something wrong going on with the plugin). Have you tried to bind to pause event and close your socket from socket.io:

document.addEventListener("pause", function () {
  socket.disconnect(); // disconnect comes from socket.io api
}, false);

This should propagate to Java side and close the socket connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants