Skip to content

[OA][Infrastructure] - Init WS Server#267

Merged
LOTaher merged 4 commits into
mainfrom
266/ws-server
Mar 30, 2026
Merged

[OA][Infrastructure] - Init WS Server#267
LOTaher merged 4 commits into
mainfrom
266/ws-server

Conversation

@LOTaher
Copy link
Copy Markdown
Collaborator

@LOTaher LOTaher commented Mar 30, 2026

[OA][Infrastructure] - Init WS Server

Changes

  • Scaffolded the server side of our web socket heartbeat.
  • Clients are authenticated using JWTs and use websockets' ping and pong commands for the heartbeat.
    • The metadata being stored in this JWT for now is just userId, isAlive and the _id from setInterval. We're going to also most likely want to add some more metadata here eventually such as a "timeout bank" to give each client a set number of seconds of being offline before their OA closes.
  • All connections are stored in a single map.

Notes

  • This implementation is in Javascript so there are some nicities being used here. An example being I can add whatever keys I want to an already existing socket object I get from the ws.on("connection") callback.
  • The next task here is to implement a token generation helper as well as initializing the connection on the client side. This will consist of continuously sending a pong back to the server.
  • Furthermore, we're going to need API endpoints for our WS server to hit to do certain operations like end an OA.

Checklist

Please go through all items before requesting reviewers:

  • All commits are tagged with the ticket number
  • No linting errors / newline warnings
  • All code follows repository-configured formatting
  • No merge conflicts
  • All checks passing
  • Screenshots included for UI changes
  • Remove non-applicable sections of this template
  • PR assigned to yourself
  • Reviewers requested & Slack ping sent
  • PR linked to the issue (fill in 'Closes #')
  • If design-related, notify the designer in Slack

Closes

Closes #266

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sarge Ready Ready Preview, Comment Mar 30, 2026 2:23pm

Request Review

Comment thread src/ws/index.js
}

ws.on('connection', async (socket, request) => {
const token = getTokenFromRequest(request);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the token get initially added to the connection request? I'm assuming this is something we will set up when configuring the websocket on the client (aka in the react code)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the token will be generated using our client and API. As long as the secrets are the same, this will be a successful operation. If not, then the catch will drop the connection.

Copy link
Copy Markdown
Collaborator

@cherman23 cherman23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with questions - might require changes based on answers

Comment thread src/ws/index.js
});

socket.on('error', (err) => {
console.error(`Socket error for ${socket.userId}:`, err.message);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to send an error message to our main server if it's broken? Lmk if this is even feasible.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Let's add this when developing the client side logic.

Comment thread src/ws/index.js
});

ws.on('error', (err) => {
console.error('Socket error: ', err);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@LOTaher LOTaher self-assigned this Mar 30, 2026
@LOTaher LOTaher marked this pull request as ready for review March 30, 2026 18:42
@LOTaher LOTaher merged commit 8ae813c into main Mar 30, 2026
4 checks passed
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

Successfully merging this pull request may close these issues.

[OA][Infrastructure] - Init WS Server

2 participants