Skip to content

Fix event handling bugs and cleanup #9

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

uguratar
Copy link
Member

Summary

  • use a separate total_toppers event for user counts
  • validate user names on registration
  • remove socket listeners when components are destroyed

Testing

  • npm run lint (fails: tslint: not found)
  • npm run test (fails: ng: not found)

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes event-handling inconsistencies, adds registration validation, and ensures socket listeners are cleaned up when components are destroyed.

  • Introduce a separate total_toppers event for user counts
  • Validate currentTopper.name before registering users
  • Implement OnDestroy hooks to remove socket listeners in components

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/app/top-main/top-main.component.ts Implement OnDestroy to remove 'update_toppers' listener
src/app/register/register.component.ts Add name-check in addUser(), switch to 'total_toppers', cleanup
src/app/chat/chat.component.ts Add OnDestroy to remove 'message' listener
server.ts Change initial emit from 'update_toppers' to 'total_toppers'
Comments suppressed due to low confidence (2)

src/app/register/register.component.ts:41

  • Accessing this.currentTopper.name may throw if currentTopper is undefined. Initialize currentTopper in ngOnInit() or add a guard to ensure currentTopper is set before use.
    if (!this.currentTopper.name) {

server.ts:35

  • Other parts of the server may still emit 'update_toppers'. Ensure all server-side emits and client listeners consistently use 'total_toppers' to prevent mismatches.
  client.emit('total_toppers', totalToppers);

const socket = this.socketService.getSocketConnection();
socket.off('total_toppers');
socket.off('update_me');
socket.off('register_failed');
Copy link
Preview

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

You're unsubscribing from 'register_failed', but there’s no matching .on('register_failed', ...) listener in this component. Remove this off call or add the corresponding subscription.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants