Skip to content

Conversation

@anand9125
Copy link

This PR rewrites the entire WebSocket flow to use Actix actors instead of the previous manual handler-based implementation.
The old approach mixed state management, routing, and message broadcasting inside a single handler, which caused issues with lifetimes, shared mutability, and concurrency.

The new architecture fully adopts the Actix actor model:

Changes:
Introduced a WsClient actor to encapsulate per-connection state and handle incoming WebSocket frames.
Added a RoomManager actor responsible for room creation, membership tracking, and broadcasting messages to connected clients.
Replaced manual message routing with typed Actix messages (Join, Leave, RoomMessage, etc.).
Removed lifetime-dependent logic and moved all mutable shared state into Actor mailboxes.
Improved isolation between clients — no shared mutable state, no need for mutexes.
Ensured safe, concurrent communication using Actix’s actor scheduling and message passing.

Benefits:

Cleaner separation of concerns (client vs room management).
No lifetime errors from shared references.
Proper concurrency — actors never block the event loop.
Easier to extend (adding rooms, private messages, game logic, etc.)
More idiomatic Rust + Actix implementation.

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