peerpigeon
Version:
WebRTC-based peer-to-peer mesh networking library with intelligent routing and signaling server
94 lines (70 loc) • 2.75 kB
Markdown
# WebSocket Server Migration - Complete ✅
## Summary
Successfully migrated from the legacy `websocket-server/` directory to the new `server/` module with the enhanced `PeerPigeonServer` class.
## What Changed
### ✅ Removed
- **`websocket-server/server.js`** - Legacy standalone server (448 lines)
- **`websocket-server/`** directory
### ✅ New Files
- **`server/start.js`** - New standalone server script that uses `PeerPigeonServer`
### ✅ Updated Files
1. **`package.json`**
- Changed `npm start` and `npm run server` to use `server/start.js`
- Updated lint scripts to check `server/` instead of `websocket-server/`
- Removed `websocket-server/` from published files
2. **Test Files**
- `test/browser-integration-test.js`
- `test/manual-video-test.js`
- `test/manual-video-streaming-test.js`
- `test/video-streaming-test.js`
- All now spawn `server/start.js` instead of `websocket-server/server.js`
3. **Development Files**
- `dev-runner.js` - Now uses `server/start.js`
4. **Documentation**
- `examples/browser/minimal/README.md` - Updated server start command
- `SELECTIVE_STREAMING_GUIDE.md` - Updated to use `npm run server`
## Benefits of New Server
The new `server/index.js` (`PeerPigeonServer` class) provides:
1. **Hub Support** - Can act as a hub with mesh networking capabilities
2. **Network Namespaces** - Isolate peers into different networks
3. **Bootstrap Connections** - Hubs can connect to other hubs
4. **Better API** - Event-driven architecture with EventEmitter
5. **Programmatic Usage** - Can be imported and used as a module
6. **Auto Port Selection** - Automatically tries next port if one is in use
7. **Better Cleanup** - More robust connection management
8. **Statistics API** - `getStats()` and `getHubStats()` methods
## Migration Commands
### Old Way
```bash
node websocket-server/server.js
```
### New Way
```bash
npm run server
# or
node server/start.js
# or programmatically
import { PeerPigeonServer } from './server/index.js';
const server = new PeerPigeonServer({ port: 3000 });
await server.start();
```
## Environment Variables
The new server supports:
- `PORT` - Server port (default: 3000)
- `HOST` - Server host (default: localhost)
- `MAX_CONNECTIONS` - Max connections (default: 1000)
- `CORS_ORIGIN` - CORS origin (default: *)
## Testing
Server was tested and verified working:
```bash
✅ Server starts successfully
✅ Health endpoint responds: /health
✅ Backwards compatible with all existing tests
```
## Next Steps
1. ✅ All npm scripts updated
2. ✅ All tests migrated
3. ✅ Documentation updated
4. ✅ Old code removed
5. 🎉 Migration complete!
The codebase is now cleaner with a single, more powerful server implementation.