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
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { createApp } from 'vue'
|
|
2
|
-
import
|
|
2
|
+
import { createPinia } from 'pinia'
|
|
3
|
+
import App from './App.vue'
|
|
4
|
+
import router from './router.js'
|
|
3
5
|
|
|
4
6
|
const app = createApp(App)
|
|
7
|
+
const pinia = createPinia()
|
|
8
|
+
|
|
9
|
+
app.use(pinia)
|
|
10
|
+
app.use(router)
|
|
5
11
|
app.mount('#app')
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { createRouter, createWebHistory } from 'vue-router';
|
|
2
|
+
import NetworkView from './components/NetworkView.vue';
|
|
3
|
+
import MessagingView from './components/MessagingView.vue';
|
|
4
|
+
import MediaView from './components/MediaView.vue';
|
|
5
|
+
import DHTView from './components/DHTView.vue';
|
|
6
|
+
import StorageView from './components/StorageView.vue';
|
|
7
|
+
import CryptoView from './components/CryptoView.vue';
|
|
8
|
+
import DebugView from './components/DebugView.vue';
|
|
9
|
+
import TestingView from './components/TestingView.vue';
|
|
10
|
+
|
|
11
|
+
const routes = [
|
|
12
|
+
{
|
|
13
|
+
path: '/',
|
|
14
|
+
redirect: '/network'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
path: '/network',
|
|
18
|
+
name: 'Network',
|
|
19
|
+
component: NetworkView
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
path: '/messaging',
|
|
23
|
+
name: 'Messaging',
|
|
24
|
+
component: MessagingView
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
path: '/media',
|
|
28
|
+
name: 'Media',
|
|
29
|
+
component: MediaView
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
path: '/dht',
|
|
33
|
+
name: 'DHT',
|
|
34
|
+
component: DHTView
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
path: '/storage',
|
|
38
|
+
name: 'Storage',
|
|
39
|
+
component: StorageView
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
path: '/crypto',
|
|
43
|
+
name: 'Crypto',
|
|
44
|
+
component: CryptoView
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
path: '/debug',
|
|
48
|
+
name: 'Debug',
|
|
49
|
+
component: DebugView
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
path: '/testing',
|
|
53
|
+
name: 'Testing',
|
|
54
|
+
component: TestingView
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const router = createRouter({
|
|
59
|
+
history: createWebHistory(),
|
|
60
|
+
routes
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export default router;
|
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import { defineStore } from 'pinia';
|
|
2
|
-
import { ref, reactive, computed } from 'vue';
|
|
2
|
+
import { ref, reactive, computed, markRaw } from 'vue';
|
|
3
|
+
|
|
4
|
+
// Helper to wait for PeerPigeon to be available
|
|
5
|
+
const waitForPeerPigeon = (maxWait = 5000) => {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const startTime = Date.now();
|
|
8
|
+
const checkInterval = 100;
|
|
9
|
+
|
|
10
|
+
const check = () => {
|
|
11
|
+
if (window.PeerPigeon?.PeerPigeonMesh) {
|
|
12
|
+
console.log('✅ PeerPigeon loaded successfully');
|
|
13
|
+
resolve(window.PeerPigeon);
|
|
14
|
+
} else if (Date.now() - startTime > maxWait) {
|
|
15
|
+
console.error('❌ PeerPigeon failed to load within timeout');
|
|
16
|
+
reject(new Error('PeerPigeon library not available'));
|
|
17
|
+
} else {
|
|
18
|
+
setTimeout(check, checkInterval);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
check();
|
|
23
|
+
});
|
|
24
|
+
};
|
|
3
25
|
|
|
4
26
|
export const usePeerPigeonStore = defineStore('peerpigeon', () => {
|
|
5
|
-
// Core state
|
|
6
|
-
const mesh = ref(null);
|
|
27
|
+
// Core state
|
|
28
|
+
const mesh = ref(null); // Will be wrapped with markRaw to prevent reactivity issues
|
|
7
29
|
const isInitialized = ref(false);
|
|
8
30
|
const isConnected = ref(false);
|
|
9
31
|
const signalingUrl = ref('ws://localhost:3000');
|
|
@@ -20,8 +42,9 @@ export const usePeerPigeonStore = defineStore('peerpigeon', () => {
|
|
|
20
42
|
const discoveredPeers = reactive(new Map());
|
|
21
43
|
const networkStatus = reactive({
|
|
22
44
|
connectedCount: 0,
|
|
23
|
-
maxPeers:
|
|
45
|
+
maxPeers: 4,
|
|
24
46
|
minPeers: 2,
|
|
47
|
+
autoConnect: true,
|
|
25
48
|
autoDiscovery: true,
|
|
26
49
|
evictionStrategy: true,
|
|
27
50
|
xorRouting: true
|
|
@@ -74,10 +97,32 @@ export const usePeerPigeonStore = defineStore('peerpigeon', () => {
|
|
|
74
97
|
// Core methods
|
|
75
98
|
const initMesh = async (options = {}) => {
|
|
76
99
|
try {
|
|
100
|
+
// Wait for PeerPigeon to be available
|
|
101
|
+
addDebugLog('Waiting for PeerPigeon library to load...', 'info');
|
|
102
|
+
|
|
103
|
+
let PeerPigeonLib;
|
|
104
|
+
try {
|
|
105
|
+
PeerPigeonLib = await waitForPeerPigeon();
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error('❌ PeerPigeon not available:', error);
|
|
108
|
+
addDebugLog('PeerPigeon library not found - using mock', 'error');
|
|
109
|
+
PeerPigeonLib = null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Debug: Check if PeerPigeon is available
|
|
113
|
+
console.log('🔍 PeerPigeon availability:', {
|
|
114
|
+
available: !!PeerPigeonLib,
|
|
115
|
+
PeerPigeonMesh: !!(PeerPigeonLib?.PeerPigeonMesh),
|
|
116
|
+
keys: PeerPigeonLib ? Object.keys(PeerPigeonLib) : []
|
|
117
|
+
});
|
|
118
|
+
|
|
77
119
|
// Use real PeerPigeonMesh if available, otherwise mock
|
|
78
|
-
const PeerPigeonMeshClass =
|
|
120
|
+
const PeerPigeonMeshClass = PeerPigeonLib?.PeerPigeonMesh;
|
|
79
121
|
|
|
80
122
|
if (!PeerPigeonMeshClass) {
|
|
123
|
+
console.error('❌ PeerPigeonMesh not found! Using mock implementation.');
|
|
124
|
+
addDebugLog('Using mock PeerPigeon implementation', 'warning');
|
|
125
|
+
|
|
81
126
|
// Fallback to mock implementation for development
|
|
82
127
|
const MockPeerPigeonMesh = class {
|
|
83
128
|
constructor(meshOptions) {
|
|
@@ -215,15 +260,23 @@ export const usePeerPigeonStore = defineStore('peerpigeon', () => {
|
|
|
215
260
|
allowGlobalFallback: allowGlobalFallback.value,
|
|
216
261
|
maxPeers: networkStatus.maxPeers,
|
|
217
262
|
minPeers: networkStatus.minPeers,
|
|
263
|
+
autoConnect: true,
|
|
218
264
|
autoDiscovery: networkStatus.autoDiscovery,
|
|
219
265
|
evictionStrategy: networkStatus.evictionStrategy,
|
|
220
266
|
xorRouting: networkStatus.xorRouting,
|
|
221
267
|
...options
|
|
222
268
|
};
|
|
223
269
|
|
|
224
|
-
mesh.value = new MockPeerPigeonMesh(meshOptions);
|
|
270
|
+
mesh.value = markRaw(new MockPeerPigeonMesh(meshOptions));
|
|
225
271
|
} else {
|
|
226
272
|
// Use real PeerPigeonMesh
|
|
273
|
+
console.log('🚀 Initializing real PeerPigeonMesh with options:', {
|
|
274
|
+
networkName: networkName.value,
|
|
275
|
+
maxPeers: networkStatus.maxPeers,
|
|
276
|
+
autoConnect: true,
|
|
277
|
+
autoDiscovery: networkStatus.autoDiscovery
|
|
278
|
+
});
|
|
279
|
+
|
|
227
280
|
const meshOptions = {
|
|
228
281
|
enableWebDHT: true,
|
|
229
282
|
enableCrypto: true,
|
|
@@ -232,17 +285,22 @@ export const usePeerPigeonStore = defineStore('peerpigeon', () => {
|
|
|
232
285
|
allowGlobalFallback: allowGlobalFallback.value,
|
|
233
286
|
maxPeers: networkStatus.maxPeers,
|
|
234
287
|
minPeers: networkStatus.minPeers,
|
|
288
|
+
autoConnect: true,
|
|
235
289
|
autoDiscovery: networkStatus.autoDiscovery,
|
|
236
290
|
evictionStrategy: networkStatus.evictionStrategy,
|
|
237
291
|
xorRouting: networkStatus.xorRouting,
|
|
238
292
|
...options
|
|
239
293
|
};
|
|
240
294
|
|
|
241
|
-
|
|
295
|
+
// CRITICAL: Use markRaw to prevent Vue from making mesh reactive
|
|
296
|
+
// Vue's Proxy wrapper can interfere with WebRTC connections
|
|
297
|
+
mesh.value = markRaw(new PeerPigeonMeshClass(meshOptions));
|
|
298
|
+
console.log('✅ PeerPigeonMesh instance created (marked as raw)');
|
|
242
299
|
}
|
|
243
300
|
|
|
244
301
|
setupEventHandlers();
|
|
245
302
|
|
|
303
|
+
// Use raw instance for init to avoid Vue proxy issues
|
|
246
304
|
await mesh.value.init();
|
|
247
305
|
isInitialized.value = true;
|
|
248
306
|
peerId.value = mesh.value.peerId;
|
|
@@ -326,6 +384,7 @@ export const usePeerPigeonStore = defineStore('peerpigeon', () => {
|
|
|
326
384
|
});
|
|
327
385
|
|
|
328
386
|
mesh.value.addEventListener('peerConnected', (event) => {
|
|
387
|
+
console.log('🤝 PEER CONNECTED EVENT:', event);
|
|
329
388
|
const peerInfo = {
|
|
330
389
|
id: event.peerId,
|
|
331
390
|
connected: true,
|
|
@@ -338,6 +397,7 @@ export const usePeerPigeonStore = defineStore('peerpigeon', () => {
|
|
|
338
397
|
});
|
|
339
398
|
|
|
340
399
|
mesh.value.addEventListener('peerDisconnected', (event) => {
|
|
400
|
+
console.log('👋 PEER DISCONNECTED EVENT:', event);
|
|
341
401
|
const peer = peers.get(event.peerId);
|
|
342
402
|
if (peer) {
|
|
343
403
|
peer.connected = false;
|
|
@@ -350,6 +410,7 @@ export const usePeerPigeonStore = defineStore('peerpigeon', () => {
|
|
|
350
410
|
});
|
|
351
411
|
|
|
352
412
|
mesh.value.addEventListener('peerDiscovered', (event) => {
|
|
413
|
+
console.log('🔍 PEER DISCOVERED EVENT:', event);
|
|
353
414
|
discoveredPeers.set(event.peerId, {
|
|
354
415
|
id: event.peerId,
|
|
355
416
|
discoveryTime: new Date(),
|
|
@@ -2,5 +2,19 @@ import { defineConfig } from 'vite';
|
|
|
2
2
|
import vue from '@vitejs/plugin-vue';
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
|
-
plugins: [vue()]
|
|
5
|
+
plugins: [vue()],
|
|
6
|
+
server: {
|
|
7
|
+
port: 5173,
|
|
8
|
+
strictPort: false,
|
|
9
|
+
// Use 0.0.0.0 to allow all network interfaces
|
|
10
|
+
host: '0.0.0.0',
|
|
11
|
+
https: false,
|
|
12
|
+
cors: true,
|
|
13
|
+
// Disable HMR to avoid WebSocket conflicts
|
|
14
|
+
hmr: false
|
|
15
|
+
},
|
|
16
|
+
// Prevent Vite from optimizing PeerPigeon library
|
|
17
|
+
optimizeDeps: {
|
|
18
|
+
exclude: ['peerpigeon']
|
|
19
|
+
}
|
|
6
20
|
});
|