From 44839e03179c777ea0a82a2a375fe8ec184347d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Gierwia=C5=82o?= Date: Sat, 15 Nov 2025 16:18:35 +0100 Subject: [PATCH] feat: switch to STUN servers for production NAT traversal Changed WebRTC config from localhost-only to STUN servers: - Removed rtcConfigLocalhost (no longer needed) - Using rtcConfig with Google STUN servers - Enables NAT traversal for users on different networks - Removed unnecessary iceCandidatePoolSize config - Link sharing remains as fallback for blocked users --- frontend/src/hooks/useWebRTC.js | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/frontend/src/hooks/useWebRTC.js b/frontend/src/hooks/useWebRTC.js index 60c4685..618679b 100644 --- a/frontend/src/hooks/useWebRTC.js +++ b/frontend/src/hooks/useWebRTC.js @@ -1,20 +1,13 @@ import { useState, useEffect, useRef, useCallback } from 'react'; import { getSocket } from '../services/socket'; -// WebRTC configuration with STUN servers +// WebRTC configuration with STUN servers for NAT traversal const rtcConfig = { iceServers: [ { urls: 'stun:stun.l.google.com:19302' }, { urls: 'stun:stun1.l.google.com:19302' }, { urls: 'stun:stun2.l.google.com:19302' }, ], - iceTransportPolicy: 'all', // Use all candidates (host, srflx, relay) - iceCandidatePoolSize: 10, // Pre-gather candidates -}; - -// Alternative config for localhost testing (no STUN) -const rtcConfigLocalhost = { - iceServers: [], // No STUN - use only host candidates for localhost }; // File chunk size (16KB recommended for WebRTC DataChannel) @@ -68,10 +61,10 @@ export const useWebRTC = (matchId, userId) => { return peerConnectionRef.current; } - // Use localhost config for testing (no STUN servers) - const pc = new RTCPeerConnection(rtcConfigLocalhost); + // Use full config with STUN servers for production + const pc = new RTCPeerConnection(rtcConfig); peerConnectionRef.current = pc; - console.log('🔧 Using rtcConfigLocalhost (no STUN servers)'); + console.log('🔧 Using rtcConfig with STUN servers for NAT traversal'); // ICE candidate handler pc.onicecandidate = (event) => {