# Events and webhooks

## Client events (in the browser)

The client posts messages to the window that opened it (`window.parent`, `window.top`, `window.opener`). Every message is an object with `type` and `timestamp` (Unix ms):

| `type` | Other fields | When |
|---|---|---|
| `POKERPRO_READY` | `version`, `isEmbedded`, `returnUrl` | The client has loaded |
| `POKERPRO_BALANCE_UPDATE` | `balance` (string, minor units), `currency`, `userId` | The player's poker balance changed |
| `POKERPRO_EXIT` | `returnUrl` | The player left the client |
| `POKERPRO_RETURN_TO_OPERATOR` | `returnUrl` | The player pressed "back to casino" |

Messages are sent with target origin `*`: check `event.origin` against `https://pokerpro.rexplay.site` before you trust one.

```js
window.addEventListener('message', (event) => {
  if (event.origin !== 'https://pokerpro.rexplay.site') return;
  const msg = event.data;
  if (msg?.type === 'POKERPRO_BALANCE_UPDATE') showPokerBalance(msg.balance, msg.currency);
  if (msg?.type === 'POKERPRO_RETURN_TO_OPERATOR') closePoker();
});
```

## Webhooks (to your backend)

**Under construction.**
