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 pc = conn['pc']; // Access underlying peer connection for debugging
if (pc) {
// Store original handlers
const originalIceCandidate = pc.onicecandidate;
const originalGatheringStateChange = pc.onicegatheringstatechange;
const originalIceConnectionStateChange = pc.oniceconnectionstatechange;
const originalConnectionStateChange = pc.onconnectionstatechange;
// Wrap handlers to add logging
pc.onicecandidate = (event) => {
// Add new handlers that don't override existing ones
pc.addEventListener('icecandidate', (event) => {
if (event.candidate) {
console.log('🧊 ICE candidate gathered:', {
type: event.candidate.type,
@@ -311,24 +305,19 @@ export default function App() {
} else {
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);
if (originalGatheringStateChange) originalGatheringStateChange.call(pc, event);
};
});
pc.oniceconnectionstatechange = (event) => {
pc.addEventListener('iceconnectionstatechange', () => {
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);
if (originalConnectionStateChange) originalConnectionStateChange.call(pc, event);
};
});
}
};