LOOK AND TYPE / STUDY / LEVEL 4 OF 5
Two devices,
one picture.
One person, two browsers. The headset knows where my head points but has no keyboard. The laptop has the keyboard but does not know where I look. Neither can do the job alone. So each one shares the one thing it knows, in a variable that only it writes, and both draw the picture from those variables. The headset does not send pictures to the laptop, and the laptop does not send keys to the headset. Below, the two panels are two clients. The only thing that passes between them is the list of variables on the right.
Two clients
drag the left picture; type into the right oneThe headset (client 1)
The laptop (client 2)
Click the right picture and type on your real keyboard, or use the buttons. This page has no AI: after Enter the laptop shows "CHANGING" for two seconds and then says so.
The shared variables
each client's own copyMessages, newest first
Who owns what
js/scenes/hw9/deskTyping.jsThe gaze is sent only when it changes: a new target, or a move of more than 1 cm along the desk. The line is sent after every key that did something. Once a second each client repeats what it owns, so that a client that joined late, or missed a message, catches up.
Whose gaze does the keyboard follow?
js/scenes/hw9/deskTyping.jsEvery gaze carries xr: true or false. The keyboard follows the first client that says it is in a headset and is not the client holding the keyboard. If there is none, it follows its own: the laptop's camera, with Tab to step through the things. That is the desktop fallback.
Drawing from the shared state
js/scenes/hw9/deskTyping.jsThe frame code does not ask "am I the headset or the laptop". It takes the line (its own if this client holds the keyboard, else the shared one) and the focus, and draws. That is why the two pictures agree.
What you should be able to explain
- One writer per variable. Only the headset writes
deskGaze_1. Only the client with the keyboard writesdeskLine. Two clients never write the same variable, so there is nothing to merge. This is the same rule as in Giant & Mini, level 2. - State, not events. The laptop does not send "the R key was pressed". It sends the whole line as it now is. A lost message does no lasting harm, because the next one carries everything again. Cut the connection, turn the head, type, and reconnect: within a second both pictures agree again.
- The lock lives on the laptop. Set the network to 1.5 s. Look at the house, type one letter, and look at the cup straight away. The line stays on the house:
lineKeyran on the laptop with the focus the laptop had at that moment. - What else is shared. Notes are shared one thing at a time:
deskNotes[target]. The things themselves are ingiantMiniThings[id], from the Giant & Mini scene. Only the laptop asks the AI; it then puts the result into that variable, and every client rebuilds the thing's picture. This page has no things to change, so that variable is not shown. - What
busyis for. While the AI works, the laptop putsbusy = {target, at, text}into the line. Every client draws it above the target. Nobody needs a separate "the AI is thinking" message.
Exercises: ① Set the network to 1.5 s and look from the house to the cup. How long is the laptop's ring on the wrong thing? Which variable is late? ② Cut the connection, type a word and press Shift+Enter. What does the headset show? Reconnect and wait. Which line of the scene brings the note across? ③ Look at an empty place, type a letter, then look away. Why does the laptop's line keep its own at instead of using the gaze's?