01 / Build the connection

Send updates to the game

Pass supported platform events into the game iframe.

Use the browser postMessage API to send supported events from your page into the embedded game.

Sending Events

const gameIframe = document.getElementById('game-iframe');
gameIframe.contentWindow.postMessage(eventData, 'https://games.wildvoltgames.com');

Event Types

Balance Update

Notify the game when the player's balance changes outside of game actions.

{
  type: 'BALANCE_UPDATE',
  balance: 1234.56,
  timestamp: Date.now()
}

Game Control

Send control commands to the game.

{
  type: 'GAME_CONTROL',
  action: 'PAUSE' | 'RESUME' | 'STOP',
  timestamp: Date.now()
}

Configuration Update

Update game configuration during runtime.

{
  type: 'CONFIG_UPDATE',
  config: {
    sound_enabled: true,
    auto_play: false
  },
  timestamp: Date.now()
}

Event Timing

  • Wait for iframe load before sending events
  • Check iframe readiness to ensure the game can receive events
  • Handle failures gracefully if events cannot be delivered

Implementation Example

function sendEventToGame(eventType, data) {
  const gameIframe = document.getElementById('game-iframe');
  
  if (!gameIframe || !gameIframe.contentWindow) {
    console.error('Game iframe not ready');
    return;
  }
  
  const event = {
    type: eventType,
    ...data,
    timestamp: Date.now()
  };
  
  gameIframe.contentWindow.postMessage(event, 'https://games.wildvoltgames.com');
}

Best Practices

  • Validate iframe existence before sending events
  • Include timestamps in all events for debugging
  • Handle delivery failures appropriately
  • Target specific origin for security (https://games.wildvoltgames.com)
  • Avoid sending sensitive data through postMessage

On this page