peerpigeon 0.0.5 โ 0.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 +190 -12
- package/examples/browser/app.js +40 -40
- package/examples/browser/crypto-test.html +427 -0
- package/examples/browser/index.html +161 -0
- package/examples/browser/styles.css +216 -0
- package/examples/browser/ui-old.js +1704 -1708
- package/examples/browser/ui.js +2226 -1692
- package/examples/nativescript/README.md +73 -0
- package/examples/nativescript/app.js +152 -0
- package/examples/nativescript/package.json +27 -0
- package/examples/node/test-crypto-media.js +137 -0
- package/examples/node/test-crypto.js +146 -0
- package/examples/node/test-node.js +114 -115
- package/package.json +16 -13
- package/src/CleanupManager.js +154 -154
- package/src/ConnectionManager.js +772 -753
- package/src/CryptoManager.js +612 -0
- package/src/EnvironmentDetector.js +457 -384
- package/src/EventEmitter.js +19 -19
- package/src/EvictionManager.js +211 -211
- package/src/GossipManager.js +447 -366
- package/src/MediaManager.js +216 -214
- package/src/MeshOptimizer.js +165 -166
- package/src/PeerConnection.js +847 -941
- package/src/PeerDiscovery.js +255 -259
- package/src/PeerPigeonMesh.js +1100 -721
- package/src/SignalingClient.js +517 -518
- package/src/SignalingHandler.js +295 -295
- package/src/StorageManager.js +118 -104
- package/src/TimerUtils.js +29 -29
- package/src/WebDHT.js +1123 -948
- package/websocket-server/server.js +360 -362
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://badge.fury.io/js/peerpigeon)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://github.com/draeder/peerpigeon)
|
|
8
|
+
[](https://github.com/draeder/peerpigeon)
|
|
7
9
|
|
|
8
10
|
> **๐ Viewing Diagrams**: This README contains Mermaid diagrams. For proper visualization in VS Code, install the [Markdown Preview Mermaid Support](https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid) extension.
|
|
9
11
|
|
|
@@ -890,15 +892,18 @@ open "http://localhost:8080/examples/browser/?api=wss://your-signaling-server.co
|
|
|
890
892
|
- Force connection utilities for testing
|
|
891
893
|
- Real-time peer discovery and connection monitoring
|
|
892
894
|
|
|
893
|
-
## ๐
|
|
895
|
+
## ๐ Platform Compatibility & Requirements
|
|
894
896
|
|
|
895
|
-
###
|
|
896
|
-
- **WebRTC**: RTCPeerConnection and RTCDataChannel support
|
|
897
|
-
- **ES6 Modules**: Dynamic imports and module syntax
|
|
898
|
-
- **Crypto API**: For cryptographically secure peer ID generation
|
|
899
|
-
- **WebSocket API**: For real-time signaling communication
|
|
897
|
+
### Supported Platforms
|
|
900
898
|
|
|
901
|
-
|
|
899
|
+
| Platform | Environment | WebRTC Support | WebSocket Support | Status |
|
|
900
|
+
|---------|-------------|----------------|-------------------|---------|
|
|
901
|
+
| **Web Browsers** | Modern browsers | โ
Native | โ
Native | **Full Support** |
|
|
902
|
+
| **Node.js** | Server-side | โ ๏ธ Via plugin | โ
Via 'ws' | **Supported** |
|
|
903
|
+
| **NativeScript** | Mobile apps | โ ๏ธ Via plugin | โ
Native/Plugin | **Supported** |
|
|
904
|
+
| **Web Workers** | Browser workers | โ
Limited | โ
Yes | **Basic Support** |
|
|
905
|
+
|
|
906
|
+
### Browser Compatibility
|
|
902
907
|
|
|
903
908
|
| Browser | Minimum Version | WebRTC Support | WebSocket Support | Status |
|
|
904
909
|
|---------|----------------|----------------|-------------------|---------|
|
|
@@ -909,6 +914,38 @@ open "http://localhost:8080/examples/browser/?api=wss://your-signaling-server.co
|
|
|
909
914
|
| **Mobile Chrome** | 80+ | โ
Full | โ
Yes | **Supported** |
|
|
910
915
|
| **Mobile Safari** | 14+ | โ
Full | โ
Yes | **Supported** |
|
|
911
916
|
|
|
917
|
+
### Required Features
|
|
918
|
+
- **WebRTC**: RTCPeerConnection and RTCDataChannel support
|
|
919
|
+
- **ES6 Modules**: Dynamic imports and module syntax
|
|
920
|
+
- **Crypto API**: For cryptographically secure peer ID generation
|
|
921
|
+
- **WebSocket API**: For real-time signaling communication
|
|
922
|
+
|
|
923
|
+
### NativeScript Support
|
|
924
|
+
|
|
925
|
+
PeerPigeon includes comprehensive NativeScript support:
|
|
926
|
+
|
|
927
|
+
```javascript
|
|
928
|
+
// NativeScript usage (same API as browser)
|
|
929
|
+
import { PeerPigeonMesh } from 'peerpigeon';
|
|
930
|
+
|
|
931
|
+
const mesh = new PeerPigeonMesh();
|
|
932
|
+
await mesh.init(); // Automatically detects NativeScript environment
|
|
933
|
+
|
|
934
|
+
// Environment detection
|
|
935
|
+
console.log('Environment:', mesh.environmentReport.runtime);
|
|
936
|
+
// { isNativeScript: true, platform: 'android' }
|
|
937
|
+
```
|
|
938
|
+
|
|
939
|
+
**NativeScript Features:**
|
|
940
|
+
- โ
Environment detection with platform info (Android/iOS/visionOS)
|
|
941
|
+
- โ
WebSocket signaling (native or via plugin)
|
|
942
|
+
- โ
Storage management using NativeScript APIs
|
|
943
|
+
- โ
Basic mesh networking capabilities
|
|
944
|
+
- โ ๏ธ WebRTC requires additional native plugins
|
|
945
|
+
- โ ๏ธ Media features require camera/microphone permissions
|
|
946
|
+
|
|
947
|
+
See the [NativeScript example](examples/nativescript/) for complete setup instructions.
|
|
948
|
+
|
|
912
949
|
### Feature Detection
|
|
913
950
|
|
|
914
951
|
PeerPigeon automatically detects browser capabilities:
|
|
@@ -1093,11 +1130,136 @@ mesh.addEventListener('messageReceived', (event) => {
|
|
|
1093
1130
|
});
|
|
1094
1131
|
```
|
|
1095
1132
|
|
|
1096
|
-
|
|
1133
|
+
## ๐งช Testing & Development
|
|
1134
|
+
|
|
1135
|
+
PeerPigeon includes a comprehensive testing framework with unit tests, integration tests, performance benchmarks, and automated CI/CD pipeline.
|
|
1136
|
+
|
|
1137
|
+
### Quick Start
|
|
1138
|
+
|
|
1139
|
+
```bash
|
|
1140
|
+
# Install dependencies
|
|
1141
|
+
npm install
|
|
1142
|
+
|
|
1143
|
+
# Run all tests
|
|
1144
|
+
npm test
|
|
1145
|
+
|
|
1146
|
+
# Run specific test suites
|
|
1147
|
+
npm run test:unit # Unit tests only
|
|
1148
|
+
npm run test:integration # Integration tests only
|
|
1149
|
+
npm run test:custom # Custom test runners
|
|
1150
|
+
|
|
1151
|
+
# Run with coverage
|
|
1152
|
+
npm run test:coverage
|
|
1153
|
+
|
|
1154
|
+
# Performance benchmarks
|
|
1155
|
+
npm run benchmark
|
|
1156
|
+
|
|
1157
|
+
# Linting
|
|
1158
|
+
npm run lint
|
|
1159
|
+
npm run lint:fix # Auto-fix issues
|
|
1160
|
+
|
|
1161
|
+
# Full CI pipeline
|
|
1162
|
+
npm run ci
|
|
1163
|
+
```
|
|
1164
|
+
|
|
1165
|
+
### Test Structure
|
|
1166
|
+
|
|
1167
|
+
```
|
|
1168
|
+
test/
|
|
1169
|
+
โโโ unit/ # Unit tests (16 tests)
|
|
1170
|
+
โ โโโ crypto.test.js # CryptoManager tests (7 tests)
|
|
1171
|
+
โ โโโ mesh.test.js # PeerPigeonMesh tests (9 tests)
|
|
1172
|
+
โโโ integration/ # Integration tests (7 tests)
|
|
1173
|
+
โ โโโ simple.test.js # Integration scenarios
|
|
1174
|
+
โ โโโ integration-runner.js # Custom test runner
|
|
1175
|
+
โโโ setup.js # Jest configuration
|
|
1176
|
+
โโโ runner.js # Comprehensive test runner
|
|
1177
|
+
โโโ benchmark.js # Performance benchmarks
|
|
1178
|
+
```
|
|
1179
|
+
|
|
1180
|
+
### Testing Framework Features
|
|
1181
|
+
|
|
1182
|
+
- **๐ง Custom Test Runners**: Built-in Node.js test runners for comprehensive testing
|
|
1183
|
+
- **๐ Jest Integration**: Modern testing framework with ES modules support and coverage reporting
|
|
1184
|
+
- **๐ Coverage Reports**: Detailed HTML and LCOV coverage reports
|
|
1185
|
+
- **โก Performance Benchmarks**: Crypto operations, mesh performance, and memory usage
|
|
1186
|
+
- **๐ Linting**: ESLint with standard configuration (0 errors, 0 warnings)
|
|
1187
|
+
- **๐ค CI/CD Pipeline**: Automated testing with proper resource cleanup
|
|
1188
|
+
- **๐ ๏ธ Clean Test Termination**: All tests complete without hanging processes
|
|
1189
|
+
- **โก Fast Execution**: Unit tests ~0.26s, full suite ~1.2s
|
|
1190
|
+
|
|
1191
|
+
### Available Commands
|
|
1192
|
+
|
|
1193
|
+
```bash
|
|
1194
|
+
# Using npm scripts
|
|
1195
|
+
npm test # Jest tests (23/23 passing)
|
|
1196
|
+
npm run test:unit # Unit tests (16/16 passing)
|
|
1197
|
+
npm run test:integration # Integration tests (7/7 passing)
|
|
1198
|
+
npm run test:custom # Custom test runners
|
|
1199
|
+
npm run test:all # Comprehensive test suite
|
|
1200
|
+
npm run test:coverage # Coverage analysis
|
|
1201
|
+
npm run test:watch # Watch mode
|
|
1202
|
+
npm run lint # ESLint (0 errors, 0 warnings)
|
|
1203
|
+
npm run lint:fix # Auto-fix linting issues
|
|
1204
|
+
npm run benchmark # Performance benchmarks
|
|
1205
|
+
npm run ci # Full CI pipeline
|
|
1206
|
+
|
|
1207
|
+
# Using Makefile (shorter commands)
|
|
1208
|
+
make test # Run tests
|
|
1209
|
+
make lint # Run linting
|
|
1210
|
+
make benchmark # Run benchmarks
|
|
1211
|
+
make coverage # Generate coverage
|
|
1212
|
+
make ci # Full CI check
|
|
1213
|
+
make help # Show all commands
|
|
1214
|
+
```
|
|
1215
|
+
|
|
1216
|
+
### Test Categories
|
|
1217
|
+
|
|
1218
|
+
#### Unit Tests (16 tests passing)
|
|
1219
|
+
- **CryptoManager (7 tests)**: Encryption, decryption, key generation, signing
|
|
1220
|
+
- **PeerPigeonMesh (9 tests)**: Core mesh functionality, message routing
|
|
1221
|
+
- **Resource Management**: Timer cleanup, proper disconnection
|
|
1222
|
+
- **Memory Safety**: No memory leaks or hanging processes
|
|
1223
|
+
|
|
1224
|
+
#### Integration Tests (7 tests passing)
|
|
1225
|
+
- **Peer Discovery**: Network join/leave scenarios
|
|
1226
|
+
- **Message Propagation**: End-to-end gossip protocol testing
|
|
1227
|
+
- **Network Resilience**: Connection management and cleanup
|
|
1228
|
+
- **Multi-Peer Scenarios**: Real-world mesh networking tests
|
|
1229
|
+
|
|
1230
|
+
#### Performance Benchmarks
|
|
1231
|
+
- **Crypto Performance**: Key generation, encryption/decryption speed
|
|
1232
|
+
- **Mesh Operations**: Peer connection, message routing efficiency
|
|
1233
|
+
- **Memory Usage**: Memory leak detection, resource management
|
|
1234
|
+
- **Network Performance**: Message throughput, latency analysis
|
|
1235
|
+
|
|
1236
|
+
### Coverage Reports
|
|
1237
|
+
|
|
1238
|
+
After running `npm run test:coverage`, open `coverage/index.html` to view detailed coverage reports including:
|
|
1239
|
+
|
|
1240
|
+
- Line coverage
|
|
1241
|
+
- Function coverage
|
|
1242
|
+
- Branch coverage
|
|
1243
|
+
- Statement coverage
|
|
1244
|
+
|
|
1245
|
+
### Continuous Integration
|
|
1246
|
+
|
|
1247
|
+
The project includes GitHub Actions workflows for:
|
|
1248
|
+
|
|
1249
|
+
- **Multiple Node.js versions** (18.x, 20.x, 22.x)
|
|
1250
|
+
- **Automated testing** on push/PR
|
|
1251
|
+
- **Security audits**
|
|
1252
|
+
- **Performance benchmarking**
|
|
1253
|
+
- **Coverage reporting**
|
|
1254
|
+
|
|
1255
|
+
### Browser Testing Scenarios
|
|
1097
1256
|
|
|
1098
1257
|
#### Multi-Tab Testing
|
|
1099
1258
|
```bash
|
|
1100
|
-
# Open
|
|
1259
|
+
# Open multiple browser tabs for mesh testing
|
|
1260
|
+
npm run dev
|
|
1261
|
+
|
|
1262
|
+
# In separate terminal, open tabs
|
|
1101
1263
|
for i in {1..5}; do
|
|
1102
1264
|
open "http://localhost:8080/examples/browser/?debug=true&tab=$i"
|
|
1103
1265
|
done
|
|
@@ -1105,10 +1267,23 @@ done
|
|
|
1105
1267
|
|
|
1106
1268
|
#### Network Partition Testing
|
|
1107
1269
|
```javascript
|
|
1108
|
-
// Simulate network partition
|
|
1270
|
+
// Simulate network partition in browser console
|
|
1109
1271
|
mesh.disconnectPeer(specificPeerId, 'testing partition');
|
|
1110
1272
|
|
|
1111
|
-
//
|
|
1273
|
+
// Monitor reconnection behavior
|
|
1274
|
+
mesh.on('peerReconnected', (peerId) => {
|
|
1275
|
+
console.log('Peer reconnected after partition:', peerId);
|
|
1276
|
+
});
|
|
1277
|
+
```
|
|
1278
|
+
|
|
1279
|
+
#### Encryption Testing
|
|
1280
|
+
```javascript
|
|
1281
|
+
// Test encryption in browser
|
|
1282
|
+
await mesh.crypto.generateKeyPair();
|
|
1283
|
+
const encrypted = await mesh.encryptMessage('test message', targetPeerId);
|
|
1284
|
+
const decrypted = await mesh.decryptMessage(encrypted, senderPeerId);
|
|
1285
|
+
console.log('Encryption test:', decrypted === 'test message');
|
|
1286
|
+
```
|
|
1112
1287
|
setTimeout(() => {
|
|
1113
1288
|
console.log('Network recovered, connections:', mesh.getConnectedPeerCount());
|
|
1114
1289
|
}, 10000);
|
|
@@ -1181,7 +1356,10 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
1181
1356
|
|
|
1182
1357
|
**Quick Links:**
|
|
1183
1358
|
- [Live Demo](http://localhost:8080/examples/browser/) (after starting local server)
|
|
1359
|
+
- [Browser Examples](examples/browser/) - Complete web-based examples
|
|
1360
|
+
- [Node.js Examples](examples/node/) - Server-side examples
|
|
1361
|
+
- [NativeScript Examples](examples/nativescript/) - Mobile app examples
|
|
1184
1362
|
- [API Documentation](docs/API.md)
|
|
1185
|
-
- [Deployment Guide](docs/DEPLOYMENT.md)
|
|
1363
|
+
- [Deployment Guide](docs/DEPLOYMENT.md)
|
|
1186
1364
|
- [GitHub Issues](https://github.com/danrayadev/pigon/issues)
|
|
1187
1365
|
- [Contributing Guidelines](CONTRIBUTING.md)
|
package/examples/browser/app.js
CHANGED
|
@@ -2,51 +2,51 @@ import { PeerPigeonMesh } from '../../src/PeerPigeonMesh.js';
|
|
|
2
2
|
import { PeerPigeonUI } from './ui.js';
|
|
3
3
|
|
|
4
4
|
class PeerPigeonApp {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
constructor() {
|
|
6
|
+
// Initialize mesh with crypto and WebDHT enabled
|
|
7
|
+
this.mesh = new PeerPigeonMesh({
|
|
8
|
+
enableWebDHT: true,
|
|
9
|
+
enableCrypto: true
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
this.ui = new PeerPigeonUI(this.mesh);
|
|
13
|
+
this.init();
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
16
|
+
async init() {
|
|
17
|
+
try {
|
|
18
|
+
await this.mesh.init();
|
|
19
|
+
this.ui.updateUI();
|
|
20
|
+
this.setupUnloadHandler();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error('Failed to initialize app:', error);
|
|
24
23
|
}
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
setupUnloadHandler() {
|
|
27
|
+
const handleUnload = () => {
|
|
28
|
+
if (this.mesh.connected) {
|
|
29
|
+
this.mesh.sendGoodbyeMessage();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
window.addEventListener('beforeunload', handleUnload);
|
|
34
|
+
window.addEventListener('unload', handleUnload);
|
|
35
|
+
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// Initialize the application
|
|
39
39
|
document.addEventListener('DOMContentLoaded', () => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
40
|
+
const peerPigeonApp = new PeerPigeonApp();
|
|
41
|
+
|
|
42
|
+
// Expose for debugging and global access
|
|
43
|
+
window.peerPigeonApp = peerPigeonApp;
|
|
44
|
+
window.peerPigeonMesh = peerPigeonApp.mesh;
|
|
45
|
+
window.peerPigeonUI = peerPigeonApp.ui;
|
|
46
|
+
window.ui = peerPigeonApp.ui; // Also expose as 'ui' for compatibility with discovered peers buttons
|
|
47
|
+
window.peerPigeonSignaling = peerPigeonApp.mesh.signalingClient;
|
|
48
|
+
window.getPeerPigeonState = () => peerPigeonApp.mesh.getStatus();
|
|
49
|
+
|
|
50
|
+
// Expose PeerPigeonMesh class for static validation in UI
|
|
51
|
+
window.PeerPigeonMesh = PeerPigeonMesh;
|
|
52
|
+
});
|