Revolutionary Peer-to-Peer Messaging via Web Bluetooth API
Secure, private, and lightning-fast communication without internet connectivity
Bluetooth Chat Web revolutionizes wireless communication by enabling secure, peer-to-peer messaging directly through your browser. No servers, no internet requiredโjust pure device-to-device connectivity powered by cutting-edge Web Bluetooth technology.
graph LR
A[๐ฑ Device A] -->|๐ต Bluetooth LE| B[๐ AES Encryption]
B --> C[๐ก Web Bluetooth API]
C --> D[๐ฌ Real-time Chat]
D --> E[๐ Decryption]
E --> F[๐ฑ Device B]
G[๐ PWA Service Worker] --> D
H[๐ HTTPS Security] --> C
style A fill:#e1f5fe
style D fill:#f3e5f5
style F fill:#e8f5e8
| Feature | Technology | Benefit |
|---|---|---|
| ๐ก Bluetooth Messaging | Web Bluetooth API | Direct device communication without internet |
| ๐ Military-Grade Encryption | AES-256 Encryption | End-to-end message security |
| ๐ฑ Progressive Web App | Service Workers + Manifest | Install as native mobile app |
| โก Lightning Performance | Vite Build System | Sub-second load times |
| ๐ Secure Communication | HTTPS/TLS Protocol | Protected data transmission |
| ๐ฌ Real-time Interface | React 18 Features | Smooth, responsive chat experience |
- Device Discovery: Automatic scanning for nearby Bluetooth devices
- GATT Protocol: Generic Attribute Profile for device communication
- Service UUID Management: Custom Bluetooth service identifiers
- Characteristic Handling: Read/write operations for data transfer
- Connection Monitoring: Real-time connection status tracking
// Advanced Bluetooth connection with error handling
async function connectToDevice() {
try {
const device = await navigator.bluetooth.requestDevice({
acceptAllDevices: true,
optionalServices: ['battery_service', 'custom_chat_service']
});
const server = await device.gatt.connect();
return server;
} catch (error) {
console.error('Bluetooth connection failed:', error);
}
}- Optional Encryption: Toggle encryption on/off based on privacy needs
- Key Exchange: Secure key sharing between devices
- Message Integrity: Cryptographic hash verification
- Forward Secrecy: New keys for each session
// AES encryption implementation
import CryptoJS from 'crypto-js';
function encryptMessage(message, secretKey) {
return CryptoJS.AES.encrypt(message, secretKey).toString();
}
function decryptMessage(ciphertext, secretKey) {
const bytes = CryptoJS.AES.decrypt(ciphertext, secretKey);
return bytes.toString(CryptoJS.enc.Utf8);
}- Offline Functionality: Works without internet connection
- Install Prompt: Add to home screen capability
- Background Sync: Message queue for offline messages
- Push Notifications: Alert users of new messages
- App Icons: Custom icons for all device types
// Advanced service worker for offline support
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open('bluetooth-chat-v1').then((cache) => {
return cache.addAll([
'/',
'/index.html',
'/assets/main.js',
'/assets/styles.css'
]);
})
);
});- Message Bubbles: Styled sender/receiver differentiation
- Typing Indicators: Real-time typing status
- Read Receipts: Message delivery confirmation
- Emoji Support: Rich text formatting
- File Sharing: Bluetooth file transfer capability
| Component | Technology | Purpose |
|---|---|---|
| Framework | React 18+ | Modern UI with concurrent features |
| Build Tool | Vite 5.0+ | Lightning-fast HMR and builds |
| Language | TypeScript | Type-safe development |
| Styling | Tailwind CSS | Utility-first responsive design |
| State Management | Zustand/Redux | Predictable state updates |
| Component | Technology | Purpose |
|---|---|---|
| Communication | Web Bluetooth API | Device-to-device connectivity |
| Encryption | CryptoJS (AES-256) | Secure message encryption |
| PWA | Workbox + Vite PWA Plugin | Progressive web app features |
| Security | HTTPS/TLS | Secure communication protocol |
bluetooth-chat-web/
โโโ ๐ public/ # Static assets
โ โโโ manifest.json # PWA manifest
โ โโโ icons/ # App icons (multiple sizes)
โ โโโ service-worker.js # Custom service worker
โโโ ๐ src/ # Source code
โ โโโ ๐ components/ # React components
โ โ โโโ BluetoothScanner.tsx # Device discovery
โ โ โโโ ChatInterface.tsx # Main chat UI
โ โ โโโ MessageBubble.tsx # Message display
โ โ โโโ ConnectionStatus.tsx # Connection indicator
โ โ โโโ EncryptionToggle.tsx # Security controls
โ โโโ ๐ hooks/ # Custom React hooks
โ โ โโโ useBluetoothConnection.ts # Bluetooth management
โ โ โโโ useEncryption.ts # Encryption utilities
โ โ โโโ usePWA.ts # PWA features
โ โโโ ๐ utils/ # Utility functions
โ โ โโโ bluetooth.ts # Bluetooth helpers
โ โ โโโ encryption.ts # Crypto functions
โ โ โโโ storage.ts # Local storage helpers
โ โโโ ๐ types/ # TypeScript definitions
โ โ โโโ bluetooth.d.ts # Bluetooth types
โ โ โโโ message.d.ts # Message types
โ โโโ ๐ styles/ # Stylesheets
โ โ โโโ global.css # Global styles
โ โโโ App.tsx # Main application
โ โโโ main.tsx # Entry point
โโโ ๐ cert/ # SSL certificates (development)
โ โโโ key.pem # Private key
โ โโโ cert.pem # Certificate
โโโ vite.config.ts # Vite configuration
โโโ tsconfig.json # TypeScript config
โโโ tailwind.config.js # Tailwind config
โโโ package.json # Dependencies
โโโ README.md # Documentation
| Requirement | Version | Purpose |
|---|---|---|
| Node.js | 18.0+ | Runtime environment |
| npm/yarn | Latest | Package management |
| OpenSSL | 1.1.1+ | SSL certificate generation |
| Chrome/Edge | Latest | Web Bluetooth support |
# Clone the repository
git clone https://github.com/your-username/bluetooth-chat-web.git
cd bluetooth-chat-web
# Install dependencies
npm install
# Or using yarn
yarn installWhy HTTPS is Required:
- Web Bluetooth API requires secure context (HTTPS)
- PWA features need HTTPS for service workers
- Browser security policies mandate secure connections
Generate Self-Signed Certificate:
# Generate SSL certificate and private key
openssl req -x509 -newkey rsa:2048 -nodes \
-keyout key.pem -out cert.pem -days 365 \
-subj "/C=US/ST=State/L=City/O=Organization/CN=localhost"
# Create cert directory and move files
mkdir -p cert
mv key.pem cert/
mv cert.pem cert/
# Verify certificate generation
ls -la cert/# Start development server with HTTPS
npm run dev
# Server will start at:
# https://localhost:5173Access the Application:
https://localhost:5173
Trust the Certificate:
- Chrome: Click "Advanced" โ "Proceed to localhost"
- Edge: Click "Advanced" โ "Continue to localhost"
- Firefox: Add security exception
// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { VitePWA } from 'vite-plugin-pwa';
import fs from 'fs';
export default defineConfig({
plugins: [
react(),
VitePWA({
registerType: 'autoUpdate',
includeAssets: ['favicon.ico', 'robots.txt', 'icons/*.png'],
manifest: {
name: 'Bluetooth Chat Web',
short_name: 'BT Chat',
description: 'Secure Bluetooth messaging platform',
theme_color: '#0082FC',
background_color: '#ffffff',
display: 'standalone',
orientation: 'portrait',
icons: [
{
src: '/icons/icon-192.png',
sizes: '192x192',
type: 'image/png'
},
{
src: '/icons/icon-512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable'
}
]
},
workbox: {
globPatterns: ['**/*.{js,css,html,ico,png,svg}'],
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365 // 1 year
}
}
}
]
}
})
],
server: {
https: {
key: fs.readFileSync('./cert/key.pem'),
cert: fs.readFileSync('./cert/cert.pem')
},
port: 5173,
host: true
}
});# Install Vercel CLI
npm install -g vercel
# Build production version
npm run build
# Deploy to Vercel
vercel --prod
# Custom domain configuration
vercel domains add your-domain.comVercel Configuration (vercel.json):
{
"version": 2,
"builds": [
{
"src": "package.json",
"use": "@vercel/static-build",
"config": {
"distDir": "dist"
}
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/index.html"
}
],
"headers": [
{
"source": "/(.*)",
"headers": [
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Frame-Options",
"value": "DENY"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
}
]
}
]
}# Install Netlify CLI
npm install -g netlify-cli
# Build application
npm run build
# Deploy to Netlify
netlify deploy --prod --dir=dist
# Custom domain
netlify domains:add your-domain.comNetlify Configuration (netlify.toml):
[build]
command = "npm run build"
publish = "dist"
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "DENY"
X-Content-Type-Options = "nosniff"
X-XSS-Protection = "1; mode=block"
Referrer-Policy = "strict-origin-when-cross-origin"# Install gh-pages
npm install --save-dev gh-pages
# Add to package.json scripts
"predeploy": "npm run build",
"deploy": "gh-pages -d dist"
# Deploy
npm run deploy- โ HTTPS enabled with valid SSL certificate
- โ Security headers configured
- โ Content Security Policy implemented
- โ CORS properly configured
- โ Environment variables secured
- โ API keys not exposed in client code
|
Open Chrome or Edge on Android device |
Navigate to the HTTPS URL |
Tap the install icon in browser menu
|
Browser Menu Method:
- Open site in Chrome/Edge
- Tap the three-dot menu (โฎ) in top-right corner
- Select "Add to Home Screen" or "Install App"
- Confirm installation
- App icon appears on home screen
Automatic Prompt Method:
- Visit the site on HTTPS
- Wait for install banner to appear
- Tap "Install" button
- App installs automatically
Limited Support on iOS:
- Web Bluetooth API not fully supported on iOS Safari
- PWA installation works, but Bluetooth features limited
- Recommend Android devices for full functionality
iOS Installation (PWA Only):
- Open Safari browser
- Tap share button (โกโ)
- Select "Add to Home Screen"
- Confirm and install
# Run development server
npm run dev
# Run with custom port
npm run dev -- --port 3000
# Build for production testing
npm run build
npm run preview
# Run tests
npm run test
# Type checking
npm run type-check
# Lint code
npm run lintTesting on Android:
# Get your local IP address
# Linux/Mac:
ifconfig | grep "inet "
# Windows:
ipconfig
# Access from mobile using:
https://YOUR-IP-ADDRESS:5173Testing Checklist:
- โ Bluetooth device discovery works
- โ Messages send and receive correctly
- โ Encryption toggles properly
- โ PWA installs successfully
- โ Offline functionality works
- โ UI is responsive on mobile
# Issue: Bluetooth devices not found
# Solution: Check browser compatibility
navigator.bluetooth.getAvailability()
.then(isAvailable => {
console.log('Bluetooth available:', isAvailable);
});
# Ensure HTTPS is enabled
# Verify permissions are granted# Issue: Certificate errors in development
# Solution: Trust the self-signed certificate
# Chrome: Navigate to chrome://flags/#allow-insecure-localhost
# Enable "Allow invalid certificates for resources loaded from localhost"
# Or regenerate certificate with proper CN:
openssl req -x509 -newkey rsa:2048 -nodes \
-keyout key.pem -out cert.pem -days 365 \
-subj "/CN=localhost"// Check PWA compatibility
if ('serviceWorker' in navigator) {
console.log('Service Worker supported');
}
// Debug manifest issues
// Check: https://your-site.com/manifest.json
// Validate with: https://manifest-validator.appspot.com/// Code splitting for better performance
import { lazy, Suspense } from 'react';
const ChatInterface = lazy(() => import('./components/ChatInterface'));
const BluetoothScanner = lazy(() => import('./components/BluetoothScanner'));
function App() {
return (
<Suspense fallback={<Loading />}>
<ChatInterface />
<BluetoothScanner />
</Suspense>
);
}- ๐ฅ Video/Voice Calls: Bluetooth audio streaming
- ๐ File Transfer: Enhanced file sharing capabilities
- ๐ฅ Group Chat: Multi-device Bluetooth mesh networking
- ๐ Multi-Language: Internationalization support
- ๐จ Themes: Customizable UI themes
- ๐ Analytics: Usage statistics and insights
Built with โค๏ธ using React, Vite, Web Bluetooth API, and Modern Web Standards
๐ Star this repo if you love wireless communication! ๐ Report issues ๐ก Suggest features
Made with React + Vite + Web Bluetooth
