Fix ICE candidate handling by using addEventListener

Changed from overwriting onicecandidate handlers (which broke the 'this' context) to using addEventListener. This ensures the connection manager's handlers can properly send ICE candidates without context issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-15 13:31:21 +01:00
parent caedff590f
commit 1ac1121793

View File

@@ -288,18 +288,12 @@ export default function App() {
}; };
}; };
// Add ICE debugging to a connection (without overwriting existing handlers) // Add ICE debugging to a connection
const addIceLogging = (conn) => { const addIceLogging = (conn) => {
const pc = conn['pc']; // Access underlying peer connection for debugging const pc = conn['pc']; // Access underlying peer connection for debugging
if (pc) { if (pc) {
// Store original handlers // Add new handlers that don't override existing ones
const originalIceCandidate = pc.onicecandidate; pc.addEventListener('icecandidate', (event) => {
const originalGatheringStateChange = pc.onicegatheringstatechange;
const originalIceConnectionStateChange = pc.oniceconnectionstatechange;
const originalConnectionStateChange = pc.onconnectionstatechange;
// Wrap handlers to add logging
pc.onicecandidate = (event) => {
if (event.candidate) { if (event.candidate) {
console.log('🧊 ICE candidate gathered:', { console.log('🧊 ICE candidate gathered:', {
type: event.candidate.type, type: event.candidate.type,
@@ -311,24 +305,19 @@ export default function App() {
} else { } else {
console.log('🧊 ICE gathering complete'); console.log('🧊 ICE gathering complete');
} }
// Call original handler });
if (originalIceCandidate) originalIceCandidate.call(pc, event);
};
pc.onicegatheringstatechange = (event) => { pc.addEventListener('icegatheringstatechange', () => {
console.log('🧊 ICE gathering state:', pc.iceGatheringState); console.log('🧊 ICE gathering state:', pc.iceGatheringState);
if (originalGatheringStateChange) originalGatheringStateChange.call(pc, event); });
};
pc.oniceconnectionstatechange = (event) => { pc.addEventListener('iceconnectionstatechange', () => {
console.log('🧊 ICE connection state:', pc.iceConnectionState); console.log('🧊 ICE connection state:', pc.iceConnectionState);
if (originalIceConnectionStateChange) originalIceConnectionStateChange.call(pc, event); });
};
pc.onconnectionstatechange = (event) => { pc.addEventListener('connectionstatechange', () => {
console.log('🔌 Connection state:', pc.connectionState); console.log('🔌 Connection state:', pc.connectionState);
if (originalConnectionStateChange) originalConnectionStateChange.call(pc, event); });
};
} }
}; };