Phoenix Games

Events to Iframe

Send events from your platform to the game

Send events from your platform to the Phoenix Games iframe using the postMessage API.

Sending Events

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

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

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.phoenixbet.io)
  • Avoid sending sensitive data through postMessage