peerpigeon 0.1.0 → 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.
- package/README.md +141 -1365
- package/cli.js +1382 -0
- package/dist/peerpigeon-browser.js +12290 -0
- package/dist/peerpigeon-browser.js.map +7 -0
- package/docs/API_DOCUMENTATION.md +1945 -0
- package/docs/BOOTSTRAP_HUBS.md +319 -0
- package/docs/CLI_README.md +371 -0
- package/docs/DOCUMENTATION_REORGANIZATION.md +172 -0
- package/docs/HUB_QUICK_REF.md +107 -0
- package/docs/HUB_SCRIPTS.md +331 -0
- package/docs/HUB_SYSTEM.md +552 -0
- package/docs/MIGRATION_COMPLETE.md +93 -0
- package/docs/NETWORK_NAMESPACES.md +212 -0
- package/docs/README.md +107 -0
- package/docs/SELECTIVE_STREAMING_GUIDE.md +427 -0
- package/docs/TEST_CLEANUP_COMPLETE.md +80 -0
- package/examples/bootstrap-hub-example.js +292 -0
- package/examples/browser/README.md +278 -0
- package/examples/browser/app.js +2426 -49
- package/examples/browser/index.html +482 -543
- package/examples/browser/minimal/README.md +55 -0
- package/examples/browser/minimal/index.html +75 -0
- package/examples/browser/minimal/minimal.js +234 -0
- package/examples/browser/styles.css +687 -1425
- package/examples/browser/test-bundle.html +35 -0
- package/examples/browser-2/index.html +30 -0
- package/examples/browser-2/package.json +21 -0
- package/examples/browser-2/src/App-simple.vue +21 -0
- package/examples/browser-2/src/App.vue +420 -0
- package/examples/browser-2/src/components/CryptoView.vue +1661 -0
- package/examples/browser-2/src/components/DHTView.vue +1281 -0
- package/examples/browser-2/src/components/DebugView.vue +1773 -0
- package/examples/browser-2/src/components/MediaView.vue +1048 -0
- package/examples/browser-2/src/components/MessagingView.vue +775 -0
- package/examples/browser-2/src/components/NetworkView.vue +930 -0
- package/examples/browser-2/src/components/StorageView.vue +1376 -0
- package/examples/browser-2/src/main.js +5 -0
- package/examples/browser-2/src/stores/peerpigeon.js +895 -0
- package/examples/browser-2/vite.config.js +6 -0
- package/examples/hub-example.js +186 -0
- package/examples/multi-hub-test.js +186 -0
- package/examples/node/README.md +2 -2
- package/examples/node/storage-test.js +141 -6
- package/examples/selective-streaming-demo.html +698 -0
- package/examples/standard-events-demo.js +126 -0
- package/package.json +33 -16
- package/server/index.js +1032 -98
- package/server/start.js +49 -0
- package/src/ConnectionManager.js +239 -225
- package/src/CryptoManager.js +147 -18
- package/src/DebugLogger.js +0 -7
- package/src/DistributedStorageManager.js +245 -205
- package/src/EnvironmentDetector.js +109 -2
- package/src/EventEmitter.js +79 -1
- package/src/EvictionManager.js +10 -9
- package/src/GossipManager.js +163 -11
- package/src/LexicalStorageInterface.js +332 -0
- package/src/PeerConnection.js +333 -310
- package/src/PeerPigeonMesh.js +577 -135
- package/src/SignalingClient.js +14 -243
- package/src/SignalingHandler.js +31 -10
- package/src/StorageManager.js +0 -39
- package/src/WebDHT-Simple.js +389 -0
- package/src/WebDHT.js +363 -1165
- package/src/browser-entry.js +40 -0
- package/examples/browser/assets/images/favicon.png +0 -0
- package/examples/browser/assets/images/pigeon.png +0 -0
- package/examples/browser/crypto-test.html +0 -427
- package/examples/browser/ui-old.js +0 -1926
- package/examples/browser/ui.js +0 -3010
- package/websocket-server/README.md +0 -247
- package/websocket-server/server.js +0 -391
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# PeerPigeon Minimal Browser Test
|
|
2
|
+
|
|
3
|
+
This is a stripped-down version of PeerPigeon designed for testing browser-to-browser connections with minimal complexity.
|
|
4
|
+
|
|
5
|
+
## Features Enabled
|
|
6
|
+
- ✅ Basic peer connections
|
|
7
|
+
- ✅ Data channel establishment
|
|
8
|
+
- ✅ Encryption and key exchange
|
|
9
|
+
- ✅ Simple messaging
|
|
10
|
+
- ✅ Peer discovery
|
|
11
|
+
|
|
12
|
+
## Features Disabled
|
|
13
|
+
- ❌ WebDHT (distributed hash table)
|
|
14
|
+
- ❌ Distributed storage
|
|
15
|
+
- ❌ Media streams
|
|
16
|
+
- ❌ Complex routing
|
|
17
|
+
- ❌ Eviction strategies
|
|
18
|
+
|
|
19
|
+
## How to Test Browser-to-Browser Connections
|
|
20
|
+
|
|
21
|
+
1. **Start the signaling server:**
|
|
22
|
+
```bash
|
|
23
|
+
cd /Users/danraeder/Documents/GitHub/peerpigeon
|
|
24
|
+
node server/start.js
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
2. **Open two browser tabs:**
|
|
28
|
+
- Tab 1: Open `index.html` in this directory
|
|
29
|
+
- Tab 2: Open `index.html` in another tab (same file)
|
|
30
|
+
|
|
31
|
+
3. **Connect both instances:**
|
|
32
|
+
- Click "Connect" in both tabs
|
|
33
|
+
- Both should show "Connected to signaling"
|
|
34
|
+
- Watch for peer discovery and connection events
|
|
35
|
+
|
|
36
|
+
4. **Test messaging:**
|
|
37
|
+
- Once peers are connected, click "Send Test Message"
|
|
38
|
+
- Message should appear in both browser logs
|
|
39
|
+
|
|
40
|
+
## Debugging
|
|
41
|
+
|
|
42
|
+
- Open browser console (F12) for detailed logging
|
|
43
|
+
- Use `window.mesh()` in console to inspect mesh state
|
|
44
|
+
- Use `window.minimalPeer` to access the main instance
|
|
45
|
+
|
|
46
|
+
## Expected Behavior
|
|
47
|
+
|
|
48
|
+
If browser-to-browser connections work properly:
|
|
49
|
+
1. Both tabs connect to signaling server
|
|
50
|
+
2. Peers discover each other
|
|
51
|
+
3. WebRTC data channels establish successfully
|
|
52
|
+
4. Key exchange completes
|
|
53
|
+
5. Messages can be sent between browsers
|
|
54
|
+
|
|
55
|
+
If connections fail, the logs will show where the process breaks down.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>PeerPigeon Minimal Test</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: monospace;
|
|
10
|
+
margin: 20px;
|
|
11
|
+
background: #1a1a1a;
|
|
12
|
+
color: #00ff00;
|
|
13
|
+
}
|
|
14
|
+
.container {
|
|
15
|
+
max-width: 800px;
|
|
16
|
+
margin: 0 auto;
|
|
17
|
+
}
|
|
18
|
+
.status {
|
|
19
|
+
padding: 10px;
|
|
20
|
+
margin: 10px 0;
|
|
21
|
+
border: 1px solid #333;
|
|
22
|
+
background: #222;
|
|
23
|
+
}
|
|
24
|
+
.controls {
|
|
25
|
+
margin: 20px 0;
|
|
26
|
+
}
|
|
27
|
+
button {
|
|
28
|
+
background: #333;
|
|
29
|
+
color: #00ff00;
|
|
30
|
+
border: 1px solid #555;
|
|
31
|
+
padding: 10px 20px;
|
|
32
|
+
margin: 5px;
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
}
|
|
35
|
+
button:hover {
|
|
36
|
+
background: #444;
|
|
37
|
+
}
|
|
38
|
+
.log {
|
|
39
|
+
height: 300px;
|
|
40
|
+
overflow-y: auto;
|
|
41
|
+
background: #000;
|
|
42
|
+
padding: 10px;
|
|
43
|
+
border: 1px solid #333;
|
|
44
|
+
font-size: 12px;
|
|
45
|
+
}
|
|
46
|
+
.error { color: #ff4444; }
|
|
47
|
+
.success { color: #44ff44; }
|
|
48
|
+
.warning { color: #ffaa44; }
|
|
49
|
+
</style>
|
|
50
|
+
</head>
|
|
51
|
+
<body>
|
|
52
|
+
<div class="container">
|
|
53
|
+
<h1>PeerPigeon Minimal Browser Test</h1>
|
|
54
|
+
|
|
55
|
+
<div class="status">
|
|
56
|
+
<div><strong>Peer ID:</strong> <span id="peer-id">Generating...</span></div>
|
|
57
|
+
<div><strong>Status:</strong> <span id="status">Initializing...</span></div>
|
|
58
|
+
<div><strong>Connected Peers:</strong> <span id="peer-count">0</span></div>
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<div class="controls">
|
|
62
|
+
<button onclick="connect()">Connect to Signaling</button>
|
|
63
|
+
<button onclick="sendMessage()">Send Test Message</button>
|
|
64
|
+
<button onclick="clearLog()">Clear Log</button>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<div class="log" id="log"></div>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<!-- Load PeerPigeon bundle first -->
|
|
71
|
+
<script src="/dist/peerpigeon-browser.js"></script>
|
|
72
|
+
<!-- Then load our minimal implementation -->
|
|
73
|
+
<script type="module" src="minimal.js"></script>
|
|
74
|
+
</body>
|
|
75
|
+
</html>
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PeerPigeon MINIMAL Browser Implementation
|
|
3
|
+
* Stripped down to absolute essentials: peer connections, data channels, encryption
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Load PeerPigeon from the global bundle
|
|
7
|
+
let PeerPigeon;
|
|
8
|
+
|
|
9
|
+
// Wait for PeerPigeon to be available
|
|
10
|
+
async function waitForPeerPigeon() {
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
const checkPeerPigeon = () => {
|
|
13
|
+
if (window.PeerPigeon) {
|
|
14
|
+
PeerPigeon = window.PeerPigeon;
|
|
15
|
+
resolve();
|
|
16
|
+
} else {
|
|
17
|
+
setTimeout(checkPeerPigeon, 100);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
checkPeerPigeon();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class MinimalPeerPigeon {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.mesh = null;
|
|
27
|
+
this.connected = false;
|
|
28
|
+
this.peerCount = 0;
|
|
29
|
+
|
|
30
|
+
this.init();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async init() {
|
|
34
|
+
// Wait for PeerPigeon to be loaded
|
|
35
|
+
await waitForPeerPigeon();
|
|
36
|
+
|
|
37
|
+
this.log('🚀 Initializing minimal PeerPigeon...');
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
// Create mesh with ONLY essential features
|
|
41
|
+
this.mesh = new PeerPigeon.PeerPigeonMesh({
|
|
42
|
+
enableWebDHT: false, // DISABLED - not needed for basic connectivity
|
|
43
|
+
enableCrypto: true, // ENABLED - needed for key exchange
|
|
44
|
+
enableDistributedStorage: false, // DISABLED - not needed for basic connectivity
|
|
45
|
+
maxPeers: 2, // MINIMAL - only 2 peers max
|
|
46
|
+
minPeers: 1, // MINIMAL - only 1 peer min
|
|
47
|
+
autoDiscovery: true, // ENABLED - needed for peer discovery
|
|
48
|
+
evictionStrategy: false, // DISABLED - not needed for basic connectivity
|
|
49
|
+
xorRouting: false // DISABLED - not needed for basic connectivity
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
await this.mesh.init();
|
|
53
|
+
this.setupDetailedEventListeners();
|
|
54
|
+
|
|
55
|
+
document.getElementById('peer-id').textContent = this.mesh.peerId.substring(0, 8) + '...';
|
|
56
|
+
document.getElementById('status').textContent = 'Ready';
|
|
57
|
+
|
|
58
|
+
this.log('✅ Minimal PeerPigeon initialized');
|
|
59
|
+
this.log(`🆔 Peer ID: ${this.mesh.peerId}`);
|
|
60
|
+
|
|
61
|
+
} catch (error) {
|
|
62
|
+
this.log(`❌ Initialization failed: ${error.message}`, 'error');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
setupDetailedEventListeners() {
|
|
67
|
+
// Connection events with detailed debugging
|
|
68
|
+
this.mesh.addEventListener('peerConnected', (data) => {
|
|
69
|
+
this.peerCount++;
|
|
70
|
+
this.log(`🤝 PEER CONNECTED: ${data.peerId.substring(0, 8)}...`, 'success');
|
|
71
|
+
this.log(`🔍 Connection details: reason=${data.reason || 'unknown'}, total peers=${this.peerCount}`);
|
|
72
|
+
document.getElementById('peer-count').textContent = this.peerCount;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
this.mesh.addEventListener('peerDisconnected', (data) => {
|
|
76
|
+
this.peerCount--;
|
|
77
|
+
this.log(`👋 PEER DISCONNECTED: ${data.peerId.substring(0, 8)}... (${data.reason})`, 'warning');
|
|
78
|
+
document.getElementById('peer-count').textContent = this.peerCount;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
this.mesh.addEventListener('peerDiscovered', (data) => {
|
|
82
|
+
this.log(`🔍 PEER DISCOVERED: ${data.peerId.substring(0, 8)}...`);
|
|
83
|
+
this.log(`🔍 Discovery details: method=${data.method || 'signaling'}, timestamp=${Date.now()}`);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Message events
|
|
87
|
+
this.mesh.addEventListener('messageReceived', (data) => {
|
|
88
|
+
this.log(`📨 MESSAGE FROM ${data.fromPeerId.substring(0, 8)}...: ${JSON.stringify(data.message)}`, 'success');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Crypto events
|
|
92
|
+
this.mesh.addEventListener('cryptoReady', () => {
|
|
93
|
+
this.log('🔐 CRYPTO READY');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
this.mesh.addEventListener('peerKeyAdded', (data) => {
|
|
97
|
+
this.log(`🔐 KEY EXCHANGE COMPLETED: ${data.peerId.substring(0, 8)}...`, 'success');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Enhanced status events with detailed logging
|
|
101
|
+
this.mesh.addEventListener('statusChanged', (data) => {
|
|
102
|
+
this.log(`📊 STATUS: ${data.type} - ${data.message || 'No message'}`);
|
|
103
|
+
|
|
104
|
+
if (data.type === 'connected') {
|
|
105
|
+
this.connected = true;
|
|
106
|
+
document.getElementById('status').textContent = 'Connected to signaling';
|
|
107
|
+
this.log('🟢 CONNECTED to signaling server', 'success');
|
|
108
|
+
} else if (data.type === 'disconnected') {
|
|
109
|
+
this.connected = false;
|
|
110
|
+
document.getElementById('status').textContent = 'Disconnected';
|
|
111
|
+
this.log('🔴 DISCONNECTED from signaling server', 'error');
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Error events with enhanced debugging
|
|
116
|
+
this.mesh.addEventListener('error', (data) => {
|
|
117
|
+
this.log(`❌ ERROR: ${data.error.message}`, 'error');
|
|
118
|
+
this.log(`🔍 Error details: ${JSON.stringify(data)}`, 'error');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// REAL DATA CHANNEL EVENTS - these should exist
|
|
122
|
+
this.mesh.connectionManager?.addEventListener('dataChannelOpen', (data) => {
|
|
123
|
+
this.log(`� DATA CHANNEL OPENED: ${data.peerId.substring(0, 8)}...`, 'success');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Check for peer connection events from ConnectionManager
|
|
127
|
+
if (this.mesh.connectionManager) {
|
|
128
|
+
this.log('🔍 ConnectionManager found, setting up peer connection listeners');
|
|
129
|
+
|
|
130
|
+
// Monitor new peer connections
|
|
131
|
+
this.mesh.connectionManager.addEventListener('peerConnected', (data) => {
|
|
132
|
+
this.log(`� PEER CONNECTION ESTABLISHED: ${data.peerId.substring(0, 8)}...`, 'success');
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Add a debug function to check connection states
|
|
137
|
+
setInterval(() => {
|
|
138
|
+
if (this.mesh && this.mesh.connectionManager) {
|
|
139
|
+
const peers = this.mesh.connectionManager.peers || new Map();
|
|
140
|
+
const connectedPeers = [];
|
|
141
|
+
|
|
142
|
+
peers.forEach((peerConnection, peerId) => {
|
|
143
|
+
const state = peerConnection.connection?.connectionState || 'unknown';
|
|
144
|
+
const iceState = peerConnection.connection?.iceConnectionState || 'unknown';
|
|
145
|
+
const signalingState = peerConnection.connection?.signalingState || 'unknown';
|
|
146
|
+
const dataChannelState = peerConnection.dataChannel?.readyState || 'no-channel';
|
|
147
|
+
const isInitiator = peerConnection.isInitiator;
|
|
148
|
+
|
|
149
|
+
if (state !== 'new' || iceState !== 'new') {
|
|
150
|
+
connectedPeers.push({
|
|
151
|
+
id: peerId.substring(0, 8),
|
|
152
|
+
connection: state,
|
|
153
|
+
ice: iceState,
|
|
154
|
+
signaling: signalingState,
|
|
155
|
+
dataChannel: dataChannelState,
|
|
156
|
+
initiator: isInitiator
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
if (connectedPeers.length > 0) {
|
|
162
|
+
connectedPeers.forEach(peer => {
|
|
163
|
+
this.log(`🔍 PEER STATUS: ${peer.id}... | conn:${peer.connection} | ice:${peer.ice} | sig:${peer.signaling} | data:${peer.dataChannel} | init:${peer.initiator}`);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}, 5000); // Check every 5 seconds
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async connect() {
|
|
171
|
+
if (!this.mesh) {
|
|
172
|
+
this.log('❌ Mesh not initialized', 'error');
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
this.log('🔌 Connecting to signaling server...');
|
|
178
|
+
await this.mesh.connect('ws://localhost:3000');
|
|
179
|
+
this.log('✅ Connection initiated', 'success');
|
|
180
|
+
} catch (error) {
|
|
181
|
+
this.log(`❌ Connection failed: ${error.message}`, 'error');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
sendMessage() {
|
|
186
|
+
if (!this.mesh || this.peerCount === 0) {
|
|
187
|
+
this.log('❌ No connected peers', 'error');
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const testMessage = {
|
|
192
|
+
type: 'test',
|
|
193
|
+
content: 'Hello from minimal browser!',
|
|
194
|
+
timestamp: Date.now()
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
this.mesh.broadcast(testMessage);
|
|
199
|
+
this.log(`📤 BROADCAST: ${JSON.stringify(testMessage)}`);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
this.log(`❌ Broadcast failed: ${error.message}`, 'error');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
log(message, type = 'info') {
|
|
206
|
+
const logElement = document.getElementById('log');
|
|
207
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
208
|
+
const className = type === 'error' ? 'error' : type === 'success' ? 'success' : type === 'warning' ? 'warning' : '';
|
|
209
|
+
|
|
210
|
+
const logEntry = document.createElement('div');
|
|
211
|
+
logEntry.className = className;
|
|
212
|
+
logEntry.textContent = `[${timestamp}] ${message}`;
|
|
213
|
+
|
|
214
|
+
logElement.appendChild(logEntry);
|
|
215
|
+
logElement.scrollTop = logElement.scrollHeight;
|
|
216
|
+
|
|
217
|
+
// Also log to console for debugging
|
|
218
|
+
console.log(`[MINIMAL] ${message}`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
clearLog() {
|
|
222
|
+
document.getElementById('log').innerHTML = '';
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Global functions for HTML buttons
|
|
227
|
+
const minimalPeer = new MinimalPeerPigeon();
|
|
228
|
+
window.minimalPeer = minimalPeer;
|
|
229
|
+
window.connect = () => minimalPeer.connect();
|
|
230
|
+
window.sendMessage = () => minimalPeer.sendMessage();
|
|
231
|
+
window.clearLog = () => minimalPeer.clearLog();
|
|
232
|
+
|
|
233
|
+
// Debug: Expose mesh for console inspection
|
|
234
|
+
window.mesh = () => minimalPeer.mesh;
|