# Client Side Messaging You can subscribe to in-game RubyPlay messages using `postMessage API` functionality. ## Game to Wrapper Messages Messages from the game are sent to the parent page. Each message has a standard structure and contains the following fields: ``` type: string; sender: string; lang: string; data?: any; ``` 1. `type` is a string with a specific structure `rp.g2w.RedirectToLobby` where: * `rp` is an abbreviation of RubyPlay * `g2w` is a direction for notification - from game to wrapper * `RedirectToLobby` is a message name 2. `sender` is a string with an ID code of the game from which the notification is being sent 3. `lang` is a string with a language code 4. `data` field is not mandatory and contains any additional data details summary Click here to see message examples... Here are some examples: ``` {"type":"rp.g2w.payTableStatusUpdate","sender":"rp_34","lang":"en","data":{"isOpen":false}} {"type":"rp.g2w.payTableStatusUpdate","sender":"rp_34","lang":"en","data":{"isOpen":true}} {"type":"rp.g2w.gameRulesStatusUpdate","sender":"rp_25","lang":"da","data":{"isOpen":false}} {"type":"rp.g2w.gameRulesStatusUpdate","sender":"rp_25","lang":"da","data":{"isOpen":true}} {"type":"rp.g2w.paidRoundEnded","sender":"rp_76","lang":"en","data":{"win":0,"totalWin":0,"isBigWin":false}} {"type":"rp.g2w.balanceUpdate","sender":"rp_34","lang":"en","data":{"balance":999620}} {"type":"rp.g2w.paidRoundStarted","sender":"rp_54","lang":"es"} ``` The full list of messages that the game can send: table colgroup col col col thead tr th Message Name th Description th Additional Data tbody tr td code rp.g2w.RedirectToLobby td Triggers when a player redirects from the game to the casino lobby. td tr td code rp.g2w.soundStatusUpdate td Triggers every time a player switches sounds in the game. td code enabled: boolean tr td code rp.g2w.loadingEnded td Triggers when the game loading finishes and the Start button appears. td tr td code rp.g2w.gameStarted td Triggers when a player clicks the Start button and the reels become visible. td tr td code rp.g2w.gameRulesStatusUpdate td Triggers when a player opens/closes the game rules. td code isOpen: boolean tr td code rp.g2w.payTableStatusUpdate td Triggers when a player opens/closes the paytable. td code isOpen: boolean tr td code rp.g2w.gameHistoryStatusUpdate td Triggers when a player opens/closes the game history. td code isOpen: boolean tr td code rp.g2w.turboStatusUpdate td Triggers when a player switches turbo mode (on/off). td code enabled: boolean tr td code rp.g2w.fullscreenStatusUpdate td Triggers when a player switches fullscreen mode (on/off). td code enabled: boolean tr td code rp.g2w.feature td Triggers when any game feature starts/ends (free spins, pick bonus, select bonus, etc.). td code inProgress: boolean tr td code rp.g2w.autoplay td Triggers when a player switches autoplay mode (on/off). td code inProgress: boolean tr td code rp.g2w.balanceUpdate td Triggers every time the balance in the game UI is updated (placed bet, win/lose money, etc.). td code balance: number tr td code rp.g2w.systemPopup td Triggers every time the system popup is shown/closed (errors, session timers, inactivity timers, etc.). td code shown: boolean tr td code rp.g2w.paidRoundStarted td Triggers when any paid round starts. td tr td code rp.g2w.paidRoundEnded td Triggers when any paid round ends (any feature won in that round is also part of it). It also contains additional data: br ul li code win : equal to code totalWin if only one action, otherwise it's the win from the last action. li code totalWin : total win from all actions in the round. li code isBigWin : true if it was a base spin with a win over 20 bets. td pre win: number; totalWin: number; isBigWin: boolean; tr td code rp.g2w.betUpdate td Triggers when a player changes the bet. It contains the following additional data: br ul li code betIndex : index of the new bet from available list li code bet : value of the new bet (in cents) li code totalBet : new bet multiplied by wager (in cents) td pre betIndex: number; bet: number; totalBet: number; ## Wrapper to Game Messages For this functionality, the casino must use the `postMessage API` and adhere to the following fields: ``` type: string; data?: any; ``` 1. `type` is a string with a specific structure `rp.w2g.refreshBalance` where: * `rp` is an abbreviation of RubyPlay * `w2g` is a direction for notification - from wrapper to game * `refreshBalance` is a message name 2. `data` field is not mandatory and contains any additional data **IMPORTANT:** The entire message must be a JSON object. For example: ``` {"type":"rp.w2g.refreshBalance"} ``` The list of messages that the wrapper can send to the game: table colgroup col col thead tr th Message Name th Description tbody tr td code rp.w2g.refreshBalance td The casino can send this message to trigger an immediate balance update in the game. When the game receives this message, it will request an update from its server and refresh the UI with the new balance provided in the server's response. tr td code rp.w2g.pause td The casino can send this message to request a game pause. Pausing the game is not an immediate action—it depends on the current state of the slot machine (e.g., it must not be spinning). Once the game receives this message, it sends back a code 'rp.g2w.gamePause': {"pause": true} post message. tr td code rp.w2g.resume td The casino can send this message to request a game resume. Once the game receives this message, it sends back a code 'rp.g2w.gamePause': {"pause": false} post message. tr td code rp.w2g.mute td The casino can send this message to mute the game. Once the game receives this message, it sends back a code 'rp.g2w.soundStatusUpdate': {"enabled": false} post message. tr td code rp.w2g.unmute td The casino can send this message to unmute the game. Once the game receives this message, it sends back a code 'rp.g2w.soundStatusUpdate': {"enabled": true} post message. tr td code rp.w2g.stopAutoPlay td The casino can send this message to stop the autospin mode. Once the game receives this message, it sends back a code 'rp.g2w.autoplay': {"inProgress": false} post message. tr td code rp.w2g.toggleInfoPage td The casino can send this message to open the Info Page pop-up. On mobile, this will open the Settings pop-up and navigate to the Info Page tab. Once the game receives this message, it sends back a code 'rp.g2w.payTableStatusUpdate': {"isOpen": boolean} post message. tr td code rp.w2g.toggleGameRules td The casino can send this message to open the Game Rules pop-up. On mobile, this will open the Settings pop-up and navigate to the Game Rules tab. Once the game receives this message, it sends back a code 'rp.g2w.gameRulesStatusUpdate': {"isOpen": boolean} post message. tr td code rp.w2g.toggleGameHistory td The casino can send this message to open the Game History pop-up. On mobile, this will open the Settings pop-up and navigate to the Game History tab. Once the game receives this message, it sends back a code 'rp.g2w.gameHistoryStatusUpdate': {"isOpen": boolean} post message.