peerpigeon 1.0.4 → 1.0.7
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 +60 -1
- package/dist/peerpigeon-browser.js +800 -36
- package/dist/peerpigeon-browser.js.map +3 -3
- package/docs/BINARY_IMPLEMENTATION_SUMMARY.md +304 -0
- package/docs/BINARY_MESSAGES.md +332 -0
- package/docs/BROADCAST_STREAMING.md +388 -0
- package/docs/PEER_DISCOVERY_FIXES.md +140 -0
- package/docs/STREAMING_API.md +542 -0
- package/docs/STREAMING_IMPLEMENTATION_SUMMARY.md +286 -0
- package/examples/binary-message-demo.html +496 -0
- package/examples/broadcast-stream-demo.html +539 -0
- package/examples/browser-2/EXPRESS_SOLUTION.md +183 -0
- package/examples/browser-2/ICE_DEBUG.md +171 -0
- package/examples/browser-2/IMPLEMENTATION.md +218 -0
- package/examples/browser-2/QUICK_START.md +149 -0
- package/examples/browser-2/README.md +303 -0
- package/examples/browser-2/dist/assets/index-Cck_6WJV.css +1 -0
- package/examples/browser-2/dist/assets/index-D8-cNlWQ.js +57 -0
- package/examples/browser-2/dist/index.html +32 -0
- package/examples/browser-2/dist/peerpigeon-browser.js +12483 -0
- package/examples/browser-2/index.html +2 -1
- package/examples/browser-2/package-lock.json +1276 -0
- package/examples/browser-2/package.json +5 -3
- package/examples/browser-2/public/peerpigeon-browser.js +12483 -0
- package/examples/browser-2/src/App.vue +7 -4
- package/examples/browser-2/src/components/CryptoView.vue +4 -4
- package/examples/browser-2/src/components/TestingView.vue +794 -0
- package/examples/browser-2/src/main.js +7 -1
- package/examples/browser-2/src/router.js +63 -0
- package/examples/browser-2/src/stores/peerpigeon.js +68 -7
- package/examples/browser-2/vite.config.js +15 -1
- package/examples/stream-file-transfer-demo.html +935 -0
- package/package.json +1 -1
- package/server/index.js +175 -38
- package/src/ConnectionManager.js +68 -8
- package/src/GossipManager.js +22 -0
- package/src/PeerConnection.js +421 -11
- package/src/PeerDiscovery.js +33 -18
- package/src/PeerPigeonMesh.js +453 -1
- package/src/SignalingClient.js +12 -5
- package/src/SignalingHandler.js +18 -5
- package/src/browser-entry.js +5 -1
|
@@ -0,0 +1,539 @@
|
|
|
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 - Broadcast Stream Demo</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
10
|
+
max-width: 1200px;
|
|
11
|
+
margin: 0 auto;
|
|
12
|
+
padding: 20px;
|
|
13
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
14
|
+
color: #333;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.container {
|
|
18
|
+
background: white;
|
|
19
|
+
border-radius: 12px;
|
|
20
|
+
padding: 30px;
|
|
21
|
+
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
h1 {
|
|
25
|
+
color: #667eea;
|
|
26
|
+
text-align: center;
|
|
27
|
+
margin-bottom: 10px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.subtitle {
|
|
31
|
+
text-align: center;
|
|
32
|
+
color: #666;
|
|
33
|
+
margin-bottom: 30px;
|
|
34
|
+
font-style: italic;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.section {
|
|
38
|
+
background: #f8f9fa;
|
|
39
|
+
padding: 20px;
|
|
40
|
+
border-radius: 8px;
|
|
41
|
+
margin-bottom: 20px;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.section h2 {
|
|
45
|
+
color: #764ba2;
|
|
46
|
+
margin-top: 0;
|
|
47
|
+
font-size: 1.3em;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
input, button {
|
|
51
|
+
padding: 12px;
|
|
52
|
+
margin: 5px;
|
|
53
|
+
border-radius: 6px;
|
|
54
|
+
border: 1px solid #ddd;
|
|
55
|
+
font-size: 14px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
button {
|
|
59
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
60
|
+
color: white;
|
|
61
|
+
border: none;
|
|
62
|
+
cursor: pointer;
|
|
63
|
+
font-weight: bold;
|
|
64
|
+
transition: transform 0.2s;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
button:hover {
|
|
68
|
+
transform: translateY(-2px);
|
|
69
|
+
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
button:disabled {
|
|
73
|
+
background: #ccc;
|
|
74
|
+
cursor: not-allowed;
|
|
75
|
+
transform: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#status {
|
|
79
|
+
padding: 15px;
|
|
80
|
+
border-radius: 6px;
|
|
81
|
+
margin: 10px 0;
|
|
82
|
+
font-weight: bold;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.status-disconnected {
|
|
86
|
+
background: #fee;
|
|
87
|
+
color: #c33;
|
|
88
|
+
border: 1px solid #fcc;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.status-connected {
|
|
92
|
+
background: #efe;
|
|
93
|
+
color: #3c3;
|
|
94
|
+
border: 1px solid #cfc;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#peers {
|
|
98
|
+
background: white;
|
|
99
|
+
padding: 15px;
|
|
100
|
+
border-radius: 6px;
|
|
101
|
+
min-height: 60px;
|
|
102
|
+
border: 2px dashed #ddd;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.peer-badge {
|
|
106
|
+
display: inline-block;
|
|
107
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
108
|
+
color: white;
|
|
109
|
+
padding: 5px 12px;
|
|
110
|
+
border-radius: 15px;
|
|
111
|
+
margin: 3px;
|
|
112
|
+
font-size: 12px;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#logs {
|
|
116
|
+
background: #2d2d2d;
|
|
117
|
+
color: #0f0;
|
|
118
|
+
padding: 15px;
|
|
119
|
+
border-radius: 6px;
|
|
120
|
+
height: 300px;
|
|
121
|
+
overflow-y: auto;
|
|
122
|
+
font-family: 'Courier New', monospace;
|
|
123
|
+
font-size: 12px;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.log-entry {
|
|
127
|
+
margin: 2px 0;
|
|
128
|
+
word-wrap: break-word;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.log-info { color: #0ff; }
|
|
132
|
+
.log-success { color: #0f0; }
|
|
133
|
+
.log-warning { color: #ff0; }
|
|
134
|
+
.log-error { color: #f00; }
|
|
135
|
+
|
|
136
|
+
.file-input-wrapper {
|
|
137
|
+
position: relative;
|
|
138
|
+
overflow: hidden;
|
|
139
|
+
display: inline-block;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.file-input-wrapper input[type=file] {
|
|
143
|
+
position: absolute;
|
|
144
|
+
left: -9999px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
#progress-container {
|
|
148
|
+
display: none;
|
|
149
|
+
margin-top: 15px;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
#progress-bar {
|
|
153
|
+
width: 100%;
|
|
154
|
+
height: 30px;
|
|
155
|
+
background: #e0e0e0;
|
|
156
|
+
border-radius: 15px;
|
|
157
|
+
overflow: hidden;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
#progress-fill {
|
|
161
|
+
height: 100%;
|
|
162
|
+
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
|
|
163
|
+
width: 0%;
|
|
164
|
+
transition: width 0.3s;
|
|
165
|
+
display: flex;
|
|
166
|
+
align-items: center;
|
|
167
|
+
justify-content: center;
|
|
168
|
+
color: white;
|
|
169
|
+
font-weight: bold;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.stats {
|
|
173
|
+
display: grid;
|
|
174
|
+
grid-template-columns: repeat(3, 1fr);
|
|
175
|
+
gap: 10px;
|
|
176
|
+
margin-top: 15px;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.stat-box {
|
|
180
|
+
background: white;
|
|
181
|
+
padding: 10px;
|
|
182
|
+
border-radius: 6px;
|
|
183
|
+
text-align: center;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.stat-label {
|
|
187
|
+
font-size: 11px;
|
|
188
|
+
color: #666;
|
|
189
|
+
text-transform: uppercase;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.stat-value {
|
|
193
|
+
font-size: 20px;
|
|
194
|
+
font-weight: bold;
|
|
195
|
+
color: #667eea;
|
|
196
|
+
}
|
|
197
|
+
</style>
|
|
198
|
+
</head>
|
|
199
|
+
<body>
|
|
200
|
+
<div class="container">
|
|
201
|
+
<h1>🐦 PeerPigeon Broadcast Stream Demo</h1>
|
|
202
|
+
<p class="subtitle">Stream files to all connected peers simultaneously</p>
|
|
203
|
+
|
|
204
|
+
<div class="section">
|
|
205
|
+
<h2>📡 Connection</h2>
|
|
206
|
+
<input type="text" id="signalingUrl" placeholder="ws://localhost:3000" value="ws://localhost:3000" style="width: 300px;">
|
|
207
|
+
<button onclick="connect()" id="connectBtn">Connect</button>
|
|
208
|
+
<button onclick="disconnect()" id="disconnectBtn" disabled>Disconnect</button>
|
|
209
|
+
<div id="status" class="status-disconnected">Disconnected</div>
|
|
210
|
+
<div id="peers">No peers connected</div>
|
|
211
|
+
</div>
|
|
212
|
+
|
|
213
|
+
<div class="section">
|
|
214
|
+
<h2>📤 Broadcast Stream</h2>
|
|
215
|
+
<p>Select a file to broadcast to all connected peers:</p>
|
|
216
|
+
<div class="file-input-wrapper">
|
|
217
|
+
<button>Choose File</button>
|
|
218
|
+
<input type="file" id="fileInput" onchange="handleFileSelect(event)">
|
|
219
|
+
</div>
|
|
220
|
+
<button onclick="broadcastSelectedFile()" id="broadcastBtn" disabled>Broadcast File</button>
|
|
221
|
+
<button onclick="testBroadcastText()" id="testTextBtn" disabled>Test: Broadcast Text</button>
|
|
222
|
+
|
|
223
|
+
<div id="progress-container">
|
|
224
|
+
<div id="progress-bar">
|
|
225
|
+
<div id="progress-fill">0%</div>
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
|
|
229
|
+
<div class="stats">
|
|
230
|
+
<div class="stat-box">
|
|
231
|
+
<div class="stat-label">Total Sent</div>
|
|
232
|
+
<div class="stat-value" id="totalSent">0 KB</div>
|
|
233
|
+
</div>
|
|
234
|
+
<div class="stat-box">
|
|
235
|
+
<div class="stat-label">Success Rate</div>
|
|
236
|
+
<div class="stat-value" id="successRate">0%</div>
|
|
237
|
+
</div>
|
|
238
|
+
<div class="stat-box">
|
|
239
|
+
<div class="stat-label">Broadcasts</div>
|
|
240
|
+
<div class="stat-value" id="broadcastCount">0</div>
|
|
241
|
+
</div>
|
|
242
|
+
</div>
|
|
243
|
+
</div>
|
|
244
|
+
|
|
245
|
+
<div class="section">
|
|
246
|
+
<h2>📥 Received Streams</h2>
|
|
247
|
+
<div id="receivedStreams"></div>
|
|
248
|
+
</div>
|
|
249
|
+
|
|
250
|
+
<div class="section">
|
|
251
|
+
<h2>📊 Logs</h2>
|
|
252
|
+
<button onclick="clearLogs()">Clear Logs</button>
|
|
253
|
+
<div id="logs"></div>
|
|
254
|
+
</div>
|
|
255
|
+
</div>
|
|
256
|
+
|
|
257
|
+
<script type="module">
|
|
258
|
+
import { PeerPigeonMesh } from '../src/PeerPigeonMesh.js';
|
|
259
|
+
|
|
260
|
+
let mesh;
|
|
261
|
+
let selectedFile = null;
|
|
262
|
+
let broadcastStats = {
|
|
263
|
+
totalBytes: 0,
|
|
264
|
+
successCount: 0,
|
|
265
|
+
totalPeers: 0,
|
|
266
|
+
broadcastCount: 0
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
window.connect = async function() {
|
|
270
|
+
const url = document.getElementById('signalingUrl').value;
|
|
271
|
+
log('Initializing PeerPigeon mesh...', 'info');
|
|
272
|
+
|
|
273
|
+
mesh = new PeerPigeonMesh({
|
|
274
|
+
maxPeers: 10,
|
|
275
|
+
enableWebDHT: true
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// Set up event listeners
|
|
279
|
+
mesh.addEventListener('connected', () => {
|
|
280
|
+
log('✅ Connected to signaling server', 'success');
|
|
281
|
+
updateStatus('Connected', true);
|
|
282
|
+
document.getElementById('connectBtn').disabled = true;
|
|
283
|
+
document.getElementById('disconnectBtn').disabled = false;
|
|
284
|
+
document.getElementById('broadcastBtn').disabled = selectedFile === null;
|
|
285
|
+
document.getElementById('testTextBtn').disabled = false;
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
mesh.addEventListener('disconnected', () => {
|
|
289
|
+
log('❌ Disconnected from signaling server', 'warning');
|
|
290
|
+
updateStatus('Disconnected', false);
|
|
291
|
+
document.getElementById('connectBtn').disabled = false;
|
|
292
|
+
document.getElementById('disconnectBtn').disabled = true;
|
|
293
|
+
document.getElementById('broadcastBtn').disabled = true;
|
|
294
|
+
document.getElementById('testTextBtn').disabled = true;
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
mesh.addEventListener('peerConnected', (data) => {
|
|
298
|
+
log(`🤝 Peer connected: ${data.peerId.substring(0, 8)}...`, 'success');
|
|
299
|
+
updatePeerList();
|
|
300
|
+
document.getElementById('broadcastBtn').disabled = selectedFile === null;
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
mesh.addEventListener('peerDisconnected', (data) => {
|
|
304
|
+
log(`👋 Peer disconnected: ${data.peerId.substring(0, 8)}...`, 'warning');
|
|
305
|
+
updatePeerList();
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
mesh.addEventListener('streamReceived', async (data) => {
|
|
309
|
+
log(`📥 Receiving stream from ${data.peerId.substring(0, 8)}...`, 'info');
|
|
310
|
+
log(`📋 Metadata: ${JSON.stringify(data.metadata)}`, 'info');
|
|
311
|
+
|
|
312
|
+
// Collect stream chunks
|
|
313
|
+
const chunks = [];
|
|
314
|
+
const reader = data.stream.getReader();
|
|
315
|
+
|
|
316
|
+
try {
|
|
317
|
+
while (true) {
|
|
318
|
+
const { done, value } = await reader.read();
|
|
319
|
+
if (done) break;
|
|
320
|
+
chunks.push(value);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Combine chunks
|
|
324
|
+
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
325
|
+
const combined = new Uint8Array(totalLength);
|
|
326
|
+
let offset = 0;
|
|
327
|
+
for (const chunk of chunks) {
|
|
328
|
+
combined.set(chunk, offset);
|
|
329
|
+
offset += chunk.length;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
log(`✅ Stream received: ${totalLength} bytes`, 'success');
|
|
333
|
+
|
|
334
|
+
// Display received stream
|
|
335
|
+
displayReceivedStream(data.peerId, data.metadata, combined);
|
|
336
|
+
} catch (error) {
|
|
337
|
+
log(`❌ Error receiving stream: ${error.message}`, 'error');
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
mesh.addEventListener('broadcastStreamComplete', (data) => {
|
|
342
|
+
log(`✅ Broadcast complete: ${data.totalBytes} bytes to ${data.successCount}/${data.totalPeers} peers`, 'success');
|
|
343
|
+
|
|
344
|
+
// Update stats
|
|
345
|
+
broadcastStats.totalBytes += data.totalBytes;
|
|
346
|
+
broadcastStats.successCount += data.successCount;
|
|
347
|
+
broadcastStats.totalPeers = data.totalPeers;
|
|
348
|
+
broadcastStats.broadcastCount++;
|
|
349
|
+
updateStats();
|
|
350
|
+
|
|
351
|
+
hideProgress();
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
mesh.addEventListener('broadcastStreamAborted', (data) => {
|
|
355
|
+
log(`❌ Broadcast aborted: ${data.reason}`, 'error');
|
|
356
|
+
hideProgress();
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
await mesh.init();
|
|
360
|
+
await mesh.connect(url);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
window.disconnect = function() {
|
|
364
|
+
if (mesh) {
|
|
365
|
+
mesh.disconnect();
|
|
366
|
+
mesh = null;
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
window.handleFileSelect = function(event) {
|
|
371
|
+
selectedFile = event.target.files[0];
|
|
372
|
+
if (selectedFile) {
|
|
373
|
+
log(`📁 File selected: ${selectedFile.name} (${formatBytes(selectedFile.size)})`, 'info');
|
|
374
|
+
if (mesh && mesh.getConnectedPeerCount() > 0) {
|
|
375
|
+
document.getElementById('broadcastBtn').disabled = false;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
window.broadcastSelectedFile = async function() {
|
|
381
|
+
if (!selectedFile || !mesh) return;
|
|
382
|
+
|
|
383
|
+
const peers = mesh.getConnectedPeerCount();
|
|
384
|
+
if (peers === 0) {
|
|
385
|
+
log('❌ No peers connected', 'error');
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
log(`📡 Broadcasting file "${selectedFile.name}" to ${peers} peer(s)...`, 'info');
|
|
390
|
+
showProgress();
|
|
391
|
+
|
|
392
|
+
try {
|
|
393
|
+
await mesh.broadcastFile(selectedFile);
|
|
394
|
+
log(`✅ File broadcast completed`, 'success');
|
|
395
|
+
} catch (error) {
|
|
396
|
+
log(`❌ Broadcast failed: ${error.message}`, 'error');
|
|
397
|
+
hideProgress();
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
window.testBroadcastText = async function() {
|
|
402
|
+
if (!mesh) return;
|
|
403
|
+
|
|
404
|
+
const peers = mesh.getConnectedPeerCount();
|
|
405
|
+
if (peers === 0) {
|
|
406
|
+
log('❌ No peers connected', 'error');
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const text = `Hello from PeerPigeon! Timestamp: ${new Date().toISOString()}`;
|
|
411
|
+
const blob = new Blob([text], { type: 'text/plain' });
|
|
412
|
+
|
|
413
|
+
log(`📡 Broadcasting text message to ${peers} peer(s)...`, 'info');
|
|
414
|
+
showProgress();
|
|
415
|
+
|
|
416
|
+
try {
|
|
417
|
+
await mesh.broadcastBlob(blob, { filename: 'test-message.txt' });
|
|
418
|
+
log(`✅ Text broadcast completed`, 'success');
|
|
419
|
+
} catch (error) {
|
|
420
|
+
log(`❌ Broadcast failed: ${error.message}`, 'error');
|
|
421
|
+
hideProgress();
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
function displayReceivedStream(peerId, metadata, data) {
|
|
426
|
+
const container = document.getElementById('receivedStreams');
|
|
427
|
+
const div = document.createElement('div');
|
|
428
|
+
div.style.cssText = 'background: white; padding: 15px; margin: 10px 0; border-radius: 6px; border: 1px solid #ddd;';
|
|
429
|
+
|
|
430
|
+
let content = `
|
|
431
|
+
<strong>From:</strong> ${peerId.substring(0, 8)}...<br>
|
|
432
|
+
<strong>Size:</strong> ${formatBytes(data.length)}<br>
|
|
433
|
+
`;
|
|
434
|
+
|
|
435
|
+
if (metadata.filename) {
|
|
436
|
+
content += `<strong>Filename:</strong> ${metadata.filename}<br>`;
|
|
437
|
+
}
|
|
438
|
+
if (metadata.mimeType) {
|
|
439
|
+
content += `<strong>Type:</strong> ${metadata.mimeType}<br>`;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// Try to display or download
|
|
443
|
+
if (metadata.mimeType && metadata.mimeType.startsWith('text/')) {
|
|
444
|
+
const text = new TextDecoder().decode(data);
|
|
445
|
+
content += `<br><pre style="background: #f0f0f0; padding: 10px; border-radius: 4px;">${text}</pre>`;
|
|
446
|
+
} else {
|
|
447
|
+
const blob = new Blob([data], { type: metadata.mimeType || 'application/octet-stream' });
|
|
448
|
+
const url = URL.createObjectURL(blob);
|
|
449
|
+
content += `<br><a href="${url}" download="${metadata.filename || 'download'}" style="color: #667eea; text-decoration: none; font-weight: bold;">📥 Download</a>`;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
div.innerHTML = content;
|
|
453
|
+
container.insertBefore(div, container.firstChild);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function updateStatus(text, connected) {
|
|
457
|
+
const statusDiv = document.getElementById('status');
|
|
458
|
+
statusDiv.textContent = text;
|
|
459
|
+
statusDiv.className = connected ? 'status-connected' : 'status-disconnected';
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function updatePeerList() {
|
|
463
|
+
if (!mesh) return;
|
|
464
|
+
|
|
465
|
+
const peers = mesh.getConnectedPeers();
|
|
466
|
+
const peerDiv = document.getElementById('peers');
|
|
467
|
+
|
|
468
|
+
if (peers.length === 0) {
|
|
469
|
+
peerDiv.innerHTML = 'No peers connected';
|
|
470
|
+
} else {
|
|
471
|
+
peerDiv.innerHTML = peers.map(p =>
|
|
472
|
+
`<span class="peer-badge">${p.peerId.substring(0, 8)}...</span>`
|
|
473
|
+
).join('');
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function updateStats() {
|
|
478
|
+
document.getElementById('totalSent').textContent = formatBytes(broadcastStats.totalBytes);
|
|
479
|
+
const rate = broadcastStats.totalPeers > 0
|
|
480
|
+
? Math.round((broadcastStats.successCount / broadcastStats.totalPeers) * 100)
|
|
481
|
+
: 0;
|
|
482
|
+
document.getElementById('successRate').textContent = `${rate}%`;
|
|
483
|
+
document.getElementById('broadcastCount').textContent = broadcastStats.broadcastCount;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function showProgress() {
|
|
487
|
+
document.getElementById('progress-container').style.display = 'block';
|
|
488
|
+
// Simulate progress animation
|
|
489
|
+
let progress = 0;
|
|
490
|
+
const interval = setInterval(() => {
|
|
491
|
+
progress += Math.random() * 10;
|
|
492
|
+
if (progress >= 90) progress = 90;
|
|
493
|
+
document.getElementById('progress-fill').style.width = `${progress}%`;
|
|
494
|
+
document.getElementById('progress-fill').textContent = `${Math.round(progress)}%`;
|
|
495
|
+
}, 100);
|
|
496
|
+
|
|
497
|
+
// Store interval for cleanup
|
|
498
|
+
window.progressInterval = interval;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function hideProgress() {
|
|
502
|
+
if (window.progressInterval) {
|
|
503
|
+
clearInterval(window.progressInterval);
|
|
504
|
+
}
|
|
505
|
+
document.getElementById('progress-fill').style.width = '100%';
|
|
506
|
+
document.getElementById('progress-fill').textContent = '100%';
|
|
507
|
+
setTimeout(() => {
|
|
508
|
+
document.getElementById('progress-container').style.display = 'none';
|
|
509
|
+
document.getElementById('progress-fill').style.width = '0%';
|
|
510
|
+
document.getElementById('progress-fill').textContent = '0%';
|
|
511
|
+
}, 1000);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function log(message, type = 'info') {
|
|
515
|
+
const logs = document.getElementById('logs');
|
|
516
|
+
const entry = document.createElement('div');
|
|
517
|
+
entry.className = `log-entry log-${type}`;
|
|
518
|
+
entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
|
519
|
+
logs.appendChild(entry);
|
|
520
|
+
logs.scrollTop = logs.scrollHeight;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
window.clearLogs = function() {
|
|
524
|
+
document.getElementById('logs').innerHTML = '';
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
function formatBytes(bytes) {
|
|
528
|
+
if (bytes === 0) return '0 Bytes';
|
|
529
|
+
const k = 1024;
|
|
530
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
|
531
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
532
|
+
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// Make functions available globally
|
|
536
|
+
window.mesh = mesh;
|
|
537
|
+
</script>
|
|
538
|
+
</body>
|
|
539
|
+
</html>
|