-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/pix 58 validate user join #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2425a90
PIX-58 validate lobby access
matteosusca ccee2c6
PIX-58 fix join race condition and simplify validation logic
matteosusca c1de011
PIX-58 Update server/src/middlewares/permissionMiddleware.ts
matteosusca 064ffa9
PIX-58 Update server/src/sockets/index.ts
matteosusca 03fad62
Update server/src/services/canvas.service.ts
matteosusca 7c73cce
PIX-58 removed unused verifyCanJoin
matteosusca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { Server, Socket } from 'socket.io'; | ||
|
|
||
| /** | ||
| * Gets the number of connected users in a specific lobby. | ||
| * @param io The Socket.IO server instance | ||
| * @param lobbyName The name of the lobby (room) | ||
| * @returns The number of clients in the room | ||
| */ | ||
| export const getLobbyUserCount = (io: Server, lobbyName: string): number => { | ||
| return io.sockets.adapter.rooms.get(lobbyName)?.size || 0; | ||
| }; | ||
|
|
||
| /** | ||
| * Fetches all users currently connected to a lobby. | ||
| */ | ||
| export const getUsersInLobby = async (io: Server, lobbyName: string): Promise<any[]> => { | ||
| const sockets = await io.in(lobbyName).fetchSockets(); | ||
| return sockets.map(s => s.data.user).filter(u => u); | ||
| }; | ||
|
|
||
| /** | ||
| * Broadcasts an event to all users in a lobby (including sender). | ||
| */ | ||
| export const broadcastToLobby = (io: Server, lobbyName: string, event: string, data: any) => { | ||
| io.to(lobbyName).emit(event, data); | ||
| }; | ||
|
|
||
| /** | ||
| * Broadcasts an event to all other users in a lobby (excluding sender). | ||
| */ | ||
| export const broadcastToOthers = (socket: Socket, lobbyName: string, event: string, data: any) => { | ||
| socket.to(lobbyName).emit(event, data); | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capacity validation uses
currentCount - 1after an optimisticsocket.join(), which makes the intent (checking count before vs after the join) hard to follow and easy to get wrong later. Consider computing a clearly namedcountBeforeJoin(or validating using the post-join count and checking> maxCollaborators) to make the off-by-one behavior explicit.