peerpigeon 0.1.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +141 -1365
  2. package/cli.js +1382 -0
  3. package/dist/peerpigeon-browser.js +12290 -0
  4. package/dist/peerpigeon-browser.js.map +7 -0
  5. package/docs/API_DOCUMENTATION.md +1945 -0
  6. package/docs/BOOTSTRAP_HUBS.md +319 -0
  7. package/docs/CLI_README.md +371 -0
  8. package/docs/DOCUMENTATION_REORGANIZATION.md +172 -0
  9. package/docs/HUB_QUICK_REF.md +107 -0
  10. package/docs/HUB_SCRIPTS.md +331 -0
  11. package/docs/HUB_SYSTEM.md +552 -0
  12. package/docs/MIGRATION_COMPLETE.md +93 -0
  13. package/docs/NETWORK_NAMESPACES.md +212 -0
  14. package/docs/README.md +107 -0
  15. package/docs/SELECTIVE_STREAMING_GUIDE.md +427 -0
  16. package/docs/TEST_CLEANUP_COMPLETE.md +80 -0
  17. package/examples/bootstrap-hub-example.js +292 -0
  18. package/examples/browser/README.md +278 -0
  19. package/examples/browser/app.js +2426 -49
  20. package/examples/browser/index.html +481 -630
  21. package/examples/browser/minimal/README.md +55 -0
  22. package/examples/browser/minimal/index.html +75 -0
  23. package/examples/browser/minimal/minimal.js +234 -0
  24. package/examples/browser/styles.css +687 -1425
  25. package/examples/browser/test-bundle.html +35 -0
  26. package/examples/browser-2/index.html +30 -0
  27. package/examples/browser-2/package.json +21 -0
  28. package/examples/browser-2/src/App-simple.vue +21 -0
  29. package/examples/browser-2/src/App.vue +420 -0
  30. package/examples/browser-2/src/components/CryptoView.vue +1661 -0
  31. package/examples/browser-2/src/components/DHTView.vue +1281 -0
  32. package/examples/browser-2/src/components/DebugView.vue +1773 -0
  33. package/examples/browser-2/src/components/MediaView.vue +1048 -0
  34. package/examples/browser-2/src/components/MessagingView.vue +775 -0
  35. package/examples/browser-2/src/components/NetworkView.vue +930 -0
  36. package/examples/browser-2/src/components/StorageView.vue +1376 -0
  37. package/examples/browser-2/src/main.js +5 -0
  38. package/examples/browser-2/src/stores/peerpigeon.js +895 -0
  39. package/examples/browser-2/vite.config.js +6 -0
  40. package/examples/hub-example.js +186 -0
  41. package/examples/multi-hub-test.js +186 -0
  42. package/examples/node/README.md +2 -2
  43. package/examples/selective-streaming-demo.html +698 -0
  44. package/examples/standard-events-demo.js +126 -0
  45. package/package.json +33 -16
  46. package/server/index.js +1032 -98
  47. package/server/start.js +49 -0
  48. package/src/ConnectionManager.js +239 -225
  49. package/src/CryptoManager.js +147 -18
  50. package/src/DebugLogger.js +0 -7
  51. package/src/DistributedStorageManager.js +224 -205
  52. package/src/EnvironmentDetector.js +109 -2
  53. package/src/EventEmitter.js +79 -1
  54. package/src/EvictionManager.js +10 -9
  55. package/src/GossipManager.js +163 -11
  56. package/src/PeerConnection.js +333 -310
  57. package/src/PeerPigeonMesh.js +577 -135
  58. package/src/SignalingClient.js +14 -243
  59. package/src/SignalingHandler.js +31 -10
  60. package/src/StorageManager.js +0 -39
  61. package/src/WebDHT-Simple.js +389 -0
  62. package/src/WebDHT.js +363 -1165
  63. package/src/browser-entry.js +40 -0
  64. package/examples/browser/assets/images/favicon.png +0 -0
  65. package/examples/browser/assets/images/pigeon.png +0 -0
  66. package/examples/browser/crypto-test.html +0 -427
  67. package/examples/browser/ui-old.js +0 -1926
  68. package/examples/browser/ui.js +0 -3391
  69. package/websocket-server/README.md +0 -247
  70. package/websocket-server/server.js +0 -391
@@ -0,0 +1,292 @@
1
+ /**
2
+ * Bootstrap Hub Example
3
+ *
4
+ * This example demonstrates how to set up a network of hubs using bootstrap connections.
5
+ * Hubs automatically connect to each other through the bootstrap hub(s) on port 3000.
6
+ */
7
+
8
+ import { PeerPigeonServer } from '../server/index.js';
9
+
10
+ // Example 1: Create the primary bootstrap hub on port 3000
11
+ async function createBootstrapHub() {
12
+ console.log('=== Creating Bootstrap Hub (Port 3000) ===\n');
13
+
14
+ const bootstrapHub = new PeerPigeonServer({
15
+ port: 3000,
16
+ host: 'localhost',
17
+ isHub: true,
18
+ // No bootstrap hubs to connect to - this is the primary hub
19
+ autoConnect: false
20
+ });
21
+
22
+ bootstrapHub.on('hubRegistered', ({ peerId, totalHubs }) => {
23
+ console.log(`[Bootstrap] Hub registered: ${peerId.substring(0, 8)}... (Total: ${totalHubs})`);
24
+ });
25
+
26
+ bootstrapHub.on('peerConnected', ({ peerId }) => {
27
+ console.log(`[Bootstrap] Peer connected: ${peerId.substring(0, 8)}...`);
28
+ });
29
+
30
+ await bootstrapHub.start();
31
+ console.log('[Bootstrap] Hub ready and waiting for connections\n');
32
+ return bootstrapHub;
33
+ }
34
+
35
+ // Example 2: Create a hub that connects to the bootstrap hub (default port 3000)
36
+ async function createSecondaryHub(port) {
37
+ console.log(`\n=== Creating Secondary Hub (Port ${port}) ===\n`);
38
+
39
+ const hub = new PeerPigeonServer({
40
+ port,
41
+ host: 'localhost',
42
+ isHub: true,
43
+ // Automatically connects to port 3000 if not specified
44
+ autoConnect: true
45
+ });
46
+
47
+ hub.on('bootstrapConnected', ({ uri }) => {
48
+ console.log(`[Hub ${port}] ✅ Connected to bootstrap hub: ${uri}`);
49
+ });
50
+
51
+ hub.on('bootstrapDisconnected', ({ uri, code, reason }) => {
52
+ console.log(`[Hub ${port}] 🔌 Disconnected from ${uri}: ${code} - ${reason}`);
53
+ });
54
+
55
+ hub.on('hubDiscovered', ({ peerId, via }) => {
56
+ console.log(`[Hub ${port}] 🏢 Discovered hub ${peerId.substring(0, 8)}... via ${via}`);
57
+ });
58
+
59
+ hub.on('hubRegistered', ({ peerId, totalHubs }) => {
60
+ console.log(`[Hub ${port}] Hub registered: ${peerId.substring(0, 8)}... (Total: ${totalHubs})`);
61
+ });
62
+
63
+ await hub.start();
64
+ return hub;
65
+ }
66
+
67
+ // Example 3: Create a hub with custom bootstrap URIs
68
+ async function createHubWithCustomBootstrap(port, bootstrapUris) {
69
+ console.log(`\n=== Creating Hub with Custom Bootstrap (Port ${port}) ===\n`);
70
+
71
+ const hub = new PeerPigeonServer({
72
+ port,
73
+ host: 'localhost',
74
+ isHub: true,
75
+ bootstrapHubs: bootstrapUris, // Custom bootstrap hub URIs
76
+ autoConnect: true,
77
+ reconnectInterval: 3000, // Reconnect after 3 seconds
78
+ maxReconnectAttempts: 5 // Try up to 5 times
79
+ });
80
+
81
+ hub.on('bootstrapConnected', ({ uri }) => {
82
+ console.log(`[Hub ${port}] ✅ Connected to bootstrap hub: ${uri}`);
83
+ });
84
+
85
+ hub.on('bootstrapDisconnected', ({ uri }) => {
86
+ console.log(`[Hub ${port}] 🔌 Lost connection to ${uri}, will retry...`);
87
+ });
88
+
89
+ hub.on('hubDiscovered', ({ peerId }) => {
90
+ console.log(`[Hub ${port}] 🏢 Discovered another hub: ${peerId.substring(0, 8)}...`);
91
+ });
92
+
93
+ await hub.start();
94
+ return hub;
95
+ }
96
+
97
+ // Example 4: Display hub statistics with bootstrap info
98
+ async function displayBootstrapStats(server, name) {
99
+ const stats = server.getStats();
100
+ const hubStats = server.getHubStats();
101
+
102
+ console.log(`\n📊 Statistics for ${name}:`);
103
+ console.log(` Port: ${stats.port}`);
104
+ console.log(` Hub Peer ID: ${stats.hubPeerId?.substring(0, 8)}...`);
105
+ console.log(` Total Connections: ${stats.connections}`);
106
+ console.log(` Registered Hubs: ${stats.hubs}`);
107
+ console.log(` Bootstrap Connections: ${stats.bootstrapHubs.connected}/${stats.bootstrapHubs.total}`);
108
+
109
+ if (hubStats.bootstrapHubs.length > 0) {
110
+ console.log(` Bootstrap Hubs:`);
111
+ hubStats.bootstrapHubs.forEach(hub => {
112
+ const status = hub.connected ? '✅' : '❌';
113
+ console.log(` ${status} ${hub.uri} (attempts: ${hub.attemptNumber})`);
114
+ });
115
+ }
116
+ }
117
+
118
+ // Example 5: Create a multi-hub network
119
+ async function createHubNetwork() {
120
+ console.log('=== Creating Hub Network ===\n');
121
+
122
+ // Start bootstrap hub on port 3000
123
+ const bootstrap = await createBootstrapHub();
124
+
125
+ // Wait a moment for bootstrap to be ready
126
+ await new Promise(resolve => setTimeout(resolve, 1000));
127
+
128
+ // Start secondary hubs that auto-connect to port 3000
129
+ const hub1 = await createSecondaryHub(3001);
130
+ const hub2 = await createSecondaryHub(3002);
131
+ const hub3 = await createSecondaryHub(3003);
132
+
133
+ // Wait for connections to establish
134
+ await new Promise(resolve => setTimeout(resolve, 2000));
135
+
136
+ // Display statistics
137
+ await displayBootstrapStats(bootstrap, 'Bootstrap Hub (3000)');
138
+ await displayBootstrapStats(hub1, 'Hub 1 (3001)');
139
+ await displayBootstrapStats(hub2, 'Hub 2 (3002)');
140
+ await displayBootstrapStats(hub3, 'Hub 3 (3003)');
141
+
142
+ console.log('\n=== Hub Network Topology ===');
143
+ console.log('Bootstrap Hub (3000)');
144
+ console.log(' ↑');
145
+ console.log(' ├── Hub 1 (3001)');
146
+ console.log(' ├── Hub 2 (3002)');
147
+ console.log(' └── Hub 3 (3003)');
148
+
149
+ return { bootstrap, hub1, hub2, hub3 };
150
+ }
151
+
152
+ // Example 6: Multiple bootstrap hubs for redundancy
153
+ async function createRedundantHubNetwork() {
154
+ console.log('\n\n=== Creating Redundant Hub Network ===\n');
155
+
156
+ // Create two bootstrap hubs
157
+ const bootstrap1 = new PeerPigeonServer({
158
+ port: 3000,
159
+ host: 'localhost',
160
+ isHub: true,
161
+ autoConnect: false
162
+ });
163
+ await bootstrap1.start();
164
+
165
+ const bootstrap2 = new PeerPigeonServer({
166
+ port: 3001,
167
+ host: 'localhost',
168
+ isHub: true,
169
+ autoConnect: false
170
+ });
171
+ await bootstrap2.start();
172
+
173
+ console.log('Bootstrap hubs started\n');
174
+
175
+ // Create a hub that connects to BOTH bootstrap hubs
176
+ const redundantHub = await createHubWithCustomBootstrap(3005, [
177
+ 'ws://localhost:3000',
178
+ 'ws://localhost:3001'
179
+ ]);
180
+
181
+ await new Promise(resolve => setTimeout(resolve, 2000));
182
+
183
+ await displayBootstrapStats(redundantHub, 'Redundant Hub (3005)');
184
+
185
+ console.log('\n=== Redundant Topology ===');
186
+ console.log('Bootstrap Hub 1 (3000) ←→ Redundant Hub (3005)');
187
+ console.log('Bootstrap Hub 2 (3001) ←→ Redundant Hub (3005)');
188
+
189
+ return { bootstrap1, bootstrap2, redundantHub };
190
+ }
191
+
192
+ // Main execution
193
+ async function main() {
194
+ console.log('╔════════════════════════════════════════════╗');
195
+ console.log('║ PeerPigeon Bootstrap Hub Example ║');
196
+ console.log('╚════════════════════════════════════════════╝\n');
197
+
198
+ try {
199
+ // Create hub network
200
+ const network = await createHubNetwork();
201
+
202
+ // Wait to observe the network
203
+ console.log('\n\nNetwork running... (press Ctrl+C to stop)');
204
+
205
+ // Optional: Create redundant network after a delay
206
+ setTimeout(async () => {
207
+ try {
208
+ await createRedundantHubNetwork();
209
+ } catch (error) {
210
+ console.error('Error creating redundant network:', error);
211
+ }
212
+ }, 5000);
213
+
214
+ // Keep running until interrupted
215
+ process.on('SIGINT', async () => {
216
+ console.log('\n\n🛑 Shutting down hub network...');
217
+
218
+ await network.bootstrap.stop();
219
+ await network.hub1.stop();
220
+ await network.hub2.stop();
221
+ await network.hub3.stop();
222
+
223
+ console.log('✅ All hubs stopped');
224
+ process.exit(0);
225
+ });
226
+
227
+ } catch (error) {
228
+ console.error('❌ Error:', error);
229
+ process.exit(1);
230
+ }
231
+ }
232
+
233
+ // Configuration examples
234
+ function printConfigurationExamples() {
235
+ console.log('\n\n=== Configuration Examples ===\n');
236
+
237
+ console.log('1. Bootstrap Hub (Primary):');
238
+ console.log(`
239
+ const bootstrap = new PeerPigeonServer({
240
+ port: 3000,
241
+ isHub: true,
242
+ autoConnect: false // Don't connect to other hubs
243
+ });
244
+ `);
245
+
246
+ console.log('2. Secondary Hub (Auto-connect to port 3000):');
247
+ console.log(`
248
+ const hub = new PeerPigeonServer({
249
+ port: 3001,
250
+ isHub: true,
251
+ autoConnect: true // Automatically connects to ws://localhost:3000
252
+ });
253
+ `);
254
+
255
+ console.log('3. Hub with Custom Bootstrap URIs:');
256
+ console.log(`
257
+ const hub = new PeerPigeonServer({
258
+ port: 3002,
259
+ isHub: true,
260
+ bootstrapHubs: [
261
+ 'ws://hub1.example.com:3000',
262
+ 'ws://hub2.example.com:3000'
263
+ ],
264
+ reconnectInterval: 5000,
265
+ maxReconnectAttempts: 10
266
+ });
267
+ `);
268
+
269
+ console.log('4. Hub with Custom Peer ID:');
270
+ console.log(`
271
+ const hub = new PeerPigeonServer({
272
+ port: 3003,
273
+ isHub: true,
274
+ hubPeerId: 'a1b2c3d4e5f6789012345678901234567890abcd'
275
+ });
276
+ `);
277
+ }
278
+
279
+ // Run if this is the main module
280
+ if (import.meta.url === `file://${process.argv[1]}`) {
281
+ main().catch(console.error);
282
+ }
283
+
284
+ export {
285
+ createBootstrapHub,
286
+ createSecondaryHub,
287
+ createHubWithCustomBootstrap,
288
+ displayBootstrapStats,
289
+ createHubNetwork,
290
+ createRedundantHubNetwork,
291
+ printConfigurationExamples
292
+ };
@@ -0,0 +1,278 @@
1
+ # PeerPigeon Browser-3 Example - Complete API Testing Suite
2
+
3
+ This is a comprehensive browser-based testing interface for all PeerPigeon features. It provides a complete testing environment with tabbed interface for testing every aspect of the PeerPigeon mesh networking library.
4
+
5
+ ## Features Tested
6
+
7
+ ### 🌐 Connection Management
8
+ - **Signaling Server Connection**: Connect/disconnect from WebSocket signaling servers
9
+ - **Mesh Configuration**: Configure max/min peers, auto-discovery, eviction strategy, XOR routing
10
+ - **Peer Management**: View connected peers, manually connect to specific peers, force connection attempts
11
+ - **Cleanup Operations**: Clean stale signaling data and connection management
12
+
13
+ ### 💬 Messaging & Communication
14
+ - **Broadcast Messages**: Send messages to all peers in the mesh network
15
+ - **Direct Messages**: Send targeted messages to specific peers
16
+ - **Message History**: Complete log of sent and received messages with timestamps
17
+ - **Message Types**: Support for text, JSON objects, and encrypted content
18
+
19
+ ### 🎥 Media Management
20
+ - **Local Media Streams**: Start/stop camera and microphone
21
+ - **Device Selection**: Choose specific cameras and microphones
22
+ - **Media Controls**: Toggle video/audio on/off during active streams
23
+ - **Remote Streams**: Display incoming video/audio from connected peers
24
+ - **Device Enumeration**: Refresh and list available media devices
25
+
26
+ ### 🗄️ Distributed Hash Table (DHT)
27
+ - **Data Storage**: Store key-value pairs across the distributed network
28
+ - **Data Retrieval**: Get stored values by key
29
+ - **Data Updates**: Update existing values with merge options
30
+ - **Data Deletion**: Remove keys from the distributed storage
31
+ - **Subscriptions**: Subscribe to key changes and receive notifications
32
+ - **Storage Spaces**: Use different storage spaces (private, public, frozen)
33
+ - **TTL Support**: Set time-to-live for stored data
34
+
35
+ ### 🔐 Encryption & Security
36
+ - **Encrypted Messaging**: Send encrypted broadcasts with optional group IDs
37
+ - **Key Exchange**: Automated key exchange between peers
38
+ - **Manual Key Management**: Manually add peer public keys
39
+ - **Crypto Status**: Monitor encryption system status and key exchanges
40
+ - **Group Encryption**: Support for group-based encryption keys
41
+
42
+ ### 📊 Network Information & Monitoring
43
+ - **Network Status**: Real-time connection status, peer counts, uptime
44
+ - **Peer State Summary**: Detailed view of all peer connection states
45
+ - **Connection Monitoring**: Start/stop connection health monitoring
46
+ - **Connectivity Debugging**: Debug connectivity issues
47
+ - **Discovered Peers**: List of all discovered peers in the network
48
+
49
+ ### 🧪 API Testing & Utilities
50
+ - **Utility Functions**: Validate peer IDs, force connections, cleanup operations
51
+ - **Performance Testing**: Test message throughput and system performance
52
+ - **Stress Testing**: High-load testing with rapid operations
53
+ - **Error Testing**: Test system behavior with invalid inputs
54
+ - **Log Export**: Export all logs and test results as JSON
55
+ - **Test Results**: Comprehensive logging of all test operations
56
+
57
+ ## Usage
58
+
59
+ ### Prerequisites
60
+ 1. Start the PeerPigeon development environment:
61
+ ```bash
62
+ npm run dev
63
+ ```
64
+ This starts both the signaling server (ws://localhost:3000) and HTTP server (http://localhost:8080)
65
+
66
+ 2. Open multiple browser windows/tabs to simulate multiple peers
67
+
68
+ ### Getting Started
69
+
70
+ 1. **Open the Testing Suite**
71
+ - Navigate to `http://localhost:8080/examples/browser-3/`
72
+ - The interface will automatically initialize PeerPigeon with all features enabled
73
+
74
+ 2. **Connect to Signaling Server**
75
+ - Default URL: `ws://localhost:3000`
76
+ - Click "Connect" button
77
+ - Status will update to show connection state
78
+
79
+ 3. **Test Features**
80
+ - Use the tabbed interface to explore different feature categories
81
+ - Each tab contains comprehensive testing tools for that feature set
82
+ - System log at the bottom shows all activity
83
+
84
+ ### Testing Workflows
85
+
86
+ #### Basic Connectivity Test
87
+ 1. Open 2+ browser windows with the testing suite
88
+ 2. Connect all instances to the signaling server
89
+ 3. Verify peers appear in the "Connected Peers" list
90
+ 4. Test broadcast and direct messaging
91
+
92
+ #### Media Streaming Test
93
+ 1. Grant camera/microphone permissions
94
+ 2. Select desired devices in Media tab
95
+ 3. Enable video/audio and start media
96
+ 4. Verify local video preview appears
97
+ 5. Check remote streams from other connected peers
98
+
99
+ #### DHT Storage Test
100
+ 1. Store data using the DHT interface
101
+ 2. Retrieve data from other peer instances
102
+ 3. Test subscriptions by updating values
103
+ 4. Verify real-time notifications work
104
+
105
+ #### Encryption Test
106
+ 1. Send encrypted broadcasts
107
+ 2. Verify automatic key exchange occurs
108
+ 3. Test manual key management
109
+ 4. Confirm encrypted messages are received and decrypted
110
+
111
+ #### Performance Testing
112
+ 1. Use the API Testing tab
113
+ 2. Configure message count and size
114
+ 3. Run performance tests
115
+ 4. Monitor results and system performance
116
+
117
+ ## File Structure
118
+
119
+ ```
120
+ examples/browser-3/
121
+ ├── index.html # Main HTML interface with tabbed layout
122
+ ├── styles.css # Comprehensive CSS styling
123
+ ├── app.js # Complete JavaScript application
124
+ └── README.md # This documentation file
125
+ ```
126
+
127
+ ## API Coverage
128
+
129
+ This testing suite exercises the complete PeerPigeon API:
130
+
131
+ ### Core PeerPigeonMesh Methods
132
+ - `new PeerPigeonMesh(options)` - Initialization with all options
133
+ - `init()` - System initialization
134
+ - `connect(url)` - Signaling server connection
135
+ - `disconnect()` - Clean disconnection
136
+ - `getStatus()` - Network status information
137
+ - `getPeers()` - Connected peer information
138
+ - `getConnectedPeerIds()` - Peer ID lists
139
+ - `getDiscoveredPeers()` - Discovery information
140
+
141
+ ### Configuration Methods
142
+ - `setMaxPeers(n)` - Maximum peer limit
143
+ - `setMinPeers(n)` - Minimum peer requirement
144
+ - `setAutoDiscovery(enabled)` - Auto-discovery toggle
145
+ - `setEvictionStrategy(enabled)` - Eviction strategy toggle
146
+ - `setXorRouting(enabled)` - XOR routing toggle
147
+
148
+ ### Messaging Methods
149
+ - `sendMessage(content)` - Broadcast messages
150
+ - `sendDirectMessage(peerId, content)` - Direct messages
151
+ - `sendEncryptedBroadcast(content, groupId)` - Encrypted broadcasts
152
+
153
+ ### Media Methods
154
+ - `initializeMedia()` - Media system initialization
155
+ - `startMedia(options)` - Start local media streams
156
+ - `stopMedia()` - Stop media streams
157
+ - `toggleVideo()` - Video track control
158
+ - `toggleAudio()` - Audio track control
159
+ - `enumerateMediaDevices()` - Device enumeration
160
+ - `getMediaState()` - Media status information
161
+ - `getLocalStream()` - Local stream access
162
+ - `getRemoteStreams()` - Remote stream access
163
+
164
+ ### DHT Methods
165
+ - `dhtPut(key, value, options)` - Store data
166
+ - `dhtGet(key, options)` - Retrieve data
167
+ - `dhtUpdate(key, value, options)` - Update data
168
+ - `dhtDelete(key)` - Delete data
169
+ - `dhtSubscribe(key)` - Subscribe to changes
170
+ - `dhtUnsubscribe(key)` - Unsubscribe from changes
171
+
172
+ ### Crypto Methods
173
+ - `exchangeKeysWithPeer(peerId)` - Key exchange
174
+ - `addPeerKey(peerId, publicKey)` - Manual key management
175
+ - `getPublicKey()` - Public key access
176
+
177
+ ### Utility Methods
178
+ - `cleanupStaleSignalingData()` - Cleanup operations
179
+ - `forceConnectToAllPeers()` - Force connections
180
+ - `debugConnectivity()` - Debug information
181
+ - `getPeerStateSummary()` - Peer state information
182
+ - `startConnectionMonitoring()` - Connection monitoring
183
+ - `stopConnectionMonitoring()` - Stop monitoring
184
+ - `canAcceptMorePeers()` - Connection capacity
185
+ - `hasPeer(peerId)` - Peer existence check
186
+ - `validatePeerId(peerId)` - Peer ID validation
187
+
188
+ ### Event Listeners
189
+ All PeerPigeon events are monitored and logged:
190
+ - `statusChanged` - Connection status changes
191
+ - `peerConnected` - New peer connections
192
+ - `peerDisconnected` - Peer disconnections
193
+ - `peerDiscovered` - Peer discovery
194
+ - `messageReceived` - Incoming messages
195
+ - `dhtValueChanged` - DHT value changes
196
+ - `localStreamStarted` - Local media started
197
+ - `localStreamStopped` - Local media stopped
198
+ - `remoteStream` - Remote media streams
199
+ - `mediaError` - Media errors
200
+ - `cryptoReady` - Encryption ready
201
+ - `cryptoError` - Encryption errors
202
+ - `peerKeyAdded` - Key exchange completion
203
+ - `connectionStats` - Connection statistics
204
+
205
+ ## Features
206
+
207
+ ### User Interface
208
+ - **Tabbed Navigation**: Organized feature testing by category
209
+ - **Real-time Updates**: Live status updates and peer information
210
+ - **Comprehensive Logging**: Detailed logs for all operations
211
+ - **Responsive Design**: Works on desktop and mobile devices
212
+ - **Dark/Light Theme**: Professional styling with clear visual hierarchy
213
+
214
+ ### Error Handling
215
+ - **Graceful Degradation**: Handles API errors without breaking interface
216
+ - **Validation**: Input validation for all user inputs
217
+ - **Error Reporting**: Clear error messages with context
218
+ - **Recovery Options**: Ways to recover from error states
219
+
220
+ ### Performance Monitoring
221
+ - **Message Metrics**: Track sent/received message counts
222
+ - **Connection Stats**: Monitor bandwidth and connection quality
223
+ - **System Performance**: Test system limits and performance
224
+ - **Export Functionality**: Export all logs and metrics
225
+
226
+ ## Troubleshooting
227
+
228
+ ### Common Issues
229
+
230
+ 1. **Connection Failed**
231
+ - Verify signaling server is running (`npm run dev`)
232
+ - Check WebSocket URL format
233
+ - Ensure firewall/proxy allows WebSocket connections
234
+
235
+ 2. **Media Not Working**
236
+ - Grant camera/microphone permissions
237
+ - Check device availability in browser settings
238
+ - Try different cameras/microphones
239
+
240
+ 3. **DHT Operations Failing**
241
+ - Ensure peers are connected
242
+ - Check data size limits
243
+ - Verify JSON format for values
244
+
245
+ 4. **No Remote Streams**
246
+ - Verify both peers have started media
247
+ - Check WebRTC connectivity
248
+ - Look for firewall/NAT issues
249
+
250
+ ### Debug Information
251
+
252
+ Use the following features for debugging:
253
+ 1. **System Log**: Monitor all system activity
254
+ 2. **Network Info Tab**: Check connection status and peer states
255
+ 3. **Debug Connectivity**: Get detailed connectivity information
256
+ 4. **Export Logs**: Save logs for analysis
257
+
258
+ ## Development
259
+
260
+ To modify or extend this testing suite:
261
+
262
+ 1. **Add New Tests**: Extend the testing controls in `setupTestingControls()`
263
+ 2. **Add New Features**: Create new tabs and corresponding functionality
264
+ 3. **Modify UI**: Update `styles.css` for visual changes
265
+ 4. **Add Event Handling**: Extend `setupEventListeners()` for new events
266
+
267
+ ## Contributing
268
+
269
+ This testing suite serves as both a comprehensive API test and a reference implementation. When adding new PeerPigeon features, update this testing suite to include:
270
+
271
+ 1. New API method tests
272
+ 2. New event listener coverage
273
+ 3. New configuration options
274
+ 4. Updated documentation
275
+
276
+ ## License
277
+
278
+ This example is part of the PeerPigeon project and follows the same license terms.