YOM supports bidirectional communication between your webpage and the game stream. Send commands to the game and listen for events coming back.
Sending Commands to the Game
Use window.postToPlayer() to send commands to a running stream:
window.postToPlayer(streamId, commandName, data);
| Parameter | Type | Description |
|---|---|---|
streamId | string | Must match the data-yom-stream-id of the target stream |
commandName | string | The function name registered in your game (see Registering Events) |
data | object | Key-value pairs passed to the game function |
Example: Bot Controls
<button onclick="window.postToPlayer('1', 'SpawnBot', {amount: '1'})">Add Bot</button>
<button onclick="window.postToPlayer('1', 'RemoveBot', {amount: '1'})">Remove Bot</button>
<button onclick="window.postToPlayer('1', 'ClearBot', {})">Clear All Bots</button>
Example: Camera Settings
window.postToPlayer('1', 'SetCameraSensitivityX', { MouseSensitivityX: '0.5' });
window.postToPlayer('1', 'SetCameraSensitivityY', { MouseSensitivityY: '0.5' });
Example: Stream Control
window.postToPlayer('1', 'pause', {});
window.postToPlayer('1', 'resume', {});
Listening for Events from the Game
The YOM player sends events to your page via postMessage. Listen for them on the window object:
window.addEventListener('message', function(event) {
// Only trust messages from the YOM player
if (event.origin !== 'https://player.yom.net') return;
const { event: eventName, streamId, data } = event.data;
switch (eventName) {
case 'playerReady':
console.log(`Stream ${streamId} is ready`);
break;
case 'streamActive':
console.log(`Stream ${streamId} is now playing`);
break;
case 'streamClosed':
console.log(`Stream ${streamId} ended`);
break;
case 'error':
console.error(`Stream ${streamId} error:`, data.message);
break;
}
});
Available Events
| Event | When it fires |
|---|---|
playerReady | Stream iframe is loaded and ready |
streamActive | Game has started, player is in the experience |
streamClosed | Player exited or stream ended |
error | Something went wrong |
requestFullscreen | Player requested fullscreen |
exitFullscreen | Player exited fullscreen |
Google Tag Manager Integration
All events from the player are automatically pushed to window.dataLayer for GTM/GA integration:
// Automatically pushed by yom-embed.js
window.dataLayer.push({
'event': 'streamActive',
'category': 'yom-event',
'streamId': '1',
'sessionId': 'abc123'
});
Configure your GTM container to capture yom-event category events for analytics tracking.
Games built with the UE5 SDK can also push custom events directly to the data layer.