How can I stop users going offline for an instant when they navigate between pages?

When a user leaves the room you could start a timeout to remove the user. If the user then rejoins the room you could clear that timeout so the removal never actually occurs.

Code below for example purposes only:

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);
  }
}
Was this article helpful?
0 out of 0 found this helpful
Haven't found what you were looking for?
Submit a ticket