Skip to content

Instantly share code, notes, and snippets.

@PrimeTimeTran
Last active January 9, 2018 20:47
Show Gist options
  • Save PrimeTimeTran/6aa50585c09f9df7f7676b36e193299f to your computer and use it in GitHub Desktop.
Save PrimeTimeTran/6aa50585c09f9df7f7676b36e193299f to your computer and use it in GitHub Desktop.
// PURPOSE:
// to prevent green dot from going grey on simple user navigations to different parts of the app
// PROBLEM:
// if the user 'x's the tab of their browser, this ActionCable method never runs, thus the user is always online
disconnected: function() {
setTimeout(function () {
if (!App.cable) {
this.perform("disappear");
}
}, 5000);
},
// PURPOSE:
// to fire `this.perform('disappear') if the user closes the tab or navigates to a different domain
// PROBLEM:
// if the user navigates to a different page this is also fired... thus, defeats the purpose of `setTimeout()` on line 7
window.onbeforeunload = function () {
this.perform("disappear");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment