Events from Iframe
Handle events sent by the game to your platform
Phoenix Games send events to your platform using the postMessage
API. Listen for these events to update your UI and handle game state changes.
Setting Up Event Listeners
window.addEventListener('message', (event) => {
// Verify origin for security
if (event.origin !== 'https://games.phoenixbet.io') {
return;
}
// Handle the event
handleGameEvent(event.data);
});
Event Types
Balance Update Events
Triggered when the player's balance changes due to game actions.
{
type: 'BALANCE_UPDATE',
balance: 1234.56,
timestamp: 1712401234567
}
Game Ready Events
Triggered when the game has fully loaded and is ready for player interaction.
{
type: 'GAME_READY',
timestamp: 1712401234567
}
Error Events
Sent when the game encounters errors.
{
type: 'ERROR',
code: 'INSUFFICIENT_BALANCE',
message: 'Player does not have sufficient balance',
timestamp: 1712401234567
}
Event Handling Best Practices
- Validate event origin to ensure events come from Phoenix Games
- Validate event structure before processing
- Update UI reactively based on balance changes
- Handle errors gracefully and show appropriate user feedback
- Log events for debugging and analytics
Security Considerations
- Always verify the
event.origin
matches the expected Phoenix Games domain - Validate all event data before using it in your application
- Never trust client-side events for critical operations without server-side validation