Skip to content

Instantly share code, notes, and snippets.

@aslamanver
Last active July 5, 2020 14:08
Show Gist options
  • Save aslamanver/44a250f0c361331c6a33ba319e8ca782 to your computer and use it in GitHub Desktop.
Save aslamanver/44a250f0c361331c6a33ba319e8ca782 to your computer and use it in GitHub Desktop.
Pseudocode | Socket.IO Session Handler for Node.js

Pseudocode

When the user connects the first time;

  1. Token-1 | Trying to connect the server;
  2. If Token-1 is not already connected | Token is not found in users[] array list;
  3. Create a user object with token and connection id and push to users[] array list;
  4. Complete the flow.

When the user connects again while another session is alive;

  1. Token-1 | Trying to connect the server;
  2. If Token-1 is already connected | Token is found in users[] array list;
  3. Push the connection ID to the existing user object from users[] array list;
  4. Complete the flow.

When the user disconnects;

  1. Wait a few seconds for any responses from the dropped client;
  2. If the client is not responding, remove the dropped connection ID from the user object;
  3. If the user's all the browser sessions (connection IDs) are disconnected and no any connections from the connection array on user object the user object should be removed from the users[] array list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment