Skip to content

Conversation

@Swastik221
Copy link
Contributor

  1. Removed Duplicate Event Handlers • Originally, you had two separate typing events → one calling a controller, and one broadcasting directly. • Now, we keep only the broadcasting version inside registerChatEvents, avoiding duplication and possible conflicts.
  2. Centralized Error Handling • Instead of repeating error checks in every event: • We now have a handleResult() utility that standardizes error logging and socket emission.
  3. Grouped Events by Category • Separated events into: • registerFileEvents • registerRoomEvents • registerChatEvents • registerVideoCallEvents • This makes the code easier to navigate and maintain. If you add a new event, you know exactly where it belongs.
  4. Consistent Event Naming • Changed event names to use kebab-case (join-room, leave-room, join-call). • This ensures naming consistency across all socket events.
  5. Dynamic File Event Mapping • Instead of writing repetitive handlers: • We loop over an array of file events and dynamically call the matching controller method (handleCreateFile, handleDeleteFile, etc.). • This reduces repetition and makes it easier to add/remove file-related events.
  6. Better Disconnect Handling • Previously, only the RoomController handled disconnects. • Now, both RoomController and VideoCallController are given a chance to clean up when a user disconnects.
  7. Future-Proofing (Async Ready) • Although this refactor keeps methods synchronous, the structure (handleResult) allows easy switch to async/await later if controllers perform DB or API calls. Net result:
    • Cleaner
    • DRY (Don’t Repeat Yourself)
    • Easier to extend
    • Consistent naming
    • Robust disconnect handling

1. Removed Duplicate Event Handlers
	•	Originally, you had two separate typing events → one calling a controller, and one broadcasting directly.
	•	Now, we keep only the broadcasting version inside registerChatEvents, avoiding duplication and possible conflicts.
2. Centralized Error Handling
	•	Instead of repeating error checks in every event:
	•	We now have a handleResult() utility that standardizes error logging and socket emission.
3. Grouped Events by Category
	•	Separated events into:
	•	registerFileEvents
	•	registerRoomEvents
	•	registerChatEvents
	•	registerVideoCallEvents
	•	This makes the code easier to navigate and maintain. If you add a new event, you know exactly where it belongs.
4. Consistent Event Naming
	•	Changed event names to use kebab-case (join-room, leave-room, join-call).
	•	This ensures naming consistency across all socket events.
5. Dynamic File Event Mapping
	•	Instead of writing repetitive handlers:
	•	We loop over an array of file events and dynamically call the matching controller method (handleCreateFile, handleDeleteFile, etc.).
	•	This reduces repetition and makes it easier to add/remove file-related events.
6. Better Disconnect Handling
	•	Previously, only the RoomController handled disconnects.
	•	Now, both RoomController and VideoCallController are given a chance to clean up when a user disconnects.
7. Future-Proofing (Async Ready)
	•	Although this refactor keeps methods synchronous, the structure (handleResult) allows easy switch to async/await later if controllers perform DB or API calls.
Net result:
	•	Cleaner 
	•	DRY (Don’t Repeat Yourself) 
	•	Easier to extend 
	•	Consistent naming 
	•	Robust disconnect handling
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