Dun-sin / Whisper

A fun Application to have a random chat with people safely
https://whisper.favour.dev/
MIT License
390 stars 367 forks source link

feat: Close chat functionality in home screen #697

Closed Priyanshu-2005 closed 1 month ago

Priyanshu-2005 commented 1 month ago

Fixes Issue

@Dun-sin My PR closes #677

👨‍💻 Changes proposed(What did you do ?)

Added a button Close Chat with onClick functionality to trigger a function call doCloseChat() which further emits a socket request from client side for event NEW_EVENT_CLOSE which further calls emitClose() function .

The emitClose function is responsible for handling the closure of a chat. If an error occurs while closing, it alerts the user; otherwise, it either closes the current chat or navigates the user back to the homepage, depending on whether the chat was successfully closed. The clearTimer function is called to stop any running timers. It further calls the closeChat() function.

The server listens to the request and broadcasts socket request from server side for event NEW_EVENT_CLOSE which calls a function onClose to notify the other person (who has not closed the chat) that the chat room has been closed.

✔️ Check List (Check all the applicable boxes)

Note to reviewers

📷 Screenshots

Screencast from 07-10-24 10:15:20 PM IST.webm

Client A and B searching for a buddy. image

Both connected now image

Both are able to chat image

Client A trying to close chat form home screen image

Client A closed the chat from home screen and client B is prompted a dialog box informing that the chat room has been closed and asking whether to start a new search image

Client B starts a new search image

vercel[bot] commented 1 month ago

Someone is attempting to deploy a commit to the dunsin's projects Team on Vercel.

A member of the Team first needs to authorize it.

Priyanshu-2005 commented 1 month ago

Thanks @Dun-sin for accepting the changes. It took a while to implement websocket to close the chat on button click Close Chat. But it was a great learning.

Also Kindly label my PR as hacktoberfest-accepted