This project is a simple WebSocket-based chat application built with React. It allows users to join a chat by setting a username, send messages, and view messages in real-time from other users. Each user is assigned a unique color to differentiate their messages in the chat.
-
Real-time messaging via WebSocket
-
Username-based user identification
-
Random color assignment to differentiate users
-
Auto-scroll chat window for the latest messages
-
Node.js and npm installed
-
A WebSocket server running at ws://localhost:9080/ws-blog/chat
-
Clone the repository:
git clone [email protected]:sweettypdevassy/ws-blog-frontend.git cd ws-blog-frontend
-
Install dependencies:
npm install
-
Run the application:
npm start
Open http://localhost:3000 in two browser to view the application.
-
Enter a unique username to join the chat.
-
Type a message in the input field and press "Send" or hit "Enter" to send it.
-
Messages will appear in the chat box with a unique color for each user.
-
Chat.js: The main component for the chat application.
-
WebSocket Setup: Establishes a WebSocket connection to listen for incoming messages and sends outgoing messages.
-
Username & Color Assignment: Sets the username and assigns a unique color based on the username.
-
Message Rendering: Displays messages in a chat box with color-coding.
-
Chat.css: Styles the chat components, including the chat box, message alignment, color-coding, and layout.
-
You can customize the chat application by:
-
Modifying the list of colors in the colors array for different user colors.
-
Adjusting CSS styles in Chat.css for layout, colors, and message display.