bradtraversy / chatcord

Realtime chat app with rooms
1.18k stars 1.15k forks source link

Chatroom issue #7

Open saksham7778 opened 4 years ago

saksham7778 commented 4 years ago

people with same name should not be allowed to enter the same chatroom can you tell me how to implement it ?

leslie-alldridge commented 4 years ago

@saksham7778 I've implemented this over on my repository here

Please take note of changes made to index.html, js/login.js, server.js

Long story short, it uses the global object Brad created to do the following:

  1. User requests to login
  2. Check if username exists in global state object
  3. If exists, send user back to home page and never proceed with any further socket stuff (e.g. joining a room...)
  4. If user is unique, carry on with Brad's normal socket flow so you can chat etc.

Pretty simple really, just need to apply some lateral thinking and problem solving skills. Anyone can copy paste code, but to take your learning to the next level I suggest not copying what I've done and create your own solution.

Cheers

William94wps commented 4 years ago

What would the code look like to send messages to a specific user?