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,496 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>PeerPigeon Binary Message Demo</title>
|
|
5
|
+
<style>
|
|
6
|
+
body {
|
|
7
|
+
font-family: 'Segoe UI', system-ui, sans-serif;
|
|
8
|
+
max-width: 1200px;
|
|
9
|
+
margin: 0 auto;
|
|
10
|
+
padding: 20px;
|
|
11
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
12
|
+
min-height: 100vh;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.container {
|
|
16
|
+
background: white;
|
|
17
|
+
border-radius: 12px;
|
|
18
|
+
padding: 30px;
|
|
19
|
+
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
h1 {
|
|
23
|
+
color: #667eea;
|
|
24
|
+
margin-top: 0;
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
gap: 10px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.status {
|
|
31
|
+
padding: 15px;
|
|
32
|
+
border-radius: 8px;
|
|
33
|
+
margin: 20px 0;
|
|
34
|
+
font-weight: 500;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.status.connected {
|
|
38
|
+
background: #d4edda;
|
|
39
|
+
color: #155724;
|
|
40
|
+
border: 1px solid #c3e6cb;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.status.disconnected {
|
|
44
|
+
background: #f8d7da;
|
|
45
|
+
color: #721c24;
|
|
46
|
+
border: 1px solid #f5c6cb;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.controls {
|
|
50
|
+
display: grid;
|
|
51
|
+
grid-template-columns: 1fr 1fr;
|
|
52
|
+
gap: 20px;
|
|
53
|
+
margin: 20px 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.panel {
|
|
57
|
+
background: #f8f9fa;
|
|
58
|
+
padding: 20px;
|
|
59
|
+
border-radius: 8px;
|
|
60
|
+
border: 1px solid #dee2e6;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.panel h3 {
|
|
64
|
+
margin-top: 0;
|
|
65
|
+
color: #495057;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
button {
|
|
69
|
+
background: #667eea;
|
|
70
|
+
color: white;
|
|
71
|
+
border: none;
|
|
72
|
+
padding: 12px 24px;
|
|
73
|
+
border-radius: 6px;
|
|
74
|
+
cursor: pointer;
|
|
75
|
+
font-size: 14px;
|
|
76
|
+
font-weight: 500;
|
|
77
|
+
transition: all 0.3s;
|
|
78
|
+
width: 100%;
|
|
79
|
+
margin: 5px 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
button:hover {
|
|
83
|
+
background: #5568d3;
|
|
84
|
+
transform: translateY(-1px);
|
|
85
|
+
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
button:disabled {
|
|
89
|
+
background: #6c757d;
|
|
90
|
+
cursor: not-allowed;
|
|
91
|
+
transform: none;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
input, textarea {
|
|
95
|
+
width: 100%;
|
|
96
|
+
padding: 10px;
|
|
97
|
+
border: 1px solid #ced4da;
|
|
98
|
+
border-radius: 6px;
|
|
99
|
+
font-size: 14px;
|
|
100
|
+
box-sizing: border-box;
|
|
101
|
+
margin: 5px 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
textarea {
|
|
105
|
+
resize: vertical;
|
|
106
|
+
min-height: 80px;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.log {
|
|
110
|
+
background: #1e1e1e;
|
|
111
|
+
color: #d4d4d4;
|
|
112
|
+
padding: 20px;
|
|
113
|
+
border-radius: 8px;
|
|
114
|
+
max-height: 400px;
|
|
115
|
+
overflow-y: auto;
|
|
116
|
+
font-family: 'Courier New', monospace;
|
|
117
|
+
font-size: 13px;
|
|
118
|
+
line-height: 1.6;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.log-entry {
|
|
122
|
+
padding: 4px 0;
|
|
123
|
+
border-bottom: 1px solid #333;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.log-entry:last-child {
|
|
127
|
+
border-bottom: none;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.log-entry.success { color: #4ec9b0; }
|
|
131
|
+
.log-entry.error { color: #f48771; }
|
|
132
|
+
.log-entry.info { color: #9cdcfe; }
|
|
133
|
+
.log-entry.binary { color: #dcdcaa; }
|
|
134
|
+
|
|
135
|
+
.peers-list {
|
|
136
|
+
display: flex;
|
|
137
|
+
gap: 10px;
|
|
138
|
+
flex-wrap: wrap;
|
|
139
|
+
margin: 10px 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.peer-badge {
|
|
143
|
+
background: #667eea;
|
|
144
|
+
color: white;
|
|
145
|
+
padding: 8px 16px;
|
|
146
|
+
border-radius: 20px;
|
|
147
|
+
font-size: 12px;
|
|
148
|
+
font-weight: 500;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.stats {
|
|
152
|
+
display: grid;
|
|
153
|
+
grid-template-columns: repeat(3, 1fr);
|
|
154
|
+
gap: 15px;
|
|
155
|
+
margin: 20px 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.stat-card {
|
|
159
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
160
|
+
color: white;
|
|
161
|
+
padding: 20px;
|
|
162
|
+
border-radius: 8px;
|
|
163
|
+
text-align: center;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.stat-value {
|
|
167
|
+
font-size: 32px;
|
|
168
|
+
font-weight: bold;
|
|
169
|
+
margin: 10px 0;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.stat-label {
|
|
173
|
+
font-size: 14px;
|
|
174
|
+
opacity: 0.9;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
select {
|
|
178
|
+
width: 100%;
|
|
179
|
+
padding: 10px;
|
|
180
|
+
border: 1px solid #ced4da;
|
|
181
|
+
border-radius: 6px;
|
|
182
|
+
font-size: 14px;
|
|
183
|
+
margin: 5px 0;
|
|
184
|
+
background: white;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.binary-preview {
|
|
188
|
+
background: #f8f9fa;
|
|
189
|
+
padding: 10px;
|
|
190
|
+
border-radius: 6px;
|
|
191
|
+
margin: 10px 0;
|
|
192
|
+
font-family: 'Courier New', monospace;
|
|
193
|
+
font-size: 12px;
|
|
194
|
+
max-height: 100px;
|
|
195
|
+
overflow-y: auto;
|
|
196
|
+
word-break: break-all;
|
|
197
|
+
}
|
|
198
|
+
</style>
|
|
199
|
+
</head>
|
|
200
|
+
<body>
|
|
201
|
+
<div class="container">
|
|
202
|
+
<h1>
|
|
203
|
+
📦 PeerPigeon Binary Message Demo
|
|
204
|
+
</h1>
|
|
205
|
+
|
|
206
|
+
<div id="status" class="status disconnected">
|
|
207
|
+
⏳ Initializing...
|
|
208
|
+
</div>
|
|
209
|
+
|
|
210
|
+
<div class="stats">
|
|
211
|
+
<div class="stat-card">
|
|
212
|
+
<div class="stat-label">Connected Peers</div>
|
|
213
|
+
<div class="stat-value" id="peer-count">0</div>
|
|
214
|
+
</div>
|
|
215
|
+
<div class="stat-card">
|
|
216
|
+
<div class="stat-label">Messages Sent</div>
|
|
217
|
+
<div class="stat-value" id="messages-sent">0</div>
|
|
218
|
+
</div>
|
|
219
|
+
<div class="stat-card">
|
|
220
|
+
<div class="stat-label">Bytes Received</div>
|
|
221
|
+
<div class="stat-value" id="bytes-received">0</div>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
|
|
225
|
+
<div class="controls">
|
|
226
|
+
<div class="panel">
|
|
227
|
+
<h3>📤 Send Binary Data</h3>
|
|
228
|
+
<label>Select Peer:</label>
|
|
229
|
+
<select id="target-peer">
|
|
230
|
+
<option value="">Broadcast to All</option>
|
|
231
|
+
</select>
|
|
232
|
+
|
|
233
|
+
<label>Data Size (bytes):</label>
|
|
234
|
+
<input type="number" id="data-size" value="1024" min="1" max="1000000">
|
|
235
|
+
|
|
236
|
+
<label>Fill Byte (0-255):</label>
|
|
237
|
+
<input type="number" id="fill-byte" value="42" min="0" max="255">
|
|
238
|
+
|
|
239
|
+
<button onclick="sendRandomBinary()">Send Random Binary</button>
|
|
240
|
+
<button onclick="sendTestPattern()">Send Test Pattern</button>
|
|
241
|
+
<button onclick="sendTextAsBinary()">Send Text as Binary</button>
|
|
242
|
+
</div>
|
|
243
|
+
|
|
244
|
+
<div class="panel">
|
|
245
|
+
<h3>📥 Custom Text Binary</h3>
|
|
246
|
+
<label>Enter text to send as binary:</label>
|
|
247
|
+
<textarea id="text-input" placeholder="Enter text here...">Hello from PeerPigeon! 🐦</textarea>
|
|
248
|
+
<div id="text-preview" class="binary-preview"></div>
|
|
249
|
+
<button onclick="sendCustomText()">Send as Binary</button>
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
|
|
253
|
+
<h3>📜 Activity Log</h3>
|
|
254
|
+
<div id="log" class="log"></div>
|
|
255
|
+
|
|
256
|
+
<div style="margin-top: 20px;">
|
|
257
|
+
<h3>🔗 Connected Peers</h3>
|
|
258
|
+
<div id="peers-list" class="peers-list">
|
|
259
|
+
<span style="color: #666;">No peers connected</span>
|
|
260
|
+
</div>
|
|
261
|
+
</div>
|
|
262
|
+
</div>
|
|
263
|
+
|
|
264
|
+
<script src="../dist/peerpigeon-browser.js"></script>
|
|
265
|
+
<script>
|
|
266
|
+
let mesh = null;
|
|
267
|
+
let messagesSent = 0;
|
|
268
|
+
let bytesReceived = 0;
|
|
269
|
+
|
|
270
|
+
// Initialize
|
|
271
|
+
async function init() {
|
|
272
|
+
log('🚀 Initializing PeerPigeon...', 'info');
|
|
273
|
+
|
|
274
|
+
mesh = new PeerPigeonMesh({
|
|
275
|
+
signalingServer: 'ws://localhost:3000',
|
|
276
|
+
networkName: 'binary-demo',
|
|
277
|
+
autoConnect: true,
|
|
278
|
+
maxPeers: 4,
|
|
279
|
+
debug: true
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
await mesh.connect();
|
|
283
|
+
|
|
284
|
+
setupEventListeners();
|
|
285
|
+
updateTextPreview();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function setupEventListeners() {
|
|
289
|
+
mesh.addEventListener('connected', () => {
|
|
290
|
+
updateStatus('connected', '✅ Connected to mesh network');
|
|
291
|
+
log('✅ Connected to signaling server', 'success');
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
mesh.addEventListener('disconnected', () => {
|
|
295
|
+
updateStatus('disconnected', '❌ Disconnected from mesh network');
|
|
296
|
+
log('❌ Disconnected from signaling server', 'error');
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
mesh.addEventListener('peerConnected', (event) => {
|
|
300
|
+
log(`🤝 Peer connected: ${event.peerId.substring(0, 8)}...`, 'success');
|
|
301
|
+
updatePeersList();
|
|
302
|
+
updatePeerCount();
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
mesh.addEventListener('peerDisconnected', (event) => {
|
|
306
|
+
log(`👋 Peer disconnected: ${event.peerId.substring(0, 8)}...`, 'info');
|
|
307
|
+
updatePeersList();
|
|
308
|
+
updatePeerCount();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// Binary message handler
|
|
312
|
+
mesh.addEventListener('binaryMessageReceived', (event) => {
|
|
313
|
+
const { from, data, size } = event;
|
|
314
|
+
bytesReceived += size;
|
|
315
|
+
|
|
316
|
+
log(`📦 Binary message received from ${from.substring(0, 8)}... (${size} bytes)`, 'binary');
|
|
317
|
+
|
|
318
|
+
// Try to decode as text
|
|
319
|
+
try {
|
|
320
|
+
const text = new TextDecoder().decode(data);
|
|
321
|
+
if (isPrintableText(text)) {
|
|
322
|
+
log(` 📝 Decoded text: "${text}"`, 'info');
|
|
323
|
+
} else {
|
|
324
|
+
log(` 🔢 Binary data: ${arrayToHex(data.slice(0, 20))}${size > 20 ? '...' : ''}`, 'info');
|
|
325
|
+
}
|
|
326
|
+
} catch (e) {
|
|
327
|
+
log(` 🔢 Binary data: ${arrayToHex(data.slice(0, 20))}${size > 20 ? '...' : ''}`, 'info');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
updateBytesReceived();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
// Regular text messages
|
|
334
|
+
mesh.addEventListener('messageReceived', (event) => {
|
|
335
|
+
log(`💬 Text message from ${event.from.substring(0, 8)}...: ${JSON.stringify(event.content)}`, 'info');
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async function sendRandomBinary() {
|
|
340
|
+
const size = parseInt(document.getElementById('data-size').value);
|
|
341
|
+
const targetPeer = document.getElementById('target-peer').value;
|
|
342
|
+
|
|
343
|
+
// Create random binary data
|
|
344
|
+
const data = new Uint8Array(size);
|
|
345
|
+
crypto.getRandomValues(data);
|
|
346
|
+
|
|
347
|
+
await sendBinaryData(data, targetPeer, 'random');
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
async function sendTestPattern() {
|
|
351
|
+
const size = parseInt(document.getElementById('data-size').value);
|
|
352
|
+
const fillByte = parseInt(document.getElementById('fill-byte').value);
|
|
353
|
+
const targetPeer = document.getElementById('target-peer').value;
|
|
354
|
+
|
|
355
|
+
// Create pattern with repeating byte
|
|
356
|
+
const data = new Uint8Array(size);
|
|
357
|
+
data.fill(fillByte);
|
|
358
|
+
|
|
359
|
+
await sendBinaryData(data, targetPeer, 'pattern');
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
async function sendTextAsBinary() {
|
|
363
|
+
const text = "Quick test message! 🚀";
|
|
364
|
+
await sendTextData(text, document.getElementById('target-peer').value);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
async function sendCustomText() {
|
|
368
|
+
const text = document.getElementById('text-input').value;
|
|
369
|
+
if (!text) {
|
|
370
|
+
log('❌ No text entered', 'error');
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
await sendTextData(text, document.getElementById('target-peer').value);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async function sendTextData(text, targetPeer) {
|
|
377
|
+
const encoder = new TextEncoder();
|
|
378
|
+
const data = encoder.encode(text);
|
|
379
|
+
await sendBinaryData(data, targetPeer, 'text');
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async function sendBinaryData(data, targetPeer, type) {
|
|
383
|
+
try {
|
|
384
|
+
if (targetPeer) {
|
|
385
|
+
const success = await mesh.sendBinaryData(targetPeer, data);
|
|
386
|
+
if (success) {
|
|
387
|
+
log(`📤 Sent ${type} binary data (${data.length} bytes) to ${targetPeer.substring(0, 8)}...`, 'success');
|
|
388
|
+
messagesSent++;
|
|
389
|
+
updateMessagesSent();
|
|
390
|
+
} else {
|
|
391
|
+
log(`❌ Failed to send to peer`, 'error');
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
const count = await mesh.broadcastBinaryData(data);
|
|
395
|
+
log(`📤 Broadcasted ${type} binary data (${data.length} bytes) to ${count} peers`, 'success');
|
|
396
|
+
messagesSent++;
|
|
397
|
+
updateMessagesSent();
|
|
398
|
+
}
|
|
399
|
+
} catch (error) {
|
|
400
|
+
log(`❌ Error sending binary data: ${error.message}`, 'error');
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function updateTextPreview() {
|
|
405
|
+
const text = document.getElementById('text-input').value;
|
|
406
|
+
const encoder = new TextEncoder();
|
|
407
|
+
const bytes = encoder.encode(text);
|
|
408
|
+
const preview = `Size: ${bytes.length} bytes | Hex: ${arrayToHex(bytes.slice(0, 32))}${bytes.length > 32 ? '...' : ''}`;
|
|
409
|
+
document.getElementById('text-preview').textContent = preview;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Update text preview on input
|
|
413
|
+
document.getElementById('text-input').addEventListener('input', updateTextPreview);
|
|
414
|
+
|
|
415
|
+
function updateStatus(state, message) {
|
|
416
|
+
const statusEl = document.getElementById('status');
|
|
417
|
+
statusEl.className = `status ${state}`;
|
|
418
|
+
statusEl.textContent = message;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function updatePeerCount() {
|
|
422
|
+
document.getElementById('peer-count').textContent = mesh.getConnectedPeers().length;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function updateMessagesSent() {
|
|
426
|
+
document.getElementById('messages-sent').textContent = messagesSent;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function updateBytesReceived() {
|
|
430
|
+
document.getElementById('bytes-received').textContent = formatBytes(bytesReceived);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function updatePeersList() {
|
|
434
|
+
const peers = mesh.getConnectedPeers();
|
|
435
|
+
const select = document.getElementById('target-peer');
|
|
436
|
+
const peersListEl = document.getElementById('peers-list');
|
|
437
|
+
|
|
438
|
+
// Update dropdown
|
|
439
|
+
const currentValue = select.value;
|
|
440
|
+
select.innerHTML = '<option value="">Broadcast to All</option>';
|
|
441
|
+
peers.forEach(peer => {
|
|
442
|
+
const option = document.createElement('option');
|
|
443
|
+
option.value = peer.peerId;
|
|
444
|
+
option.textContent = peer.peerId.substring(0, 16) + '...';
|
|
445
|
+
select.appendChild(option);
|
|
446
|
+
});
|
|
447
|
+
select.value = currentValue;
|
|
448
|
+
|
|
449
|
+
// Update badges
|
|
450
|
+
if (peers.length === 0) {
|
|
451
|
+
peersListEl.innerHTML = '<span style="color: #666;">No peers connected</span>';
|
|
452
|
+
} else {
|
|
453
|
+
peersListEl.innerHTML = peers.map(peer =>
|
|
454
|
+
`<div class="peer-badge">${peer.peerId.substring(0, 8)}...</div>`
|
|
455
|
+
).join('');
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function log(message, type = 'info') {
|
|
460
|
+
const logEl = document.getElementById('log');
|
|
461
|
+
const entry = document.createElement('div');
|
|
462
|
+
entry.className = `log-entry ${type}`;
|
|
463
|
+
entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`;
|
|
464
|
+
logEl.appendChild(entry);
|
|
465
|
+
logEl.scrollTop = logEl.scrollHeight;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function arrayToHex(array) {
|
|
469
|
+
return Array.from(array)
|
|
470
|
+
.map(b => b.toString(16).padStart(2, '0'))
|
|
471
|
+
.join(' ');
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function isPrintableText(text) {
|
|
475
|
+
// Check if string contains mostly printable characters
|
|
476
|
+
const printable = text.split('').filter(c => {
|
|
477
|
+
const code = c.charCodeAt(0);
|
|
478
|
+
return (code >= 32 && code <= 126) || code === 10 || code === 13;
|
|
479
|
+
}).length;
|
|
480
|
+
return printable / text.length > 0.8;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function formatBytes(bytes) {
|
|
484
|
+
if (bytes < 1024) return bytes + ' B';
|
|
485
|
+
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
|
|
486
|
+
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// Start the demo
|
|
490
|
+
init().catch(error => {
|
|
491
|
+
log(`❌ Initialization error: ${error.message}`, 'error');
|
|
492
|
+
updateStatus('disconnected', '❌ Failed to initialize');
|
|
493
|
+
});
|
|
494
|
+
</script>
|
|
495
|
+
</body>
|
|
496
|
+
</html>
|