# VDO.Ninja SDK - TURN Only Mode Example

### What is TURN-Only Mode?

TURN-only mode (relay mode) forces all WebRTC traffic through a TURN server, bypassing direct peer-to-peer connections. This is useful for:

- Testing TURN server functionality
- Ensuring privacy by hiding IP addresses
- Corporate networks with strict firewall rules
- Scenarios requiring traffic to go through specific servers

### ⚠️ Important Notes

- TURN-only mode requires valid TURN server credentials
- Connection quality may be lower due to relay overhead
- Bandwidth costs increase as all traffic goes through TURN
- The default TURN servers may have usage limits

## Configuration

ICE Transport Policy:
Custom TURN Server (optional):

## ICE Candidates Monitor

This shows what types of ICE candidates are being gathered:

Ready to test...
No candidates collected yet
Summary: Host: 0 | Server Reflexive: 0 | Relay: 0

## TURN Connection Test

Test actual connection establishment using selected ICE policy:

Ready to test...

### Publisher

-

### Viewer

-

## Code Examples

### 1. Basic TURN-Only Configuration

    const sdk = new VDONinjaSDK({
        iceTransportPolicy: 'relay',  // Forces TURN-only mode
        turnServers: [
            {
                urls: 'turn:your-turn-server.com:3478',
                username: 'your-username',
                credential: 'your-password'
            }
        ]
    });

### 2. Quick View with TURN-Only

    const sdk = new VDONinjaSDK({
        iceTransportPolicy: 'relay'
    });

    const { pc, cleanup } = await sdk.quickView({
        streamID: 'some-stream',
        room: 'secure-room'
    });

    // All connections will use TURN relay

### 3. Detecting Connection Type

    pc.onicecandidate = (event) => {
        if (event.candidate) {
            const candidate = event.candidate.candidate;

            if (candidate.includes('typ host')) {
                console.log('Host candidate (direct)');
            } else if (candidate.includes('typ srflx')) {
                console.log('Server reflexive (STUN)');
            } else if (candidate.includes('typ relay')) {
                console.log('Relay candidate (TURN)');
            }
        }
    };