Documentation

Screen Pages

The messages a screen's page receives and posts back.

A screen shows a page of your resource as a DUI. The page runs in its own browser on each client that is near the screen. Keep what it shows in setState, since the page is built again whenever a player comes back into range.

General Information

The page's URL carries two query parameters: zykeScreen, the screen's id, and zykeResource, the resource name of zyke_devices. The page needs both to post back.

#Messages to the Page

The page receives {event, data} messages through window's message event.

EventData
stateWhat your resource last passed to setState. Sent when the page is up, and again whenever the state changes
key{key, shift} for each typed key while a device with keyboard = true uses this screen
Your ownWhatever your resource sends with screen:send(event, data)

key names follow KeyboardEvent.key: letters, digits, " ", "-", ".", ",", "Backspace", "Tab", "Enter", "Delete", and the four arrow keys such as "ArrowLeft". Letters are lowercase, or uppercase while Shift is held.

While a device uses the screen as its touch screen, mouse moves, clicks, and the wheel arrive as real DOM events.

#Posting From the Page

The page posts {screen, event, data} to https://<zykeResource>/screen:

Example:

js
const params = new URLSearchParams(location.search);

function post(event, data) {
    fetch(`https://${params.get("zykeResource")}/screen`, {
        method: "POST",
        body: JSON.stringify({screen: params.get("zykeScreen"), event, data}),
    }).catch(() => {});
}

window.addEventListener("message", (e) => {
    if (e.data.event === "state") render(e.data.data);
});

post("ready");
post("cursor", {state: "hover"});
post("result", {seconds: 12});
EventPurpose
readyThe page listens for messages. The state is sent again, so post it after adding the message listener
cursor{state: "hover"} shows a hand cursor while the mouse is over something clickable. Post {state: "none"} when it leaves
Any otherPassed to the screen's onMessage(event, data). data is always a table

A page that never posts ready is treated as ready 1.5 seconds after its DUI is available.

Messages from the page come from the client. Check anything that matters, such as a hack result, on your server.

#Examples

  • Keypad: a screen that shows the code being entered, and buttons for the digits. onPress checks each press on the server and calls setState with the new entry.
  • Card reader: a screen and one or two buttons, such as the slot and a confirm key. The swipe animation goes in anim, and the page shows the reader's state from setState.
  • Laptop hack: a screen used with keyboard = true. The minigame runs in the page, clicks and the wheel arrive as DOM events, and typed keys as key messages. The page posts its result to onMessage, and your resource checks it on the server.