try now

instant cloud gaming — no download

Event Handling

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);
ParameterTypeDescription
streamIdstringMust match the data-yom-stream-id of the target stream
commandNamestringThe function name registered in your game (see Registering Events)
dataobjectKey-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

EventWhen it fires
playerReadyStream iframe is loaded and ready
streamActiveGame has started, player is in the experience
streamClosedPlayer exited or stream ended
errorSomething went wrong
requestFullscreenPlayer requested fullscreen
exitFullscreenPlayer 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.