A real-time web application that connects users on Google Maps with text chat and video chat functionality. This application allows users to see each other's locations on a map and communicate in real-time.
- Real-time User Location Tracking: Users' locations are displayed on Google Maps
- Text Chat: Real-time messaging between users
- Video Chat: WebRTC-based video communication
- Proximity-based User Discovery: Find users within a specific radius
- Persistent User Data: User information is stored in Redis
- Backend: Rust with Axum web framework
- Real-time Communication: WebSockets for chat and WebRTC for video
- Database: Redis for storing user data and geospatial information
- Frontend: React with TypeScript, Tailwind CSS, and Google Maps integration
- Rust (latest stable version)
- Node.js and npm (for the React frontend)
- Redis server
- Environment variables setup (see Configuration section)
The backend requires the following environment variables:
REDIS_URL
: URL for connecting to RedisPORT
: Port number for the web serverWS_SERVER
: WebSocket server URL
You can set these in a .env
file in the project root.
Example .env
file:
REDIS_URL=redis://localhost:6379
PORT=3000
WS_SERVER=ws://localhost:3000/ws
The React frontend requires the following environment variables:
REACT_APP_GOOGLE_MAPS_API_KEY
: Google Maps API keyREACT_APP_WEBSOCKET_URL
: WebSocket server URL
You can set these in a .env
file in the front
directory.
Example .env
file for frontend:
REACT_APP_GOOGLE_MAPS_API_KEY=your_google_maps_api_key
REACT_APP_WEBSOCKET_URL=ws://localhost:3000
- Clone the repository
- Install Rust dependencies:
cargo build
- Set up environment variables (see Backend Configuration section)
- Run the backend:
cargo run
- Navigate to the
front
directory:cd front
- Install Node.js dependencies:
npm install
- Set up environment variables (see Frontend Configuration section)
- Run the frontend development server:
npm start
- Open a web browser and navigate to
http://localhost:<PORT>/Chat
- Allow location access when prompted
- Your position will be displayed on the map
- Other users in the vicinity will appear on the map
- Click on a user to initiate a chat or video call
/ws
: WebSocket endpoint for real-time communication/Chat
: Main application page/position
: POST endpoint to update user position/users
: POST endpoint to get all users/usersinbounds
: POST endpoint to get users within a specific radius
- User Registration: When a user connects, their location is stored in Redis
- Location Updates: Users' positions are updated in real-time and broadcast to other users
- Chat Messages: Text messages are sent through WebSockets and delivered to the appropriate recipients
- Video Chat: WebRTC is used to establish peer-to-peer connections for video communication
- User Removal: When a user disconnects, their information is removed from Redis and other users are notified
- Authentication: Users log in using AWS Cognito authentication
- Map Initialization: Google Maps is initialized with the user's current location
- WebSocket Connection: A WebSocket connection is established to receive real-time updates
- User Discovery: Nearby users are displayed on the map based on geolocation
- Chat Functionality:
- Users can send messages to specific users or broadcast to all
- Messages are transmitted via WebSockets
- The chat interface displays incoming and outgoing messages
- Video Chat:
- Users can initiate video calls with other users
- WebRTC is used for peer-to-peer video/audio communication
- The application handles SDP (Session Description Protocol) and ICE (Interactive Connectivity Establishment) for WebRTC connection setup
- Users can accept or decline incoming video call requests
The backend project structure follows standard Rust conventions:
src/main.rs
: Application entry point and server setupsrc/lib.rs
: Core data structures and utility functionssrc/handlers/
: Request handlers for different endpointsposition.rs
: Handlers for location-related endpointswebsocket.rs
: WebSocket connection handling
The frontend is a React application with TypeScript and is located in the front
directory:
src/App.tsx
: Main application component with routingsrc/components/
: React componentsGoogleMap.tsx
: Main map componentMapCtrl.tsx
: Map control componentvideoChat.tsx
: Video chat componentWebSocketProvider.tsx
: WebSocket context providerparts/
: Smaller UI components
src/contexts/
: React context providersAuthContext.tsx
: Authentication context
src/api/
: API communication functionssrc/types/
: TypeScript type definitionssrc/util/
: Utility functions
- Login: Handles user authentication using AWS Cognito
- SignUp: Allows new users to register
- AuthContext: Manages authentication state throughout the application
- GoogleMap: Main component that initializes the Google Maps API and gets the user's current location
- MapCtrl: Controls the map display, handles user markers, and manages the map's idle state to fetch nearby users
- MarkerWithInfoWindow: Displays user markers on the map with information windows
- WebSocketProvider: Manages WebSocket connections for real-time communication
- SendMsgForm: Interface for sending and receiving text messages
- VideoChat: Handles video chat functionality using WebRTC
- Manages media streams
- Handles SDP offer/answer exchange
- Manages ICE candidate exchange
- Provides UI controls for video chat (connect/disconnect, etc.)
- WebSocketWrapper: Wraps WebSocket functionality
- WebRtc: Manages WebRTC peer connections
- EventBus: Provides event-based communication between components
The frontend and backend integrate through several key mechanisms:
- The React frontend establishes a WebSocket connection to the Rust backend
- Real-time messages are exchanged through this connection
- The backend broadcasts messages to appropriate recipients
- The frontend displays incoming messages and allows sending new ones
- The frontend makes HTTP requests to the backend API endpoints
- User positions are updated via the
/position
endpoint - Nearby users are fetched via the
/usersinbounds
endpoint - The backend processes these requests and interacts with Redis
- The WebSocket connection is used for WebRTC signaling
- SDP offers/answers and ICE candidates are exchanged through WebSockets
- The backend acts as a relay for WebRTC signaling messages
- Once the WebRTC connection is established, video/audio data flows directly between peers
- When users connect to the frontend, their information is sent to the backend
- The backend stores user data in Redis, including geolocation
- When users disconnect, the backend removes their data and notifies other users
- The frontend updates the map display based on user presence/absence notifications