Real-Time Communication
The Predictu widget and your casino page communicate in real time through a structured, bidirectional messaging protocol. This keeps your casino shell perfectly synchronized with everything happening inside the prediction market experience — from balance changes to trade confirmations.
Bidirectional Communication
Messages flow in both directions between your casino page and the embedded Predictu widget. Each message type serves a specific purpose in keeping the two systems in sync.
Your Casino Page to the Widget
Your casino page initiates communication by sending commands to the widget:
| Action | Purpose | When to Use |
|---|---|---|
| Session initialization | Authenticate the player and set their starting balance inside the widget | After the widget loads on the page |
| Deposit notification | Notify the widget that the player has deposited funds through your cashier | When a player deposits money via your casino's payment system |
| Withdrawal notification | Notify the widget that the player has withdrawn funds through your cashier | When a player withdraws money via your casino's payment system |
The Widget to Your Casino Page
The widget sends events back to your casino page whenever something meaningful happens:
| Event | Purpose | What You Can Do With It |
|---|---|---|
| Ready signal | The widget is fully loaded, authenticated, and ready for interaction | Hide your loading skeleton and reveal the widget |
| Balance update | The player's balance has changed (after a trade, settlement, or deposit) | Update the balance display in your casino's header or wallet area |
| Trade confirmation | A trade was successfully executed | Show a notification, log analytics, or trigger animations in your casino shell |
| Navigation update | The player navigated to a different section within the widget | Sync your browser URL for deep linking, track page views in analytics, or adjust widget sizing |
Session Lifecycle
The communication follows a predictable lifecycle:
Re-Initialization Support
You can re-send the initialization message at any time — for example, if your page reloads, if the player's balance changes from an external source, or if you need to switch player sessions. The widget gracefully re-authenticates and updates its state each time.
Origin Security
All communication is protected by origin validation on both sides:
- Your side: Always verify that incoming messages originate from the Predictu widget before processing them.
- Widget side: The widget validates every incoming message against your operator's registered origin whitelist. Messages from unregistered domains are silently ignored.
- Outbound targeting: When the widget sends messages to your page, it targets your specific origin rather than broadcasting to all listeners.
Security Model
The communication protocol is designed with defense in depth:
| Concern | Protection |
|---|---|
| Unauthorized messages | Both sides validate message origins against registered whitelists before processing. |
| Balance manipulation | Balance messages trigger server-side verification. The operator's wallet is always the source of truth. |
| Clickjacking | The widget sandbox prevents top-level navigation. All trades require explicit user confirmation within the widget. |
| Session hijacking | Player identity is verified server-side during initialization. Client-side messages alone cannot establish a session. |
Key Benefits
- Instant synchronization — your casino shell always reflects the latest balance and activity.
- Flexible integration — react to events in whatever way makes sense for your UI (notifications, animations, analytics, deep linking).
- Secure by design — origin validation and server-side verification prevent unauthorized access.
- Graceful re-initialization — supports page reloads, session switches, and external balance changes without disruption.
