agentic-qe 2.7.4 → 2.8.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.
- package/CHANGELOG.md +104 -0
- package/README.md +67 -2
- package/dist/cli/commands/agent/spawn.d.ts +12 -1
- package/dist/cli/commands/agent/spawn.d.ts.map +1 -1
- package/dist/cli/commands/agent/spawn.js +95 -8
- package/dist/cli/commands/agent/spawn.js.map +1 -1
- package/dist/cli/index.js +91 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/core/memory/HNSWVectorMemory.js +1 -1
- package/dist/edge/adapters/BrowserHNSWAdapter.d.ts +134 -0
- package/dist/edge/adapters/BrowserHNSWAdapter.d.ts.map +1 -0
- package/dist/edge/adapters/BrowserHNSWAdapter.js +484 -0
- package/dist/edge/adapters/BrowserHNSWAdapter.js.map +1 -0
- package/dist/edge/adapters/IndexedDBStorage.d.ts +114 -0
- package/dist/edge/adapters/IndexedDBStorage.d.ts.map +1 -0
- package/dist/edge/adapters/IndexedDBStorage.js +478 -0
- package/dist/edge/adapters/IndexedDBStorage.js.map +1 -0
- package/dist/edge/adapters/index.d.ts +12 -0
- package/dist/edge/adapters/index.d.ts.map +1 -0
- package/dist/edge/adapters/index.js +22 -0
- package/dist/edge/adapters/index.js.map +1 -0
- package/dist/edge/browser/BrowserAgent.d.ts +241 -0
- package/dist/edge/browser/BrowserAgent.d.ts.map +1 -0
- package/dist/edge/browser/BrowserAgent.js +743 -0
- package/dist/edge/browser/BrowserAgent.js.map +1 -0
- package/dist/edge/index.d.ts +34 -0
- package/dist/edge/index.d.ts.map +1 -0
- package/dist/edge/index.js +114 -0
- package/dist/edge/index.js.map +1 -0
- package/dist/edge/p2p/coordination/CoordinationManager.d.ts +181 -0
- package/dist/edge/p2p/coordination/CoordinationManager.d.ts.map +1 -0
- package/dist/edge/p2p/coordination/CoordinationManager.js +851 -0
- package/dist/edge/p2p/coordination/CoordinationManager.js.map +1 -0
- package/dist/edge/p2p/coordination/HealthMonitor.d.ts +143 -0
- package/dist/edge/p2p/coordination/HealthMonitor.d.ts.map +1 -0
- package/dist/edge/p2p/coordination/HealthMonitor.js +432 -0
- package/dist/edge/p2p/coordination/HealthMonitor.js.map +1 -0
- package/dist/edge/p2p/coordination/SyncOrchestrator.d.ts +146 -0
- package/dist/edge/p2p/coordination/SyncOrchestrator.d.ts.map +1 -0
- package/dist/edge/p2p/coordination/SyncOrchestrator.js +783 -0
- package/dist/edge/p2p/coordination/SyncOrchestrator.js.map +1 -0
- package/dist/edge/p2p/coordination/index.d.ts +70 -0
- package/dist/edge/p2p/coordination/index.d.ts.map +1 -0
- package/dist/edge/p2p/coordination/index.js +107 -0
- package/dist/edge/p2p/coordination/index.js.map +1 -0
- package/dist/edge/p2p/coordination/types.d.ts +572 -0
- package/dist/edge/p2p/coordination/types.d.ts.map +1 -0
- package/dist/edge/p2p/coordination/types.js +366 -0
- package/dist/edge/p2p/coordination/types.js.map +1 -0
- package/dist/edge/p2p/crdt/CRDTStore.d.ts +324 -0
- package/dist/edge/p2p/crdt/CRDTStore.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/CRDTStore.js +839 -0
- package/dist/edge/p2p/crdt/CRDTStore.js.map +1 -0
- package/dist/edge/p2p/crdt/GCounter.d.ts +173 -0
- package/dist/edge/p2p/crdt/GCounter.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/GCounter.js +394 -0
- package/dist/edge/p2p/crdt/GCounter.js.map +1 -0
- package/dist/edge/p2p/crdt/LWWRegister.d.ts +200 -0
- package/dist/edge/p2p/crdt/LWWRegister.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/LWWRegister.js +456 -0
- package/dist/edge/p2p/crdt/LWWRegister.js.map +1 -0
- package/dist/edge/p2p/crdt/ORSet.d.ts +232 -0
- package/dist/edge/p2p/crdt/ORSet.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/ORSet.js +723 -0
- package/dist/edge/p2p/crdt/ORSet.js.map +1 -0
- package/dist/edge/p2p/crdt/PatternCRDT.d.ts +366 -0
- package/dist/edge/p2p/crdt/PatternCRDT.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/PatternCRDT.js +838 -0
- package/dist/edge/p2p/crdt/PatternCRDT.js.map +1 -0
- package/dist/edge/p2p/crdt/VectorClock.d.ts +274 -0
- package/dist/edge/p2p/crdt/VectorClock.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/VectorClock.js +499 -0
- package/dist/edge/p2p/crdt/VectorClock.js.map +1 -0
- package/dist/edge/p2p/crdt/index.d.ts +87 -0
- package/dist/edge/p2p/crdt/index.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/index.js +120 -0
- package/dist/edge/p2p/crdt/index.js.map +1 -0
- package/dist/edge/p2p/crdt/types.d.ts +667 -0
- package/dist/edge/p2p/crdt/types.d.ts.map +1 -0
- package/dist/edge/p2p/crdt/types.js +208 -0
- package/dist/edge/p2p/crdt/types.js.map +1 -0
- package/dist/edge/p2p/crypto/Identity.d.ts +139 -0
- package/dist/edge/p2p/crypto/Identity.d.ts.map +1 -0
- package/dist/edge/p2p/crypto/Identity.js +449 -0
- package/dist/edge/p2p/crypto/Identity.js.map +1 -0
- package/dist/edge/p2p/crypto/KeyManager.d.ts +196 -0
- package/dist/edge/p2p/crypto/KeyManager.d.ts.map +1 -0
- package/dist/edge/p2p/crypto/KeyManager.js +576 -0
- package/dist/edge/p2p/crypto/KeyManager.js.map +1 -0
- package/dist/edge/p2p/crypto/Signer.d.ts +164 -0
- package/dist/edge/p2p/crypto/Signer.d.ts.map +1 -0
- package/dist/edge/p2p/crypto/Signer.js +357 -0
- package/dist/edge/p2p/crypto/Signer.js.map +1 -0
- package/dist/edge/p2p/crypto/index.d.ts +90 -0
- package/dist/edge/p2p/crypto/index.d.ts.map +1 -0
- package/dist/edge/p2p/crypto/index.js +158 -0
- package/dist/edge/p2p/crypto/index.js.map +1 -0
- package/dist/edge/p2p/crypto/types.d.ts +217 -0
- package/dist/edge/p2p/crypto/types.d.ts.map +1 -0
- package/dist/edge/p2p/crypto/types.js +42 -0
- package/dist/edge/p2p/crypto/types.js.map +1 -0
- package/dist/edge/p2p/federated/FederatedCoordinator.d.ts +270 -0
- package/dist/edge/p2p/federated/FederatedCoordinator.d.ts.map +1 -0
- package/dist/edge/p2p/federated/FederatedCoordinator.js +824 -0
- package/dist/edge/p2p/federated/FederatedCoordinator.js.map +1 -0
- package/dist/edge/p2p/federated/FederatedRound.d.ts +295 -0
- package/dist/edge/p2p/federated/FederatedRound.d.ts.map +1 -0
- package/dist/edge/p2p/federated/FederatedRound.js +819 -0
- package/dist/edge/p2p/federated/FederatedRound.js.map +1 -0
- package/dist/edge/p2p/federated/GradientAggregator.d.ts +226 -0
- package/dist/edge/p2p/federated/GradientAggregator.d.ts.map +1 -0
- package/dist/edge/p2p/federated/GradientAggregator.js +826 -0
- package/dist/edge/p2p/federated/GradientAggregator.js.map +1 -0
- package/dist/edge/p2p/federated/ModelManager.d.ts +248 -0
- package/dist/edge/p2p/federated/ModelManager.d.ts.map +1 -0
- package/dist/edge/p2p/federated/ModelManager.js +724 -0
- package/dist/edge/p2p/federated/ModelManager.js.map +1 -0
- package/dist/edge/p2p/federated/index.d.ts +65 -0
- package/dist/edge/p2p/federated/index.d.ts.map +1 -0
- package/dist/edge/p2p/federated/index.js +110 -0
- package/dist/edge/p2p/federated/index.js.map +1 -0
- package/dist/edge/p2p/federated/types.d.ts +905 -0
- package/dist/edge/p2p/federated/types.d.ts.map +1 -0
- package/dist/edge/p2p/federated/types.js +339 -0
- package/dist/edge/p2p/federated/types.js.map +1 -0
- package/dist/edge/p2p/index.d.ts +156 -0
- package/dist/edge/p2p/index.d.ts.map +1 -0
- package/dist/edge/p2p/index.js +242 -0
- package/dist/edge/p2p/index.js.map +1 -0
- package/dist/edge/p2p/nat/ConnectivityTester.d.ts +128 -0
- package/dist/edge/p2p/nat/ConnectivityTester.d.ts.map +1 -0
- package/dist/edge/p2p/nat/ConnectivityTester.js +560 -0
- package/dist/edge/p2p/nat/ConnectivityTester.js.map +1 -0
- package/dist/edge/p2p/nat/HolePuncher.d.ts +159 -0
- package/dist/edge/p2p/nat/HolePuncher.d.ts.map +1 -0
- package/dist/edge/p2p/nat/HolePuncher.js +569 -0
- package/dist/edge/p2p/nat/HolePuncher.js.map +1 -0
- package/dist/edge/p2p/nat/NATDetector.d.ts +109 -0
- package/dist/edge/p2p/nat/NATDetector.d.ts.map +1 -0
- package/dist/edge/p2p/nat/NATDetector.js +472 -0
- package/dist/edge/p2p/nat/NATDetector.js.map +1 -0
- package/dist/edge/p2p/nat/TURNManager.d.ts +158 -0
- package/dist/edge/p2p/nat/TURNManager.d.ts.map +1 -0
- package/dist/edge/p2p/nat/TURNManager.js +547 -0
- package/dist/edge/p2p/nat/TURNManager.js.map +1 -0
- package/dist/edge/p2p/nat/index.d.ts +74 -0
- package/dist/edge/p2p/nat/index.d.ts.map +1 -0
- package/dist/edge/p2p/nat/index.js +104 -0
- package/dist/edge/p2p/nat/index.js.map +1 -0
- package/dist/edge/p2p/nat/types.d.ts +583 -0
- package/dist/edge/p2p/nat/types.d.ts.map +1 -0
- package/dist/edge/p2p/nat/types.js +267 -0
- package/dist/edge/p2p/nat/types.js.map +1 -0
- package/dist/edge/p2p/protocol/AgentChannel.d.ts +333 -0
- package/dist/edge/p2p/protocol/AgentChannel.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/AgentChannel.js +914 -0
- package/dist/edge/p2p/protocol/AgentChannel.js.map +1 -0
- package/dist/edge/p2p/protocol/MessageEncoder.d.ts +147 -0
- package/dist/edge/p2p/protocol/MessageEncoder.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/MessageEncoder.js +738 -0
- package/dist/edge/p2p/protocol/MessageEncoder.js.map +1 -0
- package/dist/edge/p2p/protocol/MessageRouter.d.ts +266 -0
- package/dist/edge/p2p/protocol/MessageRouter.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/MessageRouter.js +808 -0
- package/dist/edge/p2p/protocol/MessageRouter.js.map +1 -0
- package/dist/edge/p2p/protocol/ProtocolHandler.d.ts +309 -0
- package/dist/edge/p2p/protocol/ProtocolHandler.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/ProtocolHandler.js +930 -0
- package/dist/edge/p2p/protocol/ProtocolHandler.js.map +1 -0
- package/dist/edge/p2p/protocol/index.d.ts +114 -0
- package/dist/edge/p2p/protocol/index.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/index.js +206 -0
- package/dist/edge/p2p/protocol/index.js.map +1 -0
- package/dist/edge/p2p/protocol/types.d.ts +737 -0
- package/dist/edge/p2p/protocol/types.d.ts.map +1 -0
- package/dist/edge/p2p/protocol/types.js +490 -0
- package/dist/edge/p2p/protocol/types.js.map +1 -0
- package/dist/edge/p2p/sharing/PatternBroadcaster.d.ts +284 -0
- package/dist/edge/p2p/sharing/PatternBroadcaster.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/PatternBroadcaster.js +644 -0
- package/dist/edge/p2p/sharing/PatternBroadcaster.js.map +1 -0
- package/dist/edge/p2p/sharing/PatternIndex.d.ts +168 -0
- package/dist/edge/p2p/sharing/PatternIndex.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/PatternIndex.js +781 -0
- package/dist/edge/p2p/sharing/PatternIndex.js.map +1 -0
- package/dist/edge/p2p/sharing/PatternSerializer.d.ts +163 -0
- package/dist/edge/p2p/sharing/PatternSerializer.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/PatternSerializer.js +696 -0
- package/dist/edge/p2p/sharing/PatternSerializer.js.map +1 -0
- package/dist/edge/p2p/sharing/PatternSyncManager.d.ts +242 -0
- package/dist/edge/p2p/sharing/PatternSyncManager.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/PatternSyncManager.js +859 -0
- package/dist/edge/p2p/sharing/PatternSyncManager.js.map +1 -0
- package/dist/edge/p2p/sharing/index.d.ts +90 -0
- package/dist/edge/p2p/sharing/index.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/index.js +152 -0
- package/dist/edge/p2p/sharing/index.js.map +1 -0
- package/dist/edge/p2p/sharing/types.d.ts +796 -0
- package/dist/edge/p2p/sharing/types.d.ts.map +1 -0
- package/dist/edge/p2p/sharing/types.js +264 -0
- package/dist/edge/p2p/sharing/types.js.map +1 -0
- package/dist/edge/p2p/webrtc/ConnectionPool.d.ts +218 -0
- package/dist/edge/p2p/webrtc/ConnectionPool.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/ConnectionPool.js +562 -0
- package/dist/edge/p2p/webrtc/ConnectionPool.js.map +1 -0
- package/dist/edge/p2p/webrtc/ICEManager.d.ts +171 -0
- package/dist/edge/p2p/webrtc/ICEManager.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/ICEManager.js +490 -0
- package/dist/edge/p2p/webrtc/ICEManager.js.map +1 -0
- package/dist/edge/p2p/webrtc/PeerConnectionManager.d.ts +159 -0
- package/dist/edge/p2p/webrtc/PeerConnectionManager.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/PeerConnectionManager.js +735 -0
- package/dist/edge/p2p/webrtc/PeerConnectionManager.js.map +1 -0
- package/dist/edge/p2p/webrtc/SignalingClient.d.ts +191 -0
- package/dist/edge/p2p/webrtc/SignalingClient.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/SignalingClient.js +608 -0
- package/dist/edge/p2p/webrtc/SignalingClient.js.map +1 -0
- package/dist/edge/p2p/webrtc/index.d.ts +158 -0
- package/dist/edge/p2p/webrtc/index.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/index.js +164 -0
- package/dist/edge/p2p/webrtc/index.js.map +1 -0
- package/dist/edge/p2p/webrtc/types.d.ts +665 -0
- package/dist/edge/p2p/webrtc/types.d.ts.map +1 -0
- package/dist/edge/p2p/webrtc/types.js +245 -0
- package/dist/edge/p2p/webrtc/types.js.map +1 -0
- package/dist/edge/server/AgentSpawnAPI.d.ts +98 -0
- package/dist/edge/server/AgentSpawnAPI.d.ts.map +1 -0
- package/dist/edge/server/AgentSpawnAPI.js +264 -0
- package/dist/edge/server/AgentSpawnAPI.js.map +1 -0
- package/dist/edge/server/SignalingServer.d.ts +71 -0
- package/dist/edge/server/SignalingServer.d.ts.map +1 -0
- package/dist/edge/server/SignalingServer.js +429 -0
- package/dist/edge/server/SignalingServer.js.map +1 -0
- package/dist/edge/server/index.d.ts +64 -0
- package/dist/edge/server/index.d.ts.map +1 -0
- package/dist/edge/server/index.js +318 -0
- package/dist/edge/server/index.js.map +1 -0
- package/dist/edge/types/browser-agent.types.d.ts +455 -0
- package/dist/edge/types/browser-agent.types.d.ts.map +1 -0
- package/dist/edge/types/browser-agent.types.js +116 -0
- package/dist/edge/types/browser-agent.types.js.map +1 -0
- package/dist/edge/types/index.d.ts +11 -0
- package/dist/edge/types/index.d.ts.map +1 -0
- package/dist/edge/types/index.js +17 -0
- package/dist/edge/types/index.js.map +1 -0
- package/dist/edge/types/storage.types.d.ts +207 -0
- package/dist/edge/types/storage.types.d.ts.map +1 -0
- package/dist/edge/types/storage.types.js +47 -0
- package/dist/edge/types/storage.types.js.map +1 -0
- package/dist/edge/wasm/shims.d.ts +224 -0
- package/dist/edge/wasm/shims.d.ts.map +1 -0
- package/dist/edge/wasm/shims.js +667 -0
- package/dist/edge/wasm/shims.js.map +1 -0
- package/dist/mcp/handlers/NewDomainToolsHandler.d.ts +33 -0
- package/dist/mcp/handlers/NewDomainToolsHandler.d.ts.map +1 -0
- package/dist/mcp/handlers/NewDomainToolsHandler.js +305 -0
- package/dist/mcp/handlers/NewDomainToolsHandler.js.map +1 -0
- package/dist/mcp/handlers/filtered/index.d.ts +15 -19
- package/dist/mcp/handlers/filtered/index.d.ts.map +1 -1
- package/dist/mcp/handlers/filtered/index.js +16 -27
- package/dist/mcp/handlers/filtered/index.js.map +1 -1
- package/dist/mcp/handlers/integration/index.d.ts +5 -4
- package/dist/mcp/handlers/integration/index.d.ts.map +1 -1
- package/dist/mcp/handlers/integration/index.js +7 -7
- package/dist/mcp/handlers/integration/index.js.map +1 -1
- package/dist/mcp/server-instructions.d.ts +1 -1
- package/dist/mcp/server-instructions.js +1 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +14 -0
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools.d.ts +8 -0
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +412 -1
- package/dist/mcp/tools.js.map +1 -1
- package/dist/planning/GOAPPlanner.d.ts +1 -0
- package/dist/planning/GOAPPlanner.d.ts.map +1 -1
- package/dist/planning/GOAPPlanner.js +12 -0
- package/dist/planning/GOAPPlanner.js.map +1 -1
- package/package.json +29 -8
- package/dist/alerting/AlertManager.d.ts +0 -120
- package/dist/alerting/AlertManager.d.ts.map +0 -1
- package/dist/alerting/AlertManager.js +0 -345
- package/dist/alerting/AlertManager.js.map +0 -1
- package/dist/alerting/FeedbackRouter.d.ts +0 -98
- package/dist/alerting/FeedbackRouter.d.ts.map +0 -1
- package/dist/alerting/FeedbackRouter.js +0 -331
- package/dist/alerting/FeedbackRouter.js.map +0 -1
- package/dist/alerting/StrategyApplicator.d.ts +0 -120
- package/dist/alerting/StrategyApplicator.d.ts.map +0 -1
- package/dist/alerting/StrategyApplicator.js +0 -299
- package/dist/alerting/StrategyApplicator.js.map +0 -1
- package/dist/alerting/index.d.ts +0 -68
- package/dist/alerting/index.d.ts.map +0 -1
- package/dist/alerting/index.js +0 -112
- package/dist/alerting/index.js.map +0 -1
- package/dist/alerting/types.d.ts +0 -118
- package/dist/alerting/types.d.ts.map +0 -1
- package/dist/alerting/types.js +0 -11
- package/dist/alerting/types.js.map +0 -1
- package/dist/cli/commands/fleet/backup.d.ts +0 -49
- package/dist/cli/commands/fleet/backup.d.ts.map +0 -1
- package/dist/cli/commands/fleet/backup.js +0 -88
- package/dist/cli/commands/fleet/backup.js.map +0 -1
- package/dist/cli/commands/fleet/health.d.ts +0 -154
- package/dist/cli/commands/fleet/health.d.ts.map +0 -1
- package/dist/cli/commands/fleet/health.js +0 -483
- package/dist/cli/commands/fleet/health.js.map +0 -1
- package/dist/cli/commands/fleet/init.d.ts +0 -11
- package/dist/cli/commands/fleet/init.d.ts.map +0 -1
- package/dist/cli/commands/fleet/init.js +0 -91
- package/dist/cli/commands/fleet/init.js.map +0 -1
- package/dist/cli/commands/fleet/logs.d.ts +0 -21
- package/dist/cli/commands/fleet/logs.d.ts.map +0 -1
- package/dist/cli/commands/fleet/logs.js +0 -267
- package/dist/cli/commands/fleet/logs.js.map +0 -1
- package/dist/cli/commands/fleet/metrics.d.ts +0 -27
- package/dist/cli/commands/fleet/metrics.d.ts.map +0 -1
- package/dist/cli/commands/fleet/metrics.js +0 -369
- package/dist/cli/commands/fleet/metrics.js.map +0 -1
- package/dist/cli/commands/fleet/monitor.d.ts +0 -18
- package/dist/cli/commands/fleet/monitor.d.ts.map +0 -1
- package/dist/cli/commands/fleet/monitor.js +0 -237
- package/dist/cli/commands/fleet/monitor.js.map +0 -1
- package/dist/cli/commands/fleet/optimize.d.ts +0 -42
- package/dist/cli/commands/fleet/optimize.d.ts.map +0 -1
- package/dist/cli/commands/fleet/optimize.js +0 -135
- package/dist/cli/commands/fleet/optimize.js.map +0 -1
- package/dist/cli/commands/fleet/recover.d.ts +0 -22
- package/dist/cli/commands/fleet/recover.d.ts.map +0 -1
- package/dist/cli/commands/fleet/recover.js +0 -99
- package/dist/cli/commands/fleet/recover.js.map +0 -1
- package/dist/cli/commands/fleet/restart.d.ts +0 -18
- package/dist/cli/commands/fleet/restart.d.ts.map +0 -1
- package/dist/cli/commands/fleet/restart.js +0 -290
- package/dist/cli/commands/fleet/restart.js.map +0 -1
- package/dist/cli/commands/fleet/scale.d.ts +0 -9
- package/dist/cli/commands/fleet/scale.d.ts.map +0 -1
- package/dist/cli/commands/fleet/scale.js +0 -77
- package/dist/cli/commands/fleet/scale.js.map +0 -1
- package/dist/cli/commands/fleet/shutdown.d.ts +0 -19
- package/dist/cli/commands/fleet/shutdown.d.ts.map +0 -1
- package/dist/cli/commands/fleet/shutdown.js +0 -307
- package/dist/cli/commands/fleet/shutdown.js.map +0 -1
- package/dist/cli/commands/fleet/status.d.ts +0 -10
- package/dist/cli/commands/fleet/status.d.ts.map +0 -1
- package/dist/cli/commands/fleet/status.js +0 -97
- package/dist/cli/commands/fleet/status.js.map +0 -1
- package/dist/cli/commands/fleet/topology.d.ts +0 -23
- package/dist/cli/commands/fleet/topology.d.ts.map +0 -1
- package/dist/cli/commands/fleet/topology.js +0 -376
- package/dist/cli/commands/fleet/topology.js.map +0 -1
- package/dist/cli/commands/monitor/alerts.d.ts +0 -45
- package/dist/cli/commands/monitor/alerts.d.ts.map +0 -1
- package/dist/cli/commands/monitor/alerts.js +0 -168
- package/dist/cli/commands/monitor/alerts.js.map +0 -1
- package/dist/cli/commands/monitor/analyze.d.ts +0 -49
- package/dist/cli/commands/monitor/analyze.d.ts.map +0 -1
- package/dist/cli/commands/monitor/analyze.js +0 -209
- package/dist/cli/commands/monitor/analyze.js.map +0 -1
- package/dist/cli/commands/monitor/compare.d.ts +0 -38
- package/dist/cli/commands/monitor/compare.d.ts.map +0 -1
- package/dist/cli/commands/monitor/compare.js +0 -177
- package/dist/cli/commands/monitor/compare.js.map +0 -1
- package/dist/cli/commands/monitor/dashboard.d.ts +0 -34
- package/dist/cli/commands/monitor/dashboard.d.ts.map +0 -1
- package/dist/cli/commands/monitor/dashboard.js +0 -157
- package/dist/cli/commands/monitor/dashboard.js.map +0 -1
- package/dist/cli/commands/monitor/export.d.ts +0 -36
- package/dist/cli/commands/monitor/export.d.ts.map +0 -1
- package/dist/cli/commands/monitor/export.js +0 -157
- package/dist/cli/commands/monitor/export.js.map +0 -1
- package/dist/cli/commands/monitor/index.d.ts +0 -11
- package/dist/cli/commands/monitor/index.d.ts.map +0 -1
- package/dist/cli/commands/monitor/index.js +0 -14
- package/dist/cli/commands/monitor/index.js.map +0 -1
- package/dist/cli/commands/quality/baseline.d.ts +0 -27
- package/dist/cli/commands/quality/baseline.d.ts.map +0 -1
- package/dist/cli/commands/quality/baseline.js +0 -124
- package/dist/cli/commands/quality/baseline.js.map +0 -1
- package/dist/cli/commands/quality/compare.d.ts +0 -36
- package/dist/cli/commands/quality/compare.d.ts.map +0 -1
- package/dist/cli/commands/quality/compare.js +0 -136
- package/dist/cli/commands/quality/compare.js.map +0 -1
- package/dist/cli/commands/quality/decision.d.ts +0 -81
- package/dist/cli/commands/quality/decision.d.ts.map +0 -1
- package/dist/cli/commands/quality/decision.js +0 -319
- package/dist/cli/commands/quality/decision.js.map +0 -1
- package/dist/cli/commands/quality/gate.d.ts +0 -47
- package/dist/cli/commands/quality/gate.d.ts.map +0 -1
- package/dist/cli/commands/quality/gate.js +0 -205
- package/dist/cli/commands/quality/gate.js.map +0 -1
- package/dist/cli/commands/quality/index.d.ts +0 -17
- package/dist/cli/commands/quality/index.d.ts.map +0 -1
- package/dist/cli/commands/quality/index.js +0 -41
- package/dist/cli/commands/quality/index.js.map +0 -1
- package/dist/cli/commands/quality/policy.d.ts +0 -57
- package/dist/cli/commands/quality/policy.d.ts.map +0 -1
- package/dist/cli/commands/quality/policy.js +0 -359
- package/dist/cli/commands/quality/policy.js.map +0 -1
- package/dist/cli/commands/quality/risk.d.ts +0 -41
- package/dist/cli/commands/quality/risk.d.ts.map +0 -1
- package/dist/cli/commands/quality/risk.js +0 -255
- package/dist/cli/commands/quality/risk.js.map +0 -1
- package/dist/cli/commands/quality/trends.d.ts +0 -40
- package/dist/cli/commands/quality/trends.d.ts.map +0 -1
- package/dist/cli/commands/quality/trends.js +0 -122
- package/dist/cli/commands/quality/trends.js.map +0 -1
- package/dist/cli/commands/quality/validate.d.ts +0 -44
- package/dist/cli/commands/quality/validate.d.ts.map +0 -1
- package/dist/cli/commands/quality/validate.js +0 -234
- package/dist/cli/commands/quality/validate.js.map +0 -1
- package/dist/cli/commands/test/analyze-failures.d.ts +0 -39
- package/dist/cli/commands/test/analyze-failures.d.ts.map +0 -1
- package/dist/cli/commands/test/analyze-failures.js +0 -113
- package/dist/cli/commands/test/analyze-failures.js.map +0 -1
- package/dist/cli/commands/test/clean.d.ts +0 -3
- package/dist/cli/commands/test/clean.d.ts.map +0 -1
- package/dist/cli/commands/test/clean.js +0 -148
- package/dist/cli/commands/test/clean.js.map +0 -1
- package/dist/cli/commands/test/debug.d.ts +0 -3
- package/dist/cli/commands/test/debug.d.ts.map +0 -1
- package/dist/cli/commands/test/debug.js +0 -167
- package/dist/cli/commands/test/debug.js.map +0 -1
- package/dist/cli/commands/test/diff.d.ts +0 -3
- package/dist/cli/commands/test/diff.d.ts.map +0 -1
- package/dist/cli/commands/test/diff.js +0 -195
- package/dist/cli/commands/test/diff.js.map +0 -1
- package/dist/cli/commands/test/flakiness.d.ts +0 -32
- package/dist/cli/commands/test/flakiness.d.ts.map +0 -1
- package/dist/cli/commands/test/flakiness.js +0 -121
- package/dist/cli/commands/test/flakiness.js.map +0 -1
- package/dist/cli/commands/test/index.d.ts +0 -17
- package/dist/cli/commands/test/index.d.ts.map +0 -1
- package/dist/cli/commands/test/index.js +0 -45
- package/dist/cli/commands/test/index.js.map +0 -1
- package/dist/cli/commands/test/mutate.d.ts +0 -29
- package/dist/cli/commands/test/mutate.d.ts.map +0 -1
- package/dist/cli/commands/test/mutate.js +0 -163
- package/dist/cli/commands/test/mutate.js.map +0 -1
- package/dist/cli/commands/test/parallel.d.ts +0 -3
- package/dist/cli/commands/test/parallel.d.ts.map +0 -1
- package/dist/cli/commands/test/parallel.js +0 -117
- package/dist/cli/commands/test/parallel.js.map +0 -1
- package/dist/cli/commands/test/profile.d.ts +0 -3
- package/dist/cli/commands/test/profile.d.ts.map +0 -1
- package/dist/cli/commands/test/profile.js +0 -156
- package/dist/cli/commands/test/profile.js.map +0 -1
- package/dist/cli/commands/test/queue.d.ts +0 -3
- package/dist/cli/commands/test/queue.d.ts.map +0 -1
- package/dist/cli/commands/test/queue.js +0 -140
- package/dist/cli/commands/test/queue.js.map +0 -1
- package/dist/cli/commands/test/retry.d.ts +0 -3
- package/dist/cli/commands/test/retry.d.ts.map +0 -1
- package/dist/cli/commands/test/retry.js +0 -105
- package/dist/cli/commands/test/retry.js.map +0 -1
- package/dist/cli/commands/test/snapshot.d.ts +0 -3
- package/dist/cli/commands/test/snapshot.d.ts.map +0 -1
- package/dist/cli/commands/test/snapshot.js +0 -176
- package/dist/cli/commands/test/snapshot.js.map +0 -1
- package/dist/cli/commands/test/trace.d.ts +0 -3
- package/dist/cli/commands/test/trace.d.ts.map +0 -1
- package/dist/cli/commands/test/trace.js +0 -137
- package/dist/cli/commands/test/trace.js.map +0 -1
- package/dist/cli/commands/test/watch.d.ts +0 -3
- package/dist/cli/commands/test/watch.d.ts.map +0 -1
- package/dist/cli/commands/test/watch.js +0 -130
- package/dist/cli/commands/test/watch.js.map +0 -1
- package/dist/cli/index-spec.d.ts +0 -3
- package/dist/cli/index-spec.d.ts.map +0 -1
- package/dist/cli/index-spec.js +0 -154
- package/dist/cli/index-spec.js.map +0 -1
- package/dist/cli/index-working.d.ts +0 -7
- package/dist/cli/index-working.d.ts.map +0 -1
- package/dist/cli/index-working.js +0 -617
- package/dist/cli/index-working.js.map +0 -1
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.d.ts +0 -83
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.d.ts.map +0 -1
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.js +0 -130
- package/dist/mcp/handlers/filtered/coverage-analyzer-filtered.js.map +0 -1
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.d.ts +0 -58
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.d.ts.map +0 -1
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.js +0 -84
- package/dist/mcp/handlers/filtered/flaky-detector-filtered.js.map +0 -1
- package/dist/mcp/handlers/filtered/security-scanner-filtered.d.ts +0 -54
- package/dist/mcp/handlers/filtered/security-scanner-filtered.d.ts.map +0 -1
- package/dist/mcp/handlers/filtered/security-scanner-filtered.js +0 -73
- package/dist/mcp/handlers/filtered/security-scanner-filtered.js.map +0 -1
- package/dist/mcp/handlers/integration/contract-validate.d.ts +0 -10
- package/dist/mcp/handlers/integration/contract-validate.d.ts.map +0 -1
- package/dist/mcp/handlers/integration/contract-validate.js +0 -348
- package/dist/mcp/handlers/integration/contract-validate.js.map +0 -1
- package/dist/reporting/ResultAggregator.d.ts +0 -107
- package/dist/reporting/ResultAggregator.d.ts.map +0 -1
- package/dist/reporting/ResultAggregator.js +0 -435
- package/dist/reporting/ResultAggregator.js.map +0 -1
- package/dist/reporting/index.d.ts +0 -48
- package/dist/reporting/index.d.ts.map +0 -1
- package/dist/reporting/index.js +0 -154
- package/dist/reporting/index.js.map +0 -1
- package/dist/reporting/reporters/ControlLoopReporter.d.ts +0 -128
- package/dist/reporting/reporters/ControlLoopReporter.d.ts.map +0 -1
- package/dist/reporting/reporters/ControlLoopReporter.js +0 -417
- package/dist/reporting/reporters/ControlLoopReporter.js.map +0 -1
- package/dist/reporting/reporters/HumanReadableReporter.d.ts +0 -140
- package/dist/reporting/reporters/HumanReadableReporter.d.ts.map +0 -1
- package/dist/reporting/reporters/HumanReadableReporter.js +0 -524
- package/dist/reporting/reporters/HumanReadableReporter.js.map +0 -1
- package/dist/reporting/reporters/JSONReporter.d.ts +0 -251
- package/dist/reporting/reporters/JSONReporter.d.ts.map +0 -1
- package/dist/reporting/reporters/JSONReporter.js +0 -325
- package/dist/reporting/reporters/JSONReporter.js.map +0 -1
- package/dist/reporting/reporters/index.d.ts +0 -14
- package/dist/reporting/reporters/index.d.ts.map +0 -1
- package/dist/reporting/reporters/index.js +0 -19
- package/dist/reporting/reporters/index.js.map +0 -1
- package/dist/reporting/types.d.ts +0 -427
- package/dist/reporting/types.d.ts.map +0 -1
- package/dist/reporting/types.js +0 -12
- package/dist/reporting/types.js.map +0 -1
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Peer Connection Manager for WebRTC
|
|
4
|
+
*
|
|
5
|
+
* Manages multiple WebRTC peer connections with automatic reconnection,
|
|
6
|
+
* data channel management, and connection state tracking.
|
|
7
|
+
*
|
|
8
|
+
* @module edge/p2p/webrtc/PeerConnectionManager
|
|
9
|
+
* @version 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PeerConnectionManager = void 0;
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
const ICEManager_1 = require("./ICEManager");
|
|
15
|
+
/**
|
|
16
|
+
* Default peer connection manager configuration
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_CONFIG = {
|
|
19
|
+
iceConfig: {
|
|
20
|
+
iceServers: types_1.DEFAULT_ICE_SERVERS,
|
|
21
|
+
enableTrickle: true,
|
|
22
|
+
gatheringTimeout: 10000,
|
|
23
|
+
enableTurnFallback: true,
|
|
24
|
+
},
|
|
25
|
+
poolConfig: {
|
|
26
|
+
maxConnections: 50,
|
|
27
|
+
idleTimeout: 60000,
|
|
28
|
+
healthCheckInterval: 30000,
|
|
29
|
+
},
|
|
30
|
+
defaultDataChannels: types_1.DEFAULT_DATA_CHANNELS,
|
|
31
|
+
autoReconnect: true,
|
|
32
|
+
reconnectConfig: types_1.DEFAULT_RECONNECT_CONFIG,
|
|
33
|
+
onConnectionStateChange: () => { },
|
|
34
|
+
onDataReceived: () => { },
|
|
35
|
+
onError: () => { },
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Peer Connection Manager - Manages WebRTC peer connections
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const signaling = new SignalingClient({ serverUrl: 'wss://signal.example.com', peerId: 'local' });
|
|
43
|
+
* const manager = new PeerConnectionManager({
|
|
44
|
+
* localPeerId: 'local',
|
|
45
|
+
* autoReconnect: true,
|
|
46
|
+
* });
|
|
47
|
+
*
|
|
48
|
+
* // Set up signaling integration
|
|
49
|
+
* manager.setSignaling(signaling);
|
|
50
|
+
*
|
|
51
|
+
* // Connect to a peer
|
|
52
|
+
* const connection = await manager.connect('remote-peer');
|
|
53
|
+
*
|
|
54
|
+
* // Send message
|
|
55
|
+
* manager.send('remote-peer', 'reliable', { type: 'hello', data: 'world' });
|
|
56
|
+
*
|
|
57
|
+
* // Listen for messages
|
|
58
|
+
* manager.on(WebRTCEventType.DATA_CHANNEL_MESSAGE, (event) => {
|
|
59
|
+
* console.log('Message from', event.peerId, ':', event.data);
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
class PeerConnectionManager {
|
|
64
|
+
/**
|
|
65
|
+
* Create a new PeerConnectionManager instance
|
|
66
|
+
*
|
|
67
|
+
* @param config - Manager configuration
|
|
68
|
+
*/
|
|
69
|
+
constructor(config) {
|
|
70
|
+
this.peers = new Map();
|
|
71
|
+
this.eventHandlers = new Map();
|
|
72
|
+
this.signaling = null;
|
|
73
|
+
this.isDestroyed = false;
|
|
74
|
+
this.config = {
|
|
75
|
+
...DEFAULT_CONFIG,
|
|
76
|
+
...config,
|
|
77
|
+
iceConfig: { ...DEFAULT_CONFIG.iceConfig, ...config.iceConfig },
|
|
78
|
+
poolConfig: { ...DEFAULT_CONFIG.poolConfig, ...config.poolConfig },
|
|
79
|
+
reconnectConfig: { ...DEFAULT_CONFIG.reconnectConfig, ...config.reconnectConfig },
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Set the signaling client for connection establishment
|
|
84
|
+
*
|
|
85
|
+
* @param signaling - SignalingClient instance
|
|
86
|
+
*/
|
|
87
|
+
setSignaling(signaling) {
|
|
88
|
+
if (this.signaling) {
|
|
89
|
+
// Remove previous handlers
|
|
90
|
+
this.signaling.on({});
|
|
91
|
+
}
|
|
92
|
+
this.signaling = signaling;
|
|
93
|
+
// Register signaling event handlers
|
|
94
|
+
signaling.on({
|
|
95
|
+
onOffer: async (from, sdp, metadata) => {
|
|
96
|
+
await this.handleRemoteOffer(from, sdp, metadata);
|
|
97
|
+
},
|
|
98
|
+
onAnswer: async (from, sdp) => {
|
|
99
|
+
await this.handleRemoteAnswer(from, sdp);
|
|
100
|
+
},
|
|
101
|
+
onIceCandidate: async (from, candidate) => {
|
|
102
|
+
await this.handleRemoteIceCandidate(from, candidate);
|
|
103
|
+
},
|
|
104
|
+
onPeerLeft: (peerId) => {
|
|
105
|
+
this.handlePeerLeft(peerId);
|
|
106
|
+
},
|
|
107
|
+
onRenegotiate: async (from, reason) => {
|
|
108
|
+
await this.handleRenegotiationRequest(from, reason);
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get local peer ID
|
|
114
|
+
*/
|
|
115
|
+
getLocalPeerId() {
|
|
116
|
+
return this.config.localPeerId;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Connect to a remote peer
|
|
120
|
+
*
|
|
121
|
+
* @param peerId - Remote peer identifier
|
|
122
|
+
* @param options - Connection options
|
|
123
|
+
* @returns Promise resolving to the peer connection
|
|
124
|
+
*/
|
|
125
|
+
async connect(peerId, options = {}) {
|
|
126
|
+
if (this.isDestroyed) {
|
|
127
|
+
throw new Error('PeerConnectionManager has been destroyed');
|
|
128
|
+
}
|
|
129
|
+
// Check if already connected
|
|
130
|
+
const existing = this.peers.get(peerId);
|
|
131
|
+
if (existing && existing.connection.state === types_1.ConnectionState.CONNECTED) {
|
|
132
|
+
return existing.connection;
|
|
133
|
+
}
|
|
134
|
+
// Check pool limits
|
|
135
|
+
if (this.peers.size >= (this.config.poolConfig.maxConnections ?? 50)) {
|
|
136
|
+
throw new Error('Connection pool is full');
|
|
137
|
+
}
|
|
138
|
+
const isInitiator = options.initiator ?? true;
|
|
139
|
+
const dataChannels = options.dataChannels ?? this.config.defaultDataChannels;
|
|
140
|
+
// Create ICE manager
|
|
141
|
+
const iceManager = new ICEManager_1.ICEManager(this.config.iceConfig);
|
|
142
|
+
// Create RTCPeerConnection
|
|
143
|
+
const rtcConfig = iceManager.getRTCConfiguration();
|
|
144
|
+
const rtcConnection = new RTCPeerConnection(rtcConfig);
|
|
145
|
+
// Create peer connection object
|
|
146
|
+
const connection = {
|
|
147
|
+
id: peerId,
|
|
148
|
+
state: types_1.ConnectionState.NEW,
|
|
149
|
+
rtcConnection,
|
|
150
|
+
dataChannels: new Map(),
|
|
151
|
+
quality: (0, types_1.createDefaultConnectionQuality)(),
|
|
152
|
+
createdAt: Date.now(),
|
|
153
|
+
lastActivityAt: Date.now(),
|
|
154
|
+
reconnectAttempts: 0,
|
|
155
|
+
metadata: options.metadata,
|
|
156
|
+
};
|
|
157
|
+
// Store internal state
|
|
158
|
+
const peerState = {
|
|
159
|
+
connection,
|
|
160
|
+
iceManager,
|
|
161
|
+
reconnectTimer: null,
|
|
162
|
+
pendingCandidates: [],
|
|
163
|
+
isInitiator,
|
|
164
|
+
negotiationNeeded: false,
|
|
165
|
+
};
|
|
166
|
+
this.peers.set(peerId, peerState);
|
|
167
|
+
// Attach ICE manager
|
|
168
|
+
iceManager.attachToPeerConnection(rtcConnection);
|
|
169
|
+
// Set up event handlers
|
|
170
|
+
this.setupPeerConnectionHandlers(peerId, peerState);
|
|
171
|
+
// Set up ICE candidate handling
|
|
172
|
+
iceManager.onCandidate((candidate) => {
|
|
173
|
+
this.sendIceCandidate(peerId, candidate);
|
|
174
|
+
});
|
|
175
|
+
// Create data channels if initiator
|
|
176
|
+
if (isInitiator) {
|
|
177
|
+
for (const channelConfig of dataChannels) {
|
|
178
|
+
this.createDataChannel(peerId, channelConfig);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Handle incoming data channels
|
|
182
|
+
rtcConnection.ondatachannel = (event) => {
|
|
183
|
+
this.setupDataChannel(peerId, event.channel);
|
|
184
|
+
};
|
|
185
|
+
// Start connection process if initiator
|
|
186
|
+
if (isInitiator) {
|
|
187
|
+
await this.initiateConnection(peerId);
|
|
188
|
+
}
|
|
189
|
+
return connection;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Disconnect from a peer
|
|
193
|
+
*
|
|
194
|
+
* @param peerId - Peer to disconnect from
|
|
195
|
+
* @param options - Disconnect options
|
|
196
|
+
*/
|
|
197
|
+
async disconnect(peerId, options = {}) {
|
|
198
|
+
const peerState = this.peers.get(peerId);
|
|
199
|
+
if (!peerState) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// Clear reconnect timer
|
|
203
|
+
if (peerState.reconnectTimer) {
|
|
204
|
+
clearTimeout(peerState.reconnectTimer);
|
|
205
|
+
peerState.reconnectTimer = null;
|
|
206
|
+
}
|
|
207
|
+
// Notify peer if requested
|
|
208
|
+
if (options.notify && this.signaling) {
|
|
209
|
+
try {
|
|
210
|
+
await this.signaling.requestRenegotiation(peerId, options.reason ?? 'disconnect');
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
// Ignore signaling errors during disconnect
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Close data channels
|
|
217
|
+
peerState.connection.dataChannels.forEach((channel) => {
|
|
218
|
+
try {
|
|
219
|
+
channel.close();
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
// Ignore errors
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
// Close peer connection
|
|
226
|
+
try {
|
|
227
|
+
peerState.connection.rtcConnection.close();
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
// Ignore errors
|
|
231
|
+
}
|
|
232
|
+
// Cleanup ICE manager
|
|
233
|
+
peerState.iceManager.destroy();
|
|
234
|
+
// Update state and remove
|
|
235
|
+
peerState.connection.state = types_1.ConnectionState.CLOSED;
|
|
236
|
+
this.emitEvent(types_1.WebRTCEventType.CONNECTION_STATE_CHANGED, peerId, types_1.ConnectionState.CLOSED);
|
|
237
|
+
this.peers.delete(peerId);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Send data to a peer through a data channel
|
|
241
|
+
*
|
|
242
|
+
* @param peerId - Target peer ID
|
|
243
|
+
* @param channel - Data channel label
|
|
244
|
+
* @param message - Message to send
|
|
245
|
+
*/
|
|
246
|
+
send(peerId, channel, message) {
|
|
247
|
+
const peerState = this.peers.get(peerId);
|
|
248
|
+
if (!peerState) {
|
|
249
|
+
throw new Error(`No connection to peer: ${peerId}`);
|
|
250
|
+
}
|
|
251
|
+
const dataChannel = peerState.connection.dataChannels.get(channel);
|
|
252
|
+
if (!dataChannel) {
|
|
253
|
+
throw new Error(`Data channel not found: ${channel}`);
|
|
254
|
+
}
|
|
255
|
+
if (dataChannel.readyState !== 'open') {
|
|
256
|
+
throw new Error(`Data channel not open: ${channel} (state: ${dataChannel.readyState})`);
|
|
257
|
+
}
|
|
258
|
+
const data = JSON.stringify({
|
|
259
|
+
...message,
|
|
260
|
+
id: message.id ?? (0, types_1.generateId)('msg'),
|
|
261
|
+
timestamp: message.timestamp ?? Date.now(),
|
|
262
|
+
});
|
|
263
|
+
dataChannel.send(data);
|
|
264
|
+
peerState.connection.lastActivityAt = Date.now();
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Send raw data to a peer
|
|
268
|
+
*
|
|
269
|
+
* @param peerId - Target peer ID
|
|
270
|
+
* @param channel - Data channel label
|
|
271
|
+
* @param data - Raw data (string, ArrayBuffer, etc.)
|
|
272
|
+
*/
|
|
273
|
+
sendRaw(peerId, channel, data) {
|
|
274
|
+
const peerState = this.peers.get(peerId);
|
|
275
|
+
if (!peerState) {
|
|
276
|
+
throw new Error(`No connection to peer: ${peerId}`);
|
|
277
|
+
}
|
|
278
|
+
const dataChannel = peerState.connection.dataChannels.get(channel);
|
|
279
|
+
if (!dataChannel) {
|
|
280
|
+
throw new Error(`Data channel not found: ${channel}`);
|
|
281
|
+
}
|
|
282
|
+
if (dataChannel.readyState !== 'open') {
|
|
283
|
+
throw new Error(`Data channel not open: ${channel}`);
|
|
284
|
+
}
|
|
285
|
+
dataChannel.send(data);
|
|
286
|
+
peerState.connection.lastActivityAt = Date.now();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Get connection state for a peer
|
|
290
|
+
*
|
|
291
|
+
* @param peerId - Peer ID
|
|
292
|
+
* @returns Connection state or null if not found
|
|
293
|
+
*/
|
|
294
|
+
getConnectionState(peerId) {
|
|
295
|
+
const peerState = this.peers.get(peerId);
|
|
296
|
+
return peerState?.connection.state ?? null;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Get peer connection object
|
|
300
|
+
*
|
|
301
|
+
* @param peerId - Peer ID
|
|
302
|
+
* @returns Peer connection or undefined if not found
|
|
303
|
+
*/
|
|
304
|
+
getPeerConnection(peerId) {
|
|
305
|
+
return this.peers.get(peerId)?.connection;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Get all connected peer IDs
|
|
309
|
+
*/
|
|
310
|
+
getConnectedPeers() {
|
|
311
|
+
const connected = [];
|
|
312
|
+
this.peers.forEach((state, peerId) => {
|
|
313
|
+
if (state.connection.state === types_1.ConnectionState.CONNECTED) {
|
|
314
|
+
connected.push(peerId);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
return connected;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Get data channel state
|
|
321
|
+
*
|
|
322
|
+
* @param peerId - Peer ID
|
|
323
|
+
* @param label - Channel label
|
|
324
|
+
* @returns Data channel state or undefined
|
|
325
|
+
*/
|
|
326
|
+
getDataChannelState(peerId, label) {
|
|
327
|
+
const peerState = this.peers.get(peerId);
|
|
328
|
+
const channel = peerState?.connection.dataChannels.get(label);
|
|
329
|
+
if (!channel) {
|
|
330
|
+
return undefined;
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
label: channel.label,
|
|
334
|
+
readyState: channel.readyState,
|
|
335
|
+
bufferedAmount: channel.bufferedAmount,
|
|
336
|
+
bufferedAmountLowThreshold: channel.bufferedAmountLowThreshold,
|
|
337
|
+
reliable: channel.maxRetransmits === null && channel.maxPacketLifeTime === null,
|
|
338
|
+
ordered: channel.ordered,
|
|
339
|
+
protocol: channel.protocol,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Get connection quality for a peer
|
|
344
|
+
*
|
|
345
|
+
* @param peerId - Peer ID
|
|
346
|
+
* @returns Connection quality or undefined
|
|
347
|
+
*/
|
|
348
|
+
async getConnectionQuality(peerId) {
|
|
349
|
+
const peerState = this.peers.get(peerId);
|
|
350
|
+
if (!peerState) {
|
|
351
|
+
return undefined;
|
|
352
|
+
}
|
|
353
|
+
return peerState.iceManager.getConnectionQuality();
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Register event handler
|
|
357
|
+
*
|
|
358
|
+
* @param event - Event type
|
|
359
|
+
* @param handler - Handler function
|
|
360
|
+
* @returns Unsubscribe function
|
|
361
|
+
*/
|
|
362
|
+
on(event, handler) {
|
|
363
|
+
if (!this.eventHandlers.has(event)) {
|
|
364
|
+
this.eventHandlers.set(event, new Set());
|
|
365
|
+
}
|
|
366
|
+
this.eventHandlers.get(event).add(handler);
|
|
367
|
+
return () => {
|
|
368
|
+
this.eventHandlers.get(event)?.delete(handler);
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Create additional data channel on existing connection
|
|
373
|
+
*
|
|
374
|
+
* @param peerId - Peer ID
|
|
375
|
+
* @param config - Data channel configuration
|
|
376
|
+
*/
|
|
377
|
+
createDataChannel(peerId, config) {
|
|
378
|
+
const peerState = this.peers.get(peerId);
|
|
379
|
+
if (!peerState) {
|
|
380
|
+
throw new Error(`No connection to peer: ${peerId}`);
|
|
381
|
+
}
|
|
382
|
+
const channelOptions = {
|
|
383
|
+
ordered: config.ordered ?? true,
|
|
384
|
+
maxRetransmits: config.reliable === false ? (config.maxRetransmits ?? 0) : undefined,
|
|
385
|
+
maxPacketLifeTime: config.reliable === false ? config.maxPacketLifeTime : undefined,
|
|
386
|
+
protocol: config.protocol ?? '',
|
|
387
|
+
negotiated: config.negotiated ?? false,
|
|
388
|
+
id: config.id,
|
|
389
|
+
};
|
|
390
|
+
const channel = peerState.connection.rtcConnection.createDataChannel(config.label, channelOptions);
|
|
391
|
+
this.setupDataChannel(peerId, channel);
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Destroy the manager and close all connections
|
|
395
|
+
*/
|
|
396
|
+
async destroy() {
|
|
397
|
+
this.isDestroyed = true;
|
|
398
|
+
// Disconnect all peers
|
|
399
|
+
const disconnectPromises = Array.from(this.peers.keys()).map((peerId) => this.disconnect(peerId, { notify: true, reason: 'manager-destroyed' }));
|
|
400
|
+
await Promise.all(disconnectPromises);
|
|
401
|
+
// Clear event handlers
|
|
402
|
+
this.eventHandlers.clear();
|
|
403
|
+
// Clear signaling reference
|
|
404
|
+
this.signaling = null;
|
|
405
|
+
}
|
|
406
|
+
// ============================================
|
|
407
|
+
// Private Methods
|
|
408
|
+
// ============================================
|
|
409
|
+
setupPeerConnectionHandlers(peerId, peerState) {
|
|
410
|
+
const { connection } = peerState;
|
|
411
|
+
const pc = connection.rtcConnection;
|
|
412
|
+
// Connection state changes
|
|
413
|
+
pc.onconnectionstatechange = () => {
|
|
414
|
+
const state = this.mapConnectionState(pc.connectionState);
|
|
415
|
+
const previousState = connection.state;
|
|
416
|
+
connection.state = state;
|
|
417
|
+
connection.lastActivityAt = Date.now();
|
|
418
|
+
this.emitEvent(types_1.WebRTCEventType.CONNECTION_STATE_CHANGED, peerId, state);
|
|
419
|
+
this.config.onConnectionStateChange?.(peerId, state);
|
|
420
|
+
// Handle reconnection
|
|
421
|
+
if (state === types_1.ConnectionState.DISCONNECTED || state === types_1.ConnectionState.FAILED) {
|
|
422
|
+
if (this.config.autoReconnect && !this.isDestroyed) {
|
|
423
|
+
this.scheduleReconnect(peerId, peerState);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
// Clear reconnect timer on successful connection
|
|
427
|
+
if (state === types_1.ConnectionState.CONNECTED && peerState.reconnectTimer) {
|
|
428
|
+
clearTimeout(peerState.reconnectTimer);
|
|
429
|
+
peerState.reconnectTimer = null;
|
|
430
|
+
connection.reconnectAttempts = 0;
|
|
431
|
+
if (previousState === types_1.ConnectionState.RECONNECTING) {
|
|
432
|
+
this.emitEvent(types_1.WebRTCEventType.RECONNECTED, peerId, {
|
|
433
|
+
attempts: connection.reconnectAttempts,
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
// Negotiation needed
|
|
439
|
+
pc.onnegotiationneeded = async () => {
|
|
440
|
+
if (peerState.isInitiator && !peerState.negotiationNeeded) {
|
|
441
|
+
peerState.negotiationNeeded = true;
|
|
442
|
+
try {
|
|
443
|
+
await this.initiateConnection(peerId);
|
|
444
|
+
}
|
|
445
|
+
finally {
|
|
446
|
+
peerState.negotiationNeeded = false;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
setupDataChannel(peerId, channel) {
|
|
452
|
+
const peerState = this.peers.get(peerId);
|
|
453
|
+
if (!peerState) {
|
|
454
|
+
channel.close();
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const { connection } = peerState;
|
|
458
|
+
// Store channel
|
|
459
|
+
connection.dataChannels.set(channel.label, channel);
|
|
460
|
+
// Channel open
|
|
461
|
+
channel.onopen = () => {
|
|
462
|
+
const state = this.getChannelState(channel);
|
|
463
|
+
this.emitEvent(types_1.WebRTCEventType.DATA_CHANNEL_OPEN, peerId, state);
|
|
464
|
+
};
|
|
465
|
+
// Channel close
|
|
466
|
+
channel.onclose = () => {
|
|
467
|
+
const state = this.getChannelState(channel);
|
|
468
|
+
this.emitEvent(types_1.WebRTCEventType.DATA_CHANNEL_CLOSED, peerId, state);
|
|
469
|
+
};
|
|
470
|
+
// Channel error
|
|
471
|
+
channel.onerror = (event) => {
|
|
472
|
+
const error = new Error(`Data channel error: ${event.message || 'unknown'}`);
|
|
473
|
+
this.emitEvent(types_1.WebRTCEventType.DATA_CHANNEL_ERROR, peerId, error);
|
|
474
|
+
this.config.onError?.(peerId, error);
|
|
475
|
+
};
|
|
476
|
+
// Channel message
|
|
477
|
+
channel.onmessage = (event) => {
|
|
478
|
+
connection.lastActivityAt = Date.now();
|
|
479
|
+
let message;
|
|
480
|
+
try {
|
|
481
|
+
if (typeof event.data === 'string') {
|
|
482
|
+
message = JSON.parse(event.data);
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
// Binary data - wrap in message format
|
|
486
|
+
message = {
|
|
487
|
+
type: 'binary',
|
|
488
|
+
data: event.data,
|
|
489
|
+
timestamp: Date.now(),
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
catch {
|
|
494
|
+
// Invalid JSON - treat as raw message
|
|
495
|
+
message = {
|
|
496
|
+
type: 'raw',
|
|
497
|
+
data: event.data,
|
|
498
|
+
timestamp: Date.now(),
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
this.emitEvent(types_1.WebRTCEventType.DATA_CHANNEL_MESSAGE, peerId, {
|
|
502
|
+
channel: channel.label,
|
|
503
|
+
message,
|
|
504
|
+
});
|
|
505
|
+
this.config.onDataReceived?.(peerId, channel.label, message);
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
getChannelState(channel) {
|
|
509
|
+
return {
|
|
510
|
+
label: channel.label,
|
|
511
|
+
readyState: channel.readyState,
|
|
512
|
+
bufferedAmount: channel.bufferedAmount,
|
|
513
|
+
bufferedAmountLowThreshold: channel.bufferedAmountLowThreshold,
|
|
514
|
+
reliable: channel.maxRetransmits === null && channel.maxPacketLifeTime === null,
|
|
515
|
+
ordered: channel.ordered,
|
|
516
|
+
protocol: channel.protocol,
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
async initiateConnection(peerId) {
|
|
520
|
+
const peerState = this.peers.get(peerId);
|
|
521
|
+
if (!peerState) {
|
|
522
|
+
throw new Error(`No peer state for: ${peerId}`);
|
|
523
|
+
}
|
|
524
|
+
const { connection } = peerState;
|
|
525
|
+
connection.state = types_1.ConnectionState.CONNECTING;
|
|
526
|
+
this.emitEvent(types_1.WebRTCEventType.CONNECTION_STATE_CHANGED, peerId, types_1.ConnectionState.CONNECTING);
|
|
527
|
+
try {
|
|
528
|
+
// Create offer
|
|
529
|
+
const offer = await connection.rtcConnection.createOffer();
|
|
530
|
+
await connection.rtcConnection.setLocalDescription(offer);
|
|
531
|
+
// Send offer via signaling
|
|
532
|
+
if (this.signaling && offer.sdp) {
|
|
533
|
+
await this.signaling.sendOffer(peerId, offer.sdp, connection.metadata);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
catch (error) {
|
|
537
|
+
connection.state = types_1.ConnectionState.FAILED;
|
|
538
|
+
this.emitEvent(types_1.WebRTCEventType.CONNECTION_ERROR, peerId, error);
|
|
539
|
+
this.config.onError?.(peerId, error);
|
|
540
|
+
throw error;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
async handleRemoteOffer(peerId, sdp, metadata) {
|
|
544
|
+
// Create connection if doesn't exist
|
|
545
|
+
let peerState = this.peers.get(peerId);
|
|
546
|
+
if (!peerState) {
|
|
547
|
+
await this.connect(peerId, { initiator: false, metadata });
|
|
548
|
+
peerState = this.peers.get(peerId);
|
|
549
|
+
}
|
|
550
|
+
if (!peerState) {
|
|
551
|
+
throw new Error(`Failed to create connection for: ${peerId}`);
|
|
552
|
+
}
|
|
553
|
+
const { connection } = peerState;
|
|
554
|
+
try {
|
|
555
|
+
// Set remote description
|
|
556
|
+
await connection.rtcConnection.setRemoteDescription({
|
|
557
|
+
type: 'offer',
|
|
558
|
+
sdp,
|
|
559
|
+
});
|
|
560
|
+
// Add any pending ICE candidates
|
|
561
|
+
for (const candidate of peerState.pendingCandidates) {
|
|
562
|
+
await peerState.iceManager.addRemoteCandidate(candidate);
|
|
563
|
+
}
|
|
564
|
+
peerState.pendingCandidates = [];
|
|
565
|
+
// Create and send answer
|
|
566
|
+
const answer = await connection.rtcConnection.createAnswer();
|
|
567
|
+
await connection.rtcConnection.setLocalDescription(answer);
|
|
568
|
+
if (this.signaling && answer.sdp) {
|
|
569
|
+
await this.signaling.sendAnswer(peerId, answer.sdp);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
catch (error) {
|
|
573
|
+
connection.state = types_1.ConnectionState.FAILED;
|
|
574
|
+
this.emitEvent(types_1.WebRTCEventType.CONNECTION_ERROR, peerId, error);
|
|
575
|
+
this.config.onError?.(peerId, error);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
async handleRemoteAnswer(peerId, sdp) {
|
|
579
|
+
const peerState = this.peers.get(peerId);
|
|
580
|
+
if (!peerState) {
|
|
581
|
+
console.warn(`Received answer for unknown peer: ${peerId}`);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
await peerState.connection.rtcConnection.setRemoteDescription({
|
|
586
|
+
type: 'answer',
|
|
587
|
+
sdp,
|
|
588
|
+
});
|
|
589
|
+
// Add any pending ICE candidates
|
|
590
|
+
for (const candidate of peerState.pendingCandidates) {
|
|
591
|
+
await peerState.iceManager.addRemoteCandidate(candidate);
|
|
592
|
+
}
|
|
593
|
+
peerState.pendingCandidates = [];
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
peerState.connection.state = types_1.ConnectionState.FAILED;
|
|
597
|
+
this.emitEvent(types_1.WebRTCEventType.CONNECTION_ERROR, peerId, error);
|
|
598
|
+
this.config.onError?.(peerId, error);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
async handleRemoteIceCandidate(peerId, candidate) {
|
|
602
|
+
const peerState = this.peers.get(peerId);
|
|
603
|
+
if (!peerState) {
|
|
604
|
+
console.warn(`Received ICE candidate for unknown peer: ${peerId}`);
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
// If remote description not set yet, queue the candidate
|
|
608
|
+
if (!peerState.connection.rtcConnection.remoteDescription) {
|
|
609
|
+
peerState.pendingCandidates.push(candidate);
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
try {
|
|
613
|
+
await peerState.iceManager.addRemoteCandidate(candidate);
|
|
614
|
+
}
|
|
615
|
+
catch (error) {
|
|
616
|
+
console.error(`Failed to add ICE candidate from ${peerId}:`, error);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
handlePeerLeft(peerId) {
|
|
620
|
+
const peerState = this.peers.get(peerId);
|
|
621
|
+
if (!peerState) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
// Clean up connection
|
|
625
|
+
this.disconnect(peerId, { notify: false }).catch((error) => {
|
|
626
|
+
console.error(`Error disconnecting from ${peerId}:`, error);
|
|
627
|
+
});
|
|
628
|
+
this.emitEvent(types_1.WebRTCEventType.PEER_LEFT, peerId, { reason: 'peer-left' });
|
|
629
|
+
}
|
|
630
|
+
async handleRenegotiationRequest(peerId, reason) {
|
|
631
|
+
const peerState = this.peers.get(peerId);
|
|
632
|
+
if (!peerState) {
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
// If reason is disconnect, close the connection
|
|
636
|
+
if (reason === 'disconnect') {
|
|
637
|
+
await this.disconnect(peerId, { notify: false });
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
// Otherwise, initiate renegotiation
|
|
641
|
+
if (peerState.isInitiator) {
|
|
642
|
+
await this.initiateConnection(peerId);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
sendIceCandidate(peerId, candidate) {
|
|
646
|
+
if (!this.signaling) {
|
|
647
|
+
console.warn('No signaling client configured');
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
this.signaling.sendIceCandidate(peerId, candidate).catch((error) => {
|
|
651
|
+
console.error(`Failed to send ICE candidate to ${peerId}:`, error);
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
scheduleReconnect(peerId, peerState) {
|
|
655
|
+
const { connection } = peerState;
|
|
656
|
+
const { reconnectConfig } = this.config;
|
|
657
|
+
if (connection.reconnectAttempts >= reconnectConfig.maxAttempts) {
|
|
658
|
+
connection.state = types_1.ConnectionState.FAILED;
|
|
659
|
+
this.emitEvent(types_1.WebRTCEventType.CONNECTION_STATE_CHANGED, peerId, types_1.ConnectionState.FAILED);
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
connection.state = types_1.ConnectionState.RECONNECTING;
|
|
663
|
+
connection.reconnectAttempts++;
|
|
664
|
+
this.emitEvent(types_1.WebRTCEventType.RECONNECTING, peerId, {
|
|
665
|
+
attempt: connection.reconnectAttempts,
|
|
666
|
+
maxAttempts: reconnectConfig.maxAttempts,
|
|
667
|
+
});
|
|
668
|
+
// Calculate delay with exponential backoff and jitter
|
|
669
|
+
const delay = this.calculateReconnectDelay(connection.reconnectAttempts, reconnectConfig);
|
|
670
|
+
peerState.reconnectTimer = setTimeout(async () => {
|
|
671
|
+
try {
|
|
672
|
+
// Close existing connection
|
|
673
|
+
peerState.connection.rtcConnection.close();
|
|
674
|
+
peerState.iceManager.destroy();
|
|
675
|
+
// Recreate connection
|
|
676
|
+
await this.connect(peerId, {
|
|
677
|
+
initiator: peerState.isInitiator,
|
|
678
|
+
metadata: connection.metadata,
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
catch (error) {
|
|
682
|
+
console.error(`Reconnection attempt ${connection.reconnectAttempts} failed:`, error);
|
|
683
|
+
// Schedule another attempt
|
|
684
|
+
const newState = this.peers.get(peerId);
|
|
685
|
+
if (newState) {
|
|
686
|
+
this.scheduleReconnect(peerId, newState);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}, delay);
|
|
690
|
+
}
|
|
691
|
+
calculateReconnectDelay(attempt, config) {
|
|
692
|
+
const exponentialDelay = config.initialDelay * Math.pow(config.multiplier, attempt - 1);
|
|
693
|
+
const cappedDelay = Math.min(exponentialDelay, config.maxDelay);
|
|
694
|
+
const jitter = cappedDelay * config.jitter * (Math.random() * 2 - 1);
|
|
695
|
+
return Math.max(0, cappedDelay + jitter);
|
|
696
|
+
}
|
|
697
|
+
mapConnectionState(rtcState) {
|
|
698
|
+
switch (rtcState) {
|
|
699
|
+
case 'new':
|
|
700
|
+
return types_1.ConnectionState.NEW;
|
|
701
|
+
case 'connecting':
|
|
702
|
+
return types_1.ConnectionState.CONNECTING;
|
|
703
|
+
case 'connected':
|
|
704
|
+
return types_1.ConnectionState.CONNECTED;
|
|
705
|
+
case 'disconnected':
|
|
706
|
+
return types_1.ConnectionState.DISCONNECTED;
|
|
707
|
+
case 'failed':
|
|
708
|
+
return types_1.ConnectionState.FAILED;
|
|
709
|
+
case 'closed':
|
|
710
|
+
return types_1.ConnectionState.CLOSED;
|
|
711
|
+
default:
|
|
712
|
+
return types_1.ConnectionState.NEW;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
emitEvent(type, peerId, data) {
|
|
716
|
+
const event = {
|
|
717
|
+
type,
|
|
718
|
+
timestamp: Date.now(),
|
|
719
|
+
peerId,
|
|
720
|
+
data,
|
|
721
|
+
};
|
|
722
|
+
const handlers = this.eventHandlers.get(type);
|
|
723
|
+
handlers?.forEach((handler) => {
|
|
724
|
+
try {
|
|
725
|
+
handler(event);
|
|
726
|
+
}
|
|
727
|
+
catch (error) {
|
|
728
|
+
console.error(`Event handler error for ${type}:`, error);
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
exports.PeerConnectionManager = PeerConnectionManager;
|
|
734
|
+
exports.default = PeerConnectionManager;
|
|
735
|
+
//# sourceMappingURL=PeerConnectionManager.js.map
|