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

iOS stops background JS = Meteor.disconnect() never called #15

Open
banjerluke opened this issue Jan 7, 2022 · 0 comments
Open

iOS stops background JS = Meteor.disconnect() never called #15

banjerluke opened this issue Jan 7, 2022 · 0 comments

Comments

@banjerluke
Copy link

Cordova iOS apps cannot execute JavaScript in the background (except in certain circumstances). JS execution is paused after about 3 seconds. You can verify this with the following code:

  document.addEventListener('pause', () => {
    console.log('pause handler');
    setTimeout(() => console.log('Still running!'), 1000);
    setTimeout(() => console.log('Still running!'), 2000);
    setTimeout(() => console.log('Still running!'), 3000);
    // the following line is not executed until the app is back in the foreground
    setTimeout(() => console.log('Still running after more than 3 seconds!'), 4000);
  });

With the default 60-second timeout, this package won't end up disconnecting before JS execution is paused.

For what it's worth, I'm trying the following simple approach (inspired by this package) to disconnect only in Cordova and Chrome (as discussed in #11):

  document.addEventListener('resume', () => {
    Meteor.reconnect();
  });
  document.addEventListener('pause', () => {
    Meteor.disconnect();
  });
  document.addEventListener('freeze', () => {   // for Chrome
    Meteor.disconnect();
  });
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

1 participant