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
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user