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,1048 @@
1
+ <template>
2
+ <div class="media-view">
3
+ <div class="section-header">
4
+ <h2>🎥 Media Streaming</h2>
5
+ <p>Stream audio and video between peers in real-time using WebRTC</p>
6
+ </div>
7
+
8
+ <!-- Media Controls -->
9
+ <div class="media-controls">
10
+ <h3>📹 Local Media Controls</h3>
11
+
12
+ <div class="controls-grid">
13
+ <div class="control-group">
14
+ <h4>Camera & Microphone</h4>
15
+ <div class="control-buttons">
16
+ <button
17
+ @click="startVideo"
18
+ :disabled="!isConnected || mediaState.videoEnabled"
19
+ class="btn btn-primary"
20
+ >
21
+ <span class="btn-icon">📹</span>
22
+ Start Video
23
+ </button>
24
+
25
+ <button
26
+ @click="startAudio"
27
+ :disabled="!isConnected || mediaState.audioEnabled"
28
+ class="btn btn-primary"
29
+ >
30
+ <span class="btn-icon">🎤</span>
31
+ Start Audio
32
+ </button>
33
+
34
+ <button
35
+ @click="startBoth"
36
+ :disabled="!isConnected || (mediaState.audioEnabled && mediaState.videoEnabled)"
37
+ class="btn btn-success"
38
+ >
39
+ <span class="btn-icon">🎬</span>
40
+ Start Both
41
+ </button>
42
+
43
+ <button
44
+ @click="stopAllMedia"
45
+ :disabled="!mediaState.localStream"
46
+ class="btn btn-danger"
47
+ >
48
+ <span class="btn-icon">⏹️</span>
49
+ Stop All
50
+ </button>
51
+ </div>
52
+ </div>
53
+
54
+ <div class="control-group">
55
+ <h4>Stream Controls</h4>
56
+ <div class="control-buttons">
57
+ <button
58
+ @click="toggleVideo"
59
+ :disabled="!mediaState.localStream"
60
+ class="btn btn-secondary"
61
+ >
62
+ <span class="btn-icon">{{ mediaState.videoEnabled ? '📹' : '❌' }}</span>
63
+ {{ mediaState.videoEnabled ? 'Disable Video' : 'Enable Video' }}
64
+ </button>
65
+
66
+ <button
67
+ @click="toggleAudio"
68
+ :disabled="!mediaState.localStream"
69
+ class="btn btn-secondary"
70
+ >
71
+ <span class="btn-icon">{{ mediaState.audioEnabled ? '🎤' : '🔇' }}</span>
72
+ {{ mediaState.audioEnabled ? 'Mute Audio' : 'Unmute Audio' }}
73
+ </button>
74
+ </div>
75
+ </div>
76
+
77
+ <div class="control-group">
78
+ <h4>Device Selection</h4>
79
+ <div class="device-selectors">
80
+ <select v-model="selectedVideoDevice" @change="changeVideoDevice" class="device-select">
81
+ <option value="">Select Camera...</option>
82
+ <option
83
+ v-for="device in videoDevices"
84
+ :key="device.deviceId"
85
+ :value="device.deviceId"
86
+ >
87
+ {{ device.label || `Camera ${device.deviceId.slice(0, 8)}...` }}
88
+ </option>
89
+ </select>
90
+
91
+ <select v-model="selectedAudioDevice" @change="changeAudioDevice" class="device-select">
92
+ <option value="">Select Microphone...</option>
93
+ <option
94
+ v-for="device in audioDevices"
95
+ :key="device.deviceId"
96
+ :value="device.deviceId"
97
+ >
98
+ {{ device.label || `Microphone ${device.deviceId.slice(0, 8)}...` }}
99
+ </option>
100
+ </select>
101
+
102
+ <button @click="refreshDevices" class="btn btn-secondary btn-sm">
103
+ <span class="btn-icon">🔄</span>
104
+ Refresh Devices
105
+ </button>
106
+ </div>
107
+ </div>
108
+ </div>
109
+ </div>
110
+
111
+ <!-- Media Streams Display -->
112
+ <div class="streams-container">
113
+ <!-- Local Stream -->
114
+ <div class="stream-section">
115
+ <h3>📺 Your Stream</h3>
116
+ <div class="local-stream-container">
117
+ <video
118
+ ref="localVideo"
119
+ autoplay
120
+ muted
121
+ playsinline
122
+ class="media-stream local-stream"
123
+ :class="{ active: mediaState.localStream }"
124
+ ></video>
125
+
126
+ <div class="stream-overlay" v-if="!mediaState.localStream">
127
+ <div class="overlay-content">
128
+ <span class="overlay-icon">📷</span>
129
+ <p>No local stream</p>
130
+ <p class="overlay-meta">Start your camera or microphone to see your stream here</p>
131
+ </div>
132
+ </div>
133
+
134
+ <div class="stream-info" v-if="mediaState.localStream">
135
+ <div class="stream-stats">
136
+ <span class="stat">
137
+ <span class="stat-icon">📹</span>
138
+ {{ mediaState.videoEnabled ? 'Video ON' : 'Video OFF' }}
139
+ </span>
140
+ <span class="stat">
141
+ <span class="stat-icon">🎤</span>
142
+ {{ mediaState.audioEnabled ? 'Audio ON' : 'Audio OFF' }}
143
+ </span>
144
+ </div>
145
+ </div>
146
+ </div>
147
+ </div>
148
+
149
+ <!-- Remote Streams -->
150
+ <div class="stream-section">
151
+ <h3>📡 Remote Streams ({{ mediaState.remoteStreams.size }})</h3>
152
+
153
+ <div v-if="mediaState.remoteStreams.size === 0" class="empty-streams">
154
+ <div class="empty-icon">📺</div>
155
+ <p>No remote streams</p>
156
+ <p class="empty-meta">Remote streams from other peers will appear here</p>
157
+ </div>
158
+
159
+ <div class="remote-streams-grid" v-else>
160
+ <div
161
+ v-for="[peerId, streamInfo] in mediaState.remoteStreams"
162
+ :key="peerId"
163
+ class="remote-stream-container"
164
+ >
165
+ <video
166
+ :ref="el => setRemoteVideoRef(el, peerId)"
167
+ autoplay
168
+ playsinline
169
+ class="media-stream remote-stream"
170
+ ></video>
171
+
172
+ <div class="stream-info">
173
+ <div class="peer-info">
174
+ <span class="peer-icon">👤</span>
175
+ {{ peerId.substring(0, 12) }}...
176
+ </div>
177
+ <div class="stream-stats">
178
+ <span class="stream-time">{{ formatDuration(streamInfo.startTime) }}</span>
179
+ </div>
180
+ </div>
181
+ </div>
182
+ </div>
183
+ </div>
184
+ </div>
185
+
186
+ <!-- Media Statistics -->
187
+ <div class="stats-section">
188
+ <h3>📊 Media Statistics</h3>
189
+ <div class="stats-grid">
190
+ <div class="stat-card">
191
+ <div class="stat-icon">📹</div>
192
+ <div class="stat-content">
193
+ <h4>Local Stream</h4>
194
+ <div class="stat-value">{{ mediaState.localStream ? 'Active' : 'Inactive' }}</div>
195
+ <div class="stat-meta">
196
+ Video: {{ mediaState.videoEnabled ? 'ON' : 'OFF' }},
197
+ Audio: {{ mediaState.audioEnabled ? 'ON' : 'OFF' }}
198
+ </div>
199
+ </div>
200
+ </div>
201
+
202
+ <div class="stat-card">
203
+ <div class="stat-icon">📡</div>
204
+ <div class="stat-content">
205
+ <h4>Remote Streams</h4>
206
+ <div class="stat-value">{{ mediaState.remoteStreams.size }}</div>
207
+ <div class="stat-meta">Connected peer streams</div>
208
+ </div>
209
+ </div>
210
+
211
+ <div class="stat-card">
212
+ <div class="stat-icon">🎛️</div>
213
+ <div class="stat-content">
214
+ <h4>Available Devices</h4>
215
+ <div class="stat-value">{{ totalDevices }}</div>
216
+ <div class="stat-meta">
217
+ {{ videoDevices.length }} cameras, {{ audioDevices.length }} mics
218
+ </div>
219
+ </div>
220
+ </div>
221
+
222
+ <div class="stat-card">
223
+ <div class="stat-icon">🔗</div>
224
+ <div class="stat-content">
225
+ <h4>WebRTC Status</h4>
226
+ <div class="stat-value">{{ webrtcStatus }}</div>
227
+ <div class="stat-meta">Real-time communication</div>
228
+ </div>
229
+ </div>
230
+ </div>
231
+ </div>
232
+
233
+ <!-- Advanced Media Features -->
234
+ <div class="advanced-section">
235
+ <h3>🔧 Advanced Media Features</h3>
236
+
237
+ <div class="advanced-features">
238
+ <div class="feature-group">
239
+ <h4>Stream Quality</h4>
240
+ <div class="quality-controls">
241
+ <label>Video Quality:</label>
242
+ <select v-model="videoQuality" @change="updateVideoQuality" class="quality-select">
243
+ <option value="low">Low (320x240)</option>
244
+ <option value="medium">Medium (640x480)</option>
245
+ <option value="high">High (1280x720)</option>
246
+ <option value="ultra">Ultra (1920x1080)</option>
247
+ </select>
248
+ </div>
249
+ </div>
250
+
251
+ <div class="feature-group">
252
+ <h4>Audio Settings</h4>
253
+ <div class="audio-controls">
254
+ <label>
255
+ <input type="checkbox" v-model="echoCancellation" @change="updateAudioSettings">
256
+ Echo Cancellation
257
+ </label>
258
+ <label>
259
+ <input type="checkbox" v-model="noiseSuppression" @change="updateAudioSettings">
260
+ Noise Suppression
261
+ </label>
262
+ </div>
263
+ </div>
264
+
265
+ <div class="feature-group">
266
+ <h4>Screen Sharing</h4>
267
+ <div class="screen-controls">
268
+ <button @click="startScreenShare" :disabled="screenSharing" class="btn btn-secondary">
269
+ <span class="btn-icon">🖥️</span>
270
+ Start Screen Share
271
+ </button>
272
+ <button @click="stopScreenShare" :disabled="!screenSharing" class="btn btn-secondary">
273
+ <span class="btn-icon">⏹️</span>
274
+ Stop Screen Share
275
+ </button>
276
+ </div>
277
+ </div>
278
+
279
+ <div class="feature-group">
280
+ <h4>Recording</h4>
281
+ <div class="recording-controls">
282
+ <button @click="startRecording" :disabled="recording" class="btn btn-secondary">
283
+ <span class="btn-icon">⏺️</span>
284
+ Start Recording
285
+ </button>
286
+ <button @click="stopRecording" :disabled="!recording" class="btn btn-secondary">
287
+ <span class="btn-icon">⏹️</span>
288
+ Stop Recording
289
+ </button>
290
+ <button @click="downloadRecording" :disabled="!recordedBlob" class="btn btn-secondary">
291
+ <span class="btn-icon">💾</span>
292
+ Download
293
+ </button>
294
+ </div>
295
+ </div>
296
+ </div>
297
+ </div>
298
+ </div>
299
+ </template>
300
+
301
+ <script setup>
302
+ import { ref, computed, onMounted, onUnmounted, nextTick, watch } from 'vue';
303
+ import { usePeerPigeonStore } from '../stores/peerpigeon.js';
304
+
305
+ const store = usePeerPigeonStore();
306
+
307
+ // Local reactive state
308
+ const localVideo = ref(null);
309
+ const remoteVideoRefs = ref(new Map());
310
+ const selectedVideoDevice = ref('');
311
+ const selectedAudioDevice = ref('');
312
+ const videoDevices = ref([]);
313
+ const audioDevices = ref([]);
314
+ const videoQuality = ref('medium');
315
+ const echoCancellation = ref(true);
316
+ const noiseSuppression = ref(true);
317
+ const screenSharing = ref(false);
318
+ const recording = ref(false);
319
+ const recordedBlob = ref(null);
320
+ const mediaRecorder = ref(null);
321
+
322
+ // Computed properties
323
+ const mediaState = computed(() => store.mediaState);
324
+ const isConnected = computed(() => store.isConnected);
325
+
326
+ const totalDevices = computed(() => {
327
+ return videoDevices.value.length + audioDevices.value.length;
328
+ });
329
+
330
+ const webrtcStatus = computed(() => {
331
+ return 'RTCPeerConnection' in window ? 'Supported' : 'Not Supported';
332
+ });
333
+
334
+ // Methods
335
+ const startVideo = async () => {
336
+ try {
337
+ await store.startMedia({ video: true, audio: false });
338
+ updateLocalVideo();
339
+ } catch (error) {
340
+ store.addDebugLog(`Failed to start video: ${error.message}`, 'error');
341
+ }
342
+ };
343
+
344
+ const startAudio = async () => {
345
+ try {
346
+ await store.startMedia({ video: false, audio: true });
347
+ } catch (error) {
348
+ store.addDebugLog(`Failed to start audio: ${error.message}`, 'error');
349
+ }
350
+ };
351
+
352
+ const startBoth = async () => {
353
+ try {
354
+ await store.startMedia({ video: true, audio: true });
355
+ updateLocalVideo();
356
+ } catch (error) {
357
+ store.addDebugLog(`Failed to start media: ${error.message}`, 'error');
358
+ }
359
+ };
360
+
361
+ const stopAllMedia = async () => {
362
+ try {
363
+ await store.stopMedia();
364
+ if (localVideo.value) {
365
+ localVideo.value.srcObject = null;
366
+ }
367
+ } catch (error) {
368
+ store.addDebugLog(`Failed to stop media: ${error.message}`, 'error');
369
+ }
370
+ };
371
+
372
+ const toggleVideo = () => {
373
+ if (store.mesh) {
374
+ store.mesh.toggleVideo();
375
+ store.addDebugLog(`Video ${mediaState.value.videoEnabled ? 'disabled' : 'enabled'}`);
376
+ }
377
+ };
378
+
379
+ const toggleAudio = () => {
380
+ if (store.mesh) {
381
+ store.mesh.toggleAudio();
382
+ store.addDebugLog(`Audio ${mediaState.value.audioEnabled ? 'disabled' : 'enabled'}`);
383
+ }
384
+ };
385
+
386
+ const updateLocalVideo = async () => {
387
+ await nextTick();
388
+ if (localVideo.value && mediaState.value.localStream) {
389
+ localVideo.value.srcObject = mediaState.value.localStream;
390
+ }
391
+ };
392
+
393
+ const setRemoteVideoRef = (el, peerId) => {
394
+ if (el) {
395
+ remoteVideoRefs.value.set(peerId, el);
396
+ const streamInfo = mediaState.value.remoteStreams.get(peerId);
397
+ if (streamInfo && streamInfo.stream) {
398
+ el.srcObject = streamInfo.stream;
399
+ }
400
+ }
401
+ };
402
+
403
+ const refreshDevices = async () => {
404
+ try {
405
+ const devices = await navigator.mediaDevices.enumerateDevices();
406
+ videoDevices.value = devices.filter(device => device.kind === 'videoinput');
407
+ audioDevices.value = devices.filter(device => device.kind === 'audioinput');
408
+ store.addDebugLog(`Found ${devices.length} media devices`, 'info');
409
+ } catch (error) {
410
+ store.addDebugLog(`Failed to enumerate devices: ${error.message}`, 'error');
411
+ }
412
+ };
413
+
414
+ const changeVideoDevice = async () => {
415
+ if (selectedVideoDevice.value && mediaState.value.localStream) {
416
+ try {
417
+ // Stop current stream and start with new device
418
+ await stopAllMedia();
419
+ await store.startMedia({
420
+ video: { deviceId: selectedVideoDevice.value },
421
+ audio: mediaState.value.audioEnabled
422
+ });
423
+ updateLocalVideo();
424
+ } catch (error) {
425
+ store.addDebugLog(`Failed to change video device: ${error.message}`, 'error');
426
+ }
427
+ }
428
+ };
429
+
430
+ const changeAudioDevice = async () => {
431
+ if (selectedAudioDevice.value && mediaState.value.localStream) {
432
+ try {
433
+ // Stop current stream and start with new device
434
+ await stopAllMedia();
435
+ await store.startMedia({
436
+ video: mediaState.value.videoEnabled,
437
+ audio: { deviceId: selectedAudioDevice.value }
438
+ });
439
+ updateLocalVideo();
440
+ } catch (error) {
441
+ store.addDebugLog(`Failed to change audio device: ${error.message}`, 'error');
442
+ }
443
+ }
444
+ };
445
+
446
+ const updateVideoQuality = async () => {
447
+ if (mediaState.value.localStream && mediaState.value.videoEnabled) {
448
+ const constraints = getVideoConstraints();
449
+ try {
450
+ const videoTrack = mediaState.value.localStream.getVideoTracks()[0];
451
+ await videoTrack.applyConstraints(constraints);
452
+ store.addDebugLog(`Video quality updated to ${videoQuality.value}`, 'info');
453
+ } catch (error) {
454
+ store.addDebugLog(`Failed to update video quality: ${error.message}`, 'error');
455
+ }
456
+ }
457
+ };
458
+
459
+ const updateAudioSettings = async () => {
460
+ if (mediaState.value.localStream && mediaState.value.audioEnabled) {
461
+ const constraints = {
462
+ echoCancellation: echoCancellation.value,
463
+ noiseSuppression: noiseSuppression.value
464
+ };
465
+
466
+ try {
467
+ const audioTrack = mediaState.value.localStream.getAudioTracks()[0];
468
+ await audioTrack.applyConstraints(constraints);
469
+ store.addDebugLog('Audio settings updated', 'info');
470
+ } catch (error) {
471
+ store.addDebugLog(`Failed to update audio settings: ${error.message}`, 'error');
472
+ }
473
+ }
474
+ };
475
+
476
+ const getVideoConstraints = () => {
477
+ const qualityMap = {
478
+ low: { width: 320, height: 240 },
479
+ medium: { width: 640, height: 480 },
480
+ high: { width: 1280, height: 720 },
481
+ ultra: { width: 1920, height: 1080 }
482
+ };
483
+
484
+ return qualityMap[videoQuality.value] || qualityMap.medium;
485
+ };
486
+
487
+ const startScreenShare = async () => {
488
+ try {
489
+ const stream = await navigator.mediaDevices.getDisplayMedia({
490
+ video: true,
491
+ audio: true
492
+ });
493
+
494
+ // Replace video track in local stream
495
+ if (mediaState.value.localStream) {
496
+ const videoTrack = stream.getVideoTracks()[0];
497
+ const sender = store.mesh?.connectionManager?.getAllConnections()
498
+ .find(conn => conn.peerConnection?.getSenders)
499
+ ?.peerConnection?.getSenders()
500
+ .find(s => s.track?.kind === 'video');
501
+
502
+ if (sender) {
503
+ await sender.replaceTrack(videoTrack);
504
+ }
505
+ }
506
+
507
+ screenSharing.value = true;
508
+ store.addDebugLog('Screen sharing started', 'success');
509
+
510
+ // Handle screen share end
511
+ stream.getVideoTracks()[0].onended = () => {
512
+ screenSharing.value = false;
513
+ store.addDebugLog('Screen sharing ended', 'info');
514
+ };
515
+ } catch (error) {
516
+ store.addDebugLog(`Failed to start screen share: ${error.message}`, 'error');
517
+ }
518
+ };
519
+
520
+ const stopScreenShare = async () => {
521
+ try {
522
+ // Switch back to camera
523
+ if (mediaState.value.videoEnabled) {
524
+ const stream = await navigator.mediaDevices.getUserMedia({
525
+ video: true,
526
+ audio: false
527
+ });
528
+
529
+ const videoTrack = stream.getVideoTracks()[0];
530
+ const sender = store.mesh?.connectionManager?.getAllConnections()
531
+ .find(conn => conn.peerConnection?.getSenders)
532
+ ?.peerConnection?.getSenders()
533
+ .find(s => s.track?.kind === 'video');
534
+
535
+ if (sender) {
536
+ await sender.replaceTrack(videoTrack);
537
+ }
538
+ }
539
+
540
+ screenSharing.value = false;
541
+ store.addDebugLog('Screen sharing stopped', 'info');
542
+ } catch (error) {
543
+ store.addDebugLog(`Failed to stop screen share: ${error.message}`, 'error');
544
+ }
545
+ };
546
+
547
+ const startRecording = () => {
548
+ if (!mediaState.value.localStream) {
549
+ store.addDebugLog('No local stream to record', 'error');
550
+ return;
551
+ }
552
+
553
+ try {
554
+ const chunks = [];
555
+ mediaRecorder.value = new MediaRecorder(mediaState.value.localStream);
556
+
557
+ mediaRecorder.value.ondataavailable = (event) => {
558
+ if (event.data.size > 0) {
559
+ chunks.push(event.data);
560
+ }
561
+ };
562
+
563
+ mediaRecorder.value.onstop = () => {
564
+ recordedBlob.value = new Blob(chunks, { type: 'video/webm' });
565
+ recording.value = false;
566
+ store.addDebugLog('Recording stopped', 'info');
567
+ };
568
+
569
+ mediaRecorder.value.start();
570
+ recording.value = true;
571
+ store.addDebugLog('Recording started', 'success');
572
+ } catch (error) {
573
+ store.addDebugLog(`Failed to start recording: ${error.message}`, 'error');
574
+ }
575
+ };
576
+
577
+ const stopRecording = () => {
578
+ if (mediaRecorder.value && recording.value) {
579
+ mediaRecorder.value.stop();
580
+ }
581
+ };
582
+
583
+ const downloadRecording = () => {
584
+ if (recordedBlob.value) {
585
+ const url = URL.createObjectURL(recordedBlob.value);
586
+ const a = document.createElement('a');
587
+ a.style.display = 'none';
588
+ a.href = url;
589
+ a.download = `peerpigeon-recording-${Date.now()}.webm`;
590
+ document.body.appendChild(a);
591
+ a.click();
592
+ document.body.removeChild(a);
593
+ URL.revokeObjectURL(url);
594
+ store.addDebugLog('Recording downloaded', 'success');
595
+ }
596
+ };
597
+
598
+ const formatDuration = (startTime) => {
599
+ if (!startTime) return '00:00';
600
+ const now = new Date();
601
+ const diff = Math.floor((now - startTime) / 1000);
602
+ const minutes = Math.floor(diff / 60);
603
+ const seconds = diff % 60;
604
+ return `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
605
+ };
606
+
607
+ // Watch for local stream changes
608
+ watch(() => mediaState.value.localStream, (newStream) => {
609
+ if (newStream && localVideo.value) {
610
+ localVideo.value.srcObject = newStream;
611
+ }
612
+ });
613
+
614
+ // Watch for remote stream changes
615
+ watch(() => mediaState.value.remoteStreams, (newStreams) => {
616
+ for (const [peerId, streamInfo] of newStreams) {
617
+ const videoEl = remoteVideoRefs.value.get(peerId);
618
+ if (videoEl && streamInfo.stream) {
619
+ videoEl.srcObject = streamInfo.stream;
620
+ }
621
+ }
622
+ }, { deep: true });
623
+
624
+ onMounted(async () => {
625
+ await refreshDevices();
626
+
627
+ // Update devices when permissions are granted
628
+ navigator.mediaDevices.addEventListener('devicechange', refreshDevices);
629
+ });
630
+
631
+ onUnmounted(() => {
632
+ navigator.mediaDevices.removeEventListener('devicechange', refreshDevices);
633
+
634
+ if (recording.value) {
635
+ stopRecording();
636
+ }
637
+ });
638
+ </script>
639
+
640
+ <style scoped>
641
+ .media-view {
642
+ max-width: 1200px;
643
+ margin: 0 auto;
644
+ }
645
+
646
+ .section-header {
647
+ text-align: center;
648
+ margin-bottom: 30px;
649
+ }
650
+
651
+ .section-header h2 {
652
+ font-size: 28px;
653
+ color: #333;
654
+ margin-bottom: 8px;
655
+ }
656
+
657
+ .section-header p {
658
+ color: #666;
659
+ font-size: 16px;
660
+ }
661
+
662
+ .media-controls {
663
+ background: white;
664
+ border-radius: 12px;
665
+ padding: 24px;
666
+ margin-bottom: 30px;
667
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
668
+ }
669
+
670
+ .media-controls h3 {
671
+ margin: 0 0 20px 0;
672
+ color: #333;
673
+ }
674
+
675
+ .controls-grid {
676
+ display: grid;
677
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
678
+ gap: 24px;
679
+ }
680
+
681
+ .control-group h4 {
682
+ margin: 0 0 12px 0;
683
+ color: #555;
684
+ font-size: 16px;
685
+ }
686
+
687
+ .control-buttons {
688
+ display: flex;
689
+ flex-wrap: wrap;
690
+ gap: 8px;
691
+ }
692
+
693
+ .device-selectors {
694
+ display: flex;
695
+ flex-direction: column;
696
+ gap: 8px;
697
+ }
698
+
699
+ .device-select {
700
+ padding: 6px 10px;
701
+ border: 1px solid #ddd;
702
+ border-radius: 4px;
703
+ font-size: 13px;
704
+ }
705
+
706
+ .quality-select {
707
+ padding: 6px 10px;
708
+ border: 1px solid #ddd;
709
+ border-radius: 4px;
710
+ font-size: 13px;
711
+ margin-left: 8px;
712
+ }
713
+
714
+ .btn {
715
+ padding: 8px 12px;
716
+ border: none;
717
+ border-radius: 6px;
718
+ font-size: 13px;
719
+ font-weight: 500;
720
+ cursor: pointer;
721
+ transition: all 0.2s;
722
+ display: flex;
723
+ align-items: center;
724
+ gap: 6px;
725
+ white-space: nowrap;
726
+ }
727
+
728
+ .btn:disabled {
729
+ opacity: 0.6;
730
+ cursor: not-allowed;
731
+ }
732
+
733
+ .btn-primary {
734
+ background: #3b82f6;
735
+ color: white;
736
+ }
737
+
738
+ .btn-primary:hover:not(:disabled) {
739
+ background: #2563eb;
740
+ }
741
+
742
+ .btn-secondary {
743
+ background: #6b7280;
744
+ color: white;
745
+ }
746
+
747
+ .btn-secondary:hover:not(:disabled) {
748
+ background: #4b5563;
749
+ }
750
+
751
+ .btn-success {
752
+ background: #10b981;
753
+ color: white;
754
+ }
755
+
756
+ .btn-success:hover:not(:disabled) {
757
+ background: #059669;
758
+ }
759
+
760
+ .btn-danger {
761
+ background: #ef4444;
762
+ color: white;
763
+ }
764
+
765
+ .btn-danger:hover:not(:disabled) {
766
+ background: #dc2626;
767
+ }
768
+
769
+ .btn-sm {
770
+ padding: 4px 8px;
771
+ font-size: 11px;
772
+ }
773
+
774
+ .btn-icon {
775
+ font-size: 14px;
776
+ }
777
+
778
+ .streams-container {
779
+ display: grid;
780
+ grid-template-columns: 1fr 1fr;
781
+ gap: 30px;
782
+ margin-bottom: 30px;
783
+ }
784
+
785
+ .stream-section {
786
+ background: white;
787
+ border-radius: 12px;
788
+ padding: 24px;
789
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
790
+ }
791
+
792
+ .stream-section h3 {
793
+ margin: 0 0 20px 0;
794
+ color: #333;
795
+ }
796
+
797
+ .local-stream-container {
798
+ position: relative;
799
+ background: #000;
800
+ border-radius: 8px;
801
+ overflow: hidden;
802
+ aspect-ratio: 16/9;
803
+ }
804
+
805
+ .media-stream {
806
+ width: 100%;
807
+ height: 100%;
808
+ object-fit: cover;
809
+ background: #000;
810
+ }
811
+
812
+ .media-stream.local-stream {
813
+ transform: scaleX(-1); /* Mirror local video */
814
+ }
815
+
816
+ .stream-overlay {
817
+ position: absolute;
818
+ top: 0;
819
+ left: 0;
820
+ right: 0;
821
+ bottom: 0;
822
+ display: flex;
823
+ align-items: center;
824
+ justify-content: center;
825
+ background: rgba(0, 0, 0, 0.8);
826
+ color: white;
827
+ }
828
+
829
+ .overlay-content {
830
+ text-align: center;
831
+ }
832
+
833
+ .overlay-icon {
834
+ font-size: 48px;
835
+ display: block;
836
+ margin-bottom: 16px;
837
+ }
838
+
839
+ .overlay-content p {
840
+ margin: 0 0 8px 0;
841
+ }
842
+
843
+ .overlay-meta {
844
+ font-size: 14px;
845
+ color: #ccc;
846
+ }
847
+
848
+ .stream-info {
849
+ position: absolute;
850
+ bottom: 0;
851
+ left: 0;
852
+ right: 0;
853
+ background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
854
+ color: white;
855
+ padding: 16px;
856
+ }
857
+
858
+ .stream-stats {
859
+ display: flex;
860
+ gap: 16px;
861
+ }
862
+
863
+ .stat {
864
+ display: flex;
865
+ align-items: center;
866
+ gap: 6px;
867
+ font-size: 14px;
868
+ }
869
+
870
+ .stat-icon {
871
+ font-size: 16px;
872
+ }
873
+
874
+ .peer-info {
875
+ display: flex;
876
+ align-items: center;
877
+ gap: 8px;
878
+ margin-bottom: 8px;
879
+ font-weight: 500;
880
+ }
881
+
882
+ .peer-icon {
883
+ font-size: 16px;
884
+ }
885
+
886
+ .stream-time {
887
+ font-size: 12px;
888
+ color: #ccc;
889
+ }
890
+
891
+ .empty-streams {
892
+ text-align: center;
893
+ padding: 60px 20px;
894
+ color: #666;
895
+ }
896
+
897
+ .empty-icon {
898
+ font-size: 48px;
899
+ margin-bottom: 16px;
900
+ }
901
+
902
+ .empty-streams p {
903
+ margin: 0 0 8px 0;
904
+ }
905
+
906
+ .empty-meta {
907
+ font-size: 14px;
908
+ color: #999;
909
+ }
910
+
911
+ .remote-streams-grid {
912
+ display: grid;
913
+ grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
914
+ gap: 16px;
915
+ }
916
+
917
+ .remote-stream-container {
918
+ position: relative;
919
+ background: #000;
920
+ border-radius: 8px;
921
+ overflow: hidden;
922
+ aspect-ratio: 16/9;
923
+ }
924
+
925
+ .stats-section {
926
+ background: white;
927
+ border-radius: 12px;
928
+ padding: 24px;
929
+ margin-bottom: 30px;
930
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
931
+ }
932
+
933
+ .stats-section h3 {
934
+ margin: 0 0 20px 0;
935
+ color: #333;
936
+ }
937
+
938
+ .stats-grid {
939
+ display: grid;
940
+ grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
941
+ gap: 20px;
942
+ }
943
+
944
+ .stat-card {
945
+ display: flex;
946
+ align-items: center;
947
+ gap: 16px;
948
+ padding: 20px;
949
+ background: #f8f9fa;
950
+ border-radius: 8px;
951
+ border: 1px solid #eee;
952
+ }
953
+
954
+ .stat-icon {
955
+ font-size: 32px;
956
+ opacity: 0.8;
957
+ }
958
+
959
+ .stat-content h4 {
960
+ margin: 0 0 8px 0;
961
+ font-size: 14px;
962
+ color: #666;
963
+ text-transform: uppercase;
964
+ letter-spacing: 0.5px;
965
+ }
966
+
967
+ .stat-value {
968
+ font-size: 24px;
969
+ font-weight: 600;
970
+ color: #333;
971
+ margin-bottom: 4px;
972
+ }
973
+
974
+ .stat-meta {
975
+ font-size: 12px;
976
+ color: #999;
977
+ }
978
+
979
+ .advanced-section {
980
+ background: white;
981
+ border-radius: 12px;
982
+ padding: 24px;
983
+ box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
984
+ }
985
+
986
+ .advanced-section h3 {
987
+ margin: 0 0 20px 0;
988
+ color: #333;
989
+ }
990
+
991
+ .advanced-features {
992
+ display: grid;
993
+ grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
994
+ gap: 24px;
995
+ }
996
+
997
+ .feature-group h4 {
998
+ margin: 0 0 12px 0;
999
+ color: #555;
1000
+ font-size: 16px;
1001
+ }
1002
+
1003
+ .quality-controls {
1004
+ display: flex;
1005
+ align-items: center;
1006
+ gap: 8px;
1007
+ }
1008
+
1009
+ .audio-controls {
1010
+ display: flex;
1011
+ flex-direction: column;
1012
+ gap: 8px;
1013
+ }
1014
+
1015
+ .audio-controls label {
1016
+ display: flex;
1017
+ align-items: center;
1018
+ gap: 8px;
1019
+ font-size: 14px;
1020
+ cursor: pointer;
1021
+ }
1022
+
1023
+ .screen-controls,
1024
+ .recording-controls {
1025
+ display: flex;
1026
+ flex-wrap: wrap;
1027
+ gap: 8px;
1028
+ }
1029
+
1030
+ /* Responsive design */
1031
+ @media (max-width: 768px) {
1032
+ .streams-container {
1033
+ grid-template-columns: 1fr;
1034
+ }
1035
+
1036
+ .controls-grid {
1037
+ grid-template-columns: 1fr;
1038
+ }
1039
+
1040
+ .control-buttons {
1041
+ justify-content: center;
1042
+ }
1043
+
1044
+ .remote-streams-grid {
1045
+ grid-template-columns: 1fr;
1046
+ }
1047
+ }
1048
+ </style>