Skip to content

Commit 9c1f01b

Browse files
author
VishnuGadekar7
committed
Merged Client from Vanilla HTML JS to React 18 Components
1 parent 5e0032d commit 9c1f01b

42 files changed

Lines changed: 2604 additions & 275 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

client/README.md

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
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

client/index.html

Lines changed: 3 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -5,138 +5,15 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
77
<title>Chat E2EE - Minimal & Secure</title>
8-
<link rel="stylesheet" href="./style.css">
98
<link rel="preconnect" href="https://fonts.googleapis.com">
109
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
1110
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600&display=swap" rel="stylesheet">
1211
</head>
1312

1413
<body>
15-
<div id="app">
16-
<!-- Setup Overlay -->
17-
<div id="setup-overlay" class="overlay">
18-
<div class="overlay-content glass">
19-
<h1>Secure Messenger</h1>
20-
<p>Simple. End-to-End Encrypted. Private.</p>
21-
22-
<div id="initial-actions" class="button-group-vertical">
23-
<button id="show-create-hash" class="primary large">Create New Channel</button>
24-
<button id="show-join-hash" class="secondary large">Already have a Hash?</button>
25-
</div>
26-
27-
<div id="create-hash-view" class="hidden">
28-
<div class="input-group">
29-
<label>Your Channel Hash</label>
30-
<div class="copy-input">
31-
<input type="text" id="generated-hash-display" readonly placeholder="Generating...">
32-
<button id="copy-hash-btn" class="icon-btn small">
33-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
34-
stroke-linecap="round" stroke-linejoin="round">
35-
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
36-
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
37-
</svg>
38-
</button>
39-
</div>
40-
</div>
41-
</div>
42-
43-
<div id="join-hash-view" class="hidden">
44-
<div class="input-group">
45-
<label for="channel-hash">Channel Hash</label>
46-
<input type="text" id="channel-hash" placeholder="Enter hash to join...">
47-
</div>
48-
</div>
49-
50-
<div id="final-actions" class="hidden">
51-
<div class="button-group">
52-
<button id="back-btn" class="secondary">Back</button>
53-
<button id="join-btn" class="primary">Connect Securely</button>
54-
</div>
55-
</div>
56-
57-
<div id="setup-status" class="status-text"></div>
58-
</div>
59-
</div>
60-
61-
<!-- Main Chat UI -->
62-
<div id="chat-container" class="hidden">
63-
<header class="glass">
64-
<div class="header-info">
65-
<div class="title-row">
66-
<span class="dot" id="status-dot"></span>
67-
<h2 id="channel-title">Secure Channel</h2>
68-
<span id="encryption-badge" class="badge">E2EE</span>
69-
</div>
70-
<div id="channel-hash-display" class="hash-badge-container hidden">
71-
<span id="header-hash" class="hash-text"></span>
72-
<button id="copy-header-hash" class="icon-btn tiny" title="Copy Link">
73-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
74-
stroke-linecap="round" stroke-linejoin="round">
75-
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
76-
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
77-
</svg>
78-
</button>
79-
</div>
80-
<p id="participant-info">Waiting for someone to join...</p>
81-
</div>
82-
<div class="header-actions">
83-
<button id="share-btn" title="Share Link" class="icon-btn hidden">
84-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
85-
stroke-linecap="round" stroke-linejoin="round">
86-
<circle cx="18" cy="5" r="3"></circle>
87-
<circle cx="6" cy="12" r="3"></circle>
88-
<circle cx="18" cy="19" r="3"></circle>
89-
<line x1="8.59" y1="13.51" x2="15.42" y2="17.49"></line>
90-
<line x1="15.41" y1="6.51" x2="8.59" y2="10.49"></line>
91-
</svg>
92-
</button>
93-
<button id="start-call-btn" title="Start Audio Call" class="icon-btn">
94-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
95-
stroke-linecap="round" stroke-linejoin="round">
96-
<path
97-
d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z">
98-
</path>
99-
</svg>
100-
</button>
101-
</div>
102-
</header>
103-
104-
<main id="messages-area">
105-
<!-- Messages will appear here -->
106-
</main>
107-
108-
<footer class="glass">
109-
<div class="input-container">
110-
<input type="text" id="msg-input" placeholder="Type a secure message...">
111-
<button id="send-btn" class="primary circle">
112-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"
113-
stroke-linecap="round" stroke-linejoin="round">
114-
<line x1="22" y1="2" x2="11" y2="13"></line>
115-
<polygon points="22 2 15 22 11 13 2 9 22 2"></polygon>
116-
</svg>
117-
</button>
118-
</div>
119-
</footer>
120-
</div>
121-
122-
<!-- Call Status Overlay -->
123-
<div id="call-overlay" class="hidden glass blur-overlay">
124-
<div class="call-info">
125-
<div class="call-avatar shimmer"></div>
126-
<h3 id="call-status">Calling...</h3>
127-
<p id="call-duration">00:00</p>
128-
<button id="end-call-btn" class="danger circle large">
129-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
130-
stroke-linejoin="round">
131-
<path
132-
d="M10.68 13.31a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7 2 2 0 0 1 1.72 2v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z">
133-
</path>
134-
</svg>
135-
</button>
136-
</div>
137-
</div>
138-
</div>
139-
<script type="module" src="./app.ts"></script>
14+
<!-- React renders everything here -->
15+
<div id="app"></div>
16+
<script type="module" src="./src/main.tsx"></script>
14017
</body>
14118

14219
</html>

client/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
},
1212
"devDependencies": {
1313
"typescript": "^5.6.2",
14-
"vite": "^5.4.1"
14+
"vite": "^5.4.1",
15+
"@vitejs/plugin-react": "^4.2.1",
16+
"@types/react": "^18.2.37",
17+
"@types/react-dom": "^18.2.15"
1518
},
1619
"dependencies": {
17-
"@chat-e2ee/service": "*"
20+
"@chat-e2ee/service": "*",
21+
"react": "^18.2.0",
22+
"react-dom": "^18.2.0"
1823
}
1924
}

0 commit comments

Comments
 (0)