Skip to content

Instantly share code, notes, and snippets.

@akmandev
Created March 27, 2017 06:43
Show Gist options
  • Save akmandev/967f9bfa017421245e1d0c5c1297893e to your computer and use it in GitHub Desktop.
Save akmandev/967f9bfa017421245e1d0c5c1297893e to your computer and use it in GitHub Desktop.
Pusher - Avoiding instant disconnects while navigating/refreshing page
function removeMember(member) {
pendingRemoves[ member.id ] = setTimeout(function() {
removeMemberFromUI(member);
}, 3000); // wait 3 seconds
};
function addMember(member) {
var pendingRemoveTimeout = pendingRemoves[member.id];
if(pendingRemoveTimeout) {
// user left, but has rejoined
clearTimeout(pendingRemoveTimeout);
}else{
// Do normal user add action
}
// Source: https://support.pusher.com/hc/en-us/articles/202054403-How-can-I-stop-users-going-offline-for-an-instant-when-they-navigate-between-pages-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment