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:

⚠️ Important Notes

Configuration







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)');
        }
    }
};