Shogun Relays - Browser Example

What is this?

This page demonstrates how to use Shogun Relays in a browser environment using CDN. It fetches a list of volunteer GUN relay servers that you can use in your decentralized applications.

Actions

Relay List

Click "Get Relays" to load the relay list...

Usage Example

<!-- Load Gun from CDN -->
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>

<!-- Load Shogun Relays -->
<script src="browser.js"></script>

<script>
  // Get relays and initialize Gun
  ShogunRelays.getRelays().then(relays => {
    console.log('Available relays:', relays)
    
    // Initialize Gun with the relay list
    const gun = Gun({peers: relays})
    
    // Use Gun as usual
    gun.get('test').put({message: 'Hello, decentralized world!'})
  })
  
  // Force update from GitHub
  ShogunRelays.forceListUpdate().then(relays => {
    console.log('Fresh relays from GitHub:', relays)
  })
</script>

Options

// Get relays with custom options
ShogunRelays.getRelays({
  peers: ['https://custom-peer.com/gun'],  // Custom initial peers
  timeout: 3000,                            // Timeout for Gun network query (ms)
  localStorage: true,                       // Use localStorage for Gun
  radisk: true,                             // Use radisk for Gun
  verbose: false                            // Show console logs
}).then(relays => {
  console.log(relays)
})