Skip to content

broadcast setup - #7

Merged
itsXILO merged 2 commits into
mainfrom
feat/broadcast-commentary
Aug 5, 2026
Merged

broadcast setup#7
itsXILO merged 2 commits into
mainfrom
feat/broadcast-commentary

Conversation

@itsXILO

@itsXILO itsXILO commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added real-time commentary updates after commentary is created.
    • Improved WebSocket connection handling, including authorization, heartbeat checks, and subscription cleanup.
    • Added clearer responses for unauthorized, rate-limited, and failed connection attempts.
  • Bug Fixes

    • Improved broadcast reliability by handling disconnected connections and reusing prepared messages.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@itsXILO, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 41 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c2e1442d-eead-4084-a024-7844fde50613

📥 Commits

Reviewing files that changed from the base of the PR and between 1d7a921 and 99dfb10.

📒 Files selected for processing (5)
  • package.json
  • src/index.js
  • src/routes/matches.js
  • src/ws/server.js
  • tests/commentary.test.js
📝 Walkthrough

Walkthrough

The WebSocket server now authorizes /ws upgrades, manages connection health and subscriptions, and exposes commentary broadcasting. The commentary creation route invokes the broadcast callback with the created record’s match ID and result.

Changes

WebSocket commentary flow

Layer / File(s) Summary
Protected WebSocket upgrade
src/ws/server.js
The server uses a noServer WebSocket instance and handles /ws upgrades with Arcjet authorization and HTTP error responses.
Subscription and connection lifecycle
src/ws/server.js
Connections validate subscription messages, broadcast serialized payloads, remove subscriptions on close, and use heartbeat checks with interval cleanup.
Commentary broadcast integration
src/ws/server.js, src/routes/commentary.js
The returned API exposes broadcastCommentary. The commentary route calls it with the created record’s match ID and result.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CommentaryRoute
  participant WebSocketServer
  participant MatchSubscribers
  participant WebSocketClient
  WebSocketClient->>WebSocketServer: Subscribe to match
  WebSocketServer->>MatchSubscribers: Store subscription
  CommentaryRoute->>WebSocketServer: Broadcast commentary
  WebSocketServer->>MatchSubscribers: Find match subscribers
  MatchSubscribers-->>WebSocketClient: Send commentary payload
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately identifies the pull request as configuring broadcast functionality, which is the main focus of the changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/broadcast-commentary

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/routes/commentary.js`:
- Around line 97-99: Update application startup’s destructured broadcast locals
to include broadcastCommentary, ensuring it is assigned to app.locals for the
commentary route’s existing check. Add an integration test covering commentary
creation and asserting receipt of the commentary WebSocket event.

In `@src/ws/server.js`:
- Around line 141-149: The HTTP shutdown flow in src/index.js must also clean up
the WebSocket server: invoke server.closeAllConnections(), terminate active
clients, close the WebSocketServer, and clear the heartbeat interval created
near the setInterval call. Update the shutdown handling around the HTTP server
listener rather than relying on wss’s close event, while preserving normal
heartbeat behavior during operation.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ee810831-8ebd-4db1-9b89-abadf6ddd52a

📥 Commits

Reviewing files that changed from the base of the PR and between 9c555b3 and 1d7a921.

📒 Files selected for processing (2)
  • src/routes/commentary.js
  • src/ws/server.js

Comment thread src/routes/commentary.js
Comment on lines +97 to +99
if(res.app.locals.broadcastCommentary) {
res.app.locals.broadcastCommentary(result.matchId, result);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -nP --type=js -C 3 \
  '(?:const|let|var)\s*\{[^}]*\}\s*=\s*attachWebSocketServer\s*\(|\.broadcastCommentary\b|broadcastCommentary\s*=' \
  src

Repository: itsXILO/LiveWire

Length of output: 953


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the WebSocket attachment implementation and inspect its returned locals/public API.
rg -n -C 4 'function attachWebSocketServer|attachWebSocketServer\s*=|broadcastCommentary|broadcastMatchCreated' .

Repository: itsXILO/LiveWire

Length of output: 3088


Register broadcastCommentary during application startup.

The startup code destructures only broadcastMatchCreated, so app.locals.broadcastCommentary is unset when the commentary route checks res.app.locals.broadcastCommentary. Add broadcastCommentary to the destructured locals assigned to app.locals, and add an integration test that creates commentary and receives the commentary WebSocket event.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/routes/commentary.js` around lines 97 - 99, Update application startup’s
destructured broadcast locals to include broadcastCommentary, ensuring it is
assigned to app.locals for the commentary route’s existing check. Add an
integration test covering commentary creation and asserting receipt of the
commentary WebSocket event.

Comment thread src/ws/server.js Outdated
@itsXILO
itsXILO merged commit 2795799 into main Aug 5, 2026
1 check 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.

1 participant