|
| 1 | +# Chat E2EE Client - React.js Implementation |
| 2 | + |
| 3 | +This is the React.js implementation of the Chat E2EE client, migrated from vanilla TypeScript while maintaining full functional parity with the original. |
| 4 | + |
| 5 | +## 📋 Project Structure |
| 6 | + |
| 7 | +``` |
| 8 | +src/ |
| 9 | +├── components/ # All React components |
| 10 | +│ ├── common/ # Reusable UI components (Button, Input, Icons) |
| 11 | +│ ├── SetupOverlay/ # Channel creation/joining flow |
| 12 | +│ ├── ChatContainer/ # Main chat interface |
| 13 | +│ └── CallOverlay/ # Audio call UI |
| 14 | +├── context/ # React Context for global state |
| 15 | +│ └── ChatContext.tsx # Chat service wrapper and state management |
| 16 | +├── hooks/ # Custom React hooks |
| 17 | +│ ├── useCallTimer.ts |
| 18 | +│ ├── useUrlHash.ts |
| 19 | +│ └── useAudioNotification.ts |
| 20 | +├── types/ # TypeScript type definitions |
| 21 | +├── utils/ # Utility functions |
| 22 | +│ ├── audioNotification.ts |
| 23 | +│ ├── messageHandling.ts |
| 24 | +│ └── callTimer.ts |
| 25 | +├── styles/ # Global styles |
| 26 | +│ └── global.css |
| 27 | +├── App.tsx # Main application component |
| 28 | +└── main.tsx # React application entry point |
| 29 | +``` |
| 30 | + |
| 31 | +## 🚀 Getting Started |
| 32 | + |
| 33 | +### Prerequisites |
| 34 | +- Node.js (v16+) |
| 35 | +- npm or yarn |
| 36 | + |
| 37 | +### Installation |
| 38 | + |
| 39 | +```bash |
| 40 | +cd client |
| 41 | +npm install |
| 42 | +``` |
| 43 | + |
| 44 | +### Development Server |
| 45 | + |
| 46 | +```bash |
| 47 | +npm run dev |
| 48 | +``` |
| 49 | + |
| 50 | +The application will be available at `http://localhost:5173` |
| 51 | + |
| 52 | +### Building for Production |
| 53 | + |
| 54 | +```bash |
| 55 | +npm run build |
| 56 | +``` |
| 57 | + |
| 58 | +The compiled output will be in the `dist/` folder. |
| 59 | + |
| 60 | +### Preview Production Build |
| 61 | + |
| 62 | +```bash |
| 63 | +npm run preview |
| 64 | +``` |
| 65 | + |
| 66 | +## 🏗️ Architecture |
| 67 | + |
| 68 | +### State Management |
| 69 | +- **ChatContext**: Wraps the `@chat-e2ee/service` package without any modifications |
| 70 | +- Global state includes: connection status, messages, call status, user ID, and channel hash |
| 71 | +- All service initialization and event handling is managed through React hooks |
| 72 | + |
| 73 | +### Component Hierarchy |
| 74 | + |
| 75 | +``` |
| 76 | +App |
| 77 | +├── ChatProvider (Context) |
| 78 | +│ ├── SetupOverlay |
| 79 | +│ │ ├── InitialActions |
| 80 | +│ │ ├── CreateHashView |
| 81 | +│ │ └── JoinHashView |
| 82 | +│ └── ChatContainer |
| 83 | +│ ├── ChatHeader |
| 84 | +│ ├── MessagesArea |
| 85 | +│ │ └── MessageBubble (repeated) |
| 86 | +│ ├── ChatFooter |
| 87 | +│ └── CallOverlay |
| 88 | +``` |
| 89 | + |
| 90 | +### Key Features |
| 91 | +- ✅ Full end-to-end message encryption |
| 92 | +- ✅ Audio call support |
| 93 | +- ✅ Real-time peer detection |
| 94 | +- ✅ Glass-morphism UI design |
| 95 | +- ✅ Mobile-responsive layout |
| 96 | +- ✅ Native share API integration |
| 97 | +- ✅ URL hash auto-population for channel joining |
| 98 | + |
| 99 | +## 🔒 Security & Backend Integration |
| 100 | + |
| 101 | +**Important:** All backend communication and encryption logic is handled by the `@chat-e2ee/service` package. This client implementation: |
| 102 | +- ✅ Does NOT modify any service logic |
| 103 | +- ✅ Does NOT change API contracts |
| 104 | +- ✅ Only wraps the service with React state management |
| 105 | +- ✅ Preserves all encryption/decryption calls |
| 106 | + |
| 107 | +Backend environment variable: |
| 108 | +```bash |
| 109 | +CHATE2EE_API_URL=http://localhost:3001 # or your backend URL |
| 110 | +``` |
| 111 | + |
| 112 | +## 📱 Responsive Design |
| 113 | + |
| 114 | +The UI is fully responsive and tested on: |
| 115 | +- Desktop browsers (1920x1080+) |
| 116 | +- Tablets (768px+) |
| 117 | +- Mobile phones (320px+) |
| 118 | +- iOS Safe Area support for notches |
| 119 | + |
| 120 | +## 🔄 Migration Notes |
| 121 | + |
| 122 | +This is a pure UI layer refactoring from vanilla TypeScript to React.js: |
| 123 | + |
| 124 | +**What Changed:** |
| 125 | +- DOM manipulation replaced with React components |
| 126 | +- Event listeners replaced with React hooks and Context |
| 127 | +- Global variables replaced with React state |
| 128 | +- CSS organization improved with component-scoped styling |
| 129 | + |
| 130 | +**What Stayed the Same:** |
| 131 | +- All service integration unchanged |
| 132 | +- All encryption logic unchanged |
| 133 | +- All API calls unchanged |
| 134 | +- All user-facing functionality identical |
| 135 | +- All UI/UX identical |
| 136 | + |
| 137 | +## 🧪 Testing |
| 138 | + |
| 139 | +### Manual Testing Checklist |
| 140 | + |
| 141 | +- [ ] Create new channel flow |
| 142 | +- [ ] Join existing channel flow |
| 143 | +- [ ] Send/receive messages in real-time |
| 144 | +- [ ] Audio call initiation and termination |
| 145 | +- [ ] Copy hash functionality |
| 146 | +- [ ] URL hash auto-population |
| 147 | +- [ ] Peer detection and status indicators |
| 148 | +- [ ] Mobile responsiveness |
| 149 | +- [ ] Message animations |
| 150 | +- [ ] Call duration timer |
| 151 | + |
| 152 | +### Browser Support |
| 153 | + |
| 154 | +- Chrome/Chromium 90+ |
| 155 | +- Firefox 88+ |
| 156 | +- Safari 14+ |
| 157 | +- Edge 90+ |
| 158 | + |
| 159 | +## 🛠️ Development |
| 160 | + |
| 161 | +### Adding a New Component |
| 162 | + |
| 163 | +1. Create component directory in `src/components/` |
| 164 | +2. Add component file (`.tsx`) and styles file (`.css`) |
| 165 | +3. Export from component file using named export |
| 166 | +4. Import and use in parent component |
| 167 | + |
| 168 | +### Adding a New Hook |
| 169 | + |
| 170 | +1. Create hook file in `src/hooks/` |
| 171 | +2. Use React hooks (useState, useEffect, useCallback, etc.) |
| 172 | +3. Export custom hook with `use` prefix |
| 173 | +4. Import in components that need it |
| 174 | + |
| 175 | +### Styling Guidelines |
| 176 | + |
| 177 | +- Use CSS classes for styling (not inline styles) |
| 178 | +- Follow BEM-like naming: `component-name`, `component-name__element` |
| 179 | +- Import CSS in component file for scoped styling |
| 180 | +- Use CSS variables from `styles/global.css` for consistency |
| 181 | +- Maintain mobile-first responsive design |
| 182 | + |
| 183 | +## 📦 Dependencies |
| 184 | + |
| 185 | +- `react@^18.2.0` - React library |
| 186 | +- `react-dom@^18.2.0` - React DOM rendering |
| 187 | +- `@chat-e2ee/service@*` - E2EE messaging service (unmodified) |
| 188 | +- `typescript@^5.6.2` - TypeScript compiler |
| 189 | +- `vite@^5.4.1` - Build tool |
| 190 | + |
| 191 | +## 🐛 Troubleshooting |
| 192 | + |
| 193 | +### Chat not initializing |
| 194 | +- Check `CHATE2EE_API_URL` environment variable |
| 195 | +- Verify backend server is running |
| 196 | +- Check browser console for detailed errors |
| 197 | + |
| 198 | +### Messages not sending |
| 199 | +- Ensure peer has joined the channel |
| 200 | +- Check network connection |
| 201 | +- Verify encryption keys are initialized |
| 202 | + |
| 203 | +### Build errors |
| 204 | +- Run `npm install` to ensure all dependencies are installed |
| 205 | +- Check Node.js version (requires v16+) |
| 206 | +- Clear `node_modules` and reinstall if needed |
| 207 | + |
| 208 | +## 📄 License |
| 209 | + |
| 210 | +Same as the main Chat E2EE project. |
| 211 | + |
| 212 | +## 🤝 Contributing |
| 213 | + |
| 214 | +This is part of the open-source Chat E2EE project. When contributing: |
| 215 | + |
| 216 | +1. **Only modify files within the `client/` folder** |
| 217 | +2. **Do not change `@chat-e2ee/service` imports or behavior** |
| 218 | +3. **Maintain full backward compatibility with the service** |
| 219 | +4. **Test all features before submitting PR** |
| 220 | +5. **Follow the existing code style and component patterns** |
| 221 | + |
| 222 | +For specific contribution guidelines, see the main project README. |
| 223 | + |
| 224 | +--- |
| 225 | + |
| 226 | +Made with ❤️ for secure, private communication |
0 commit comments