Does: lets a lease's holder (or an operator) send taps, keys, buttons and rotations to its device over WS /v1/leases/{id}/input, on a worker and through a gateway, in expo serve-sim's messages.
- Nothing here imports
ws: a socket is aLeaseSocket, whichever door the client came in by. - Lease ownership is checked by the HTTP layer only. The worker's own registry decides whether the lease still exists: it can end between that check and the upgrade.
- A lease has one device input, the daemon's (
ctx.inputs.leaseInput), shared by every socket of the lease and bydevice.rotate. The session holds it once and gives it back when the last socket leaves, the lease ends, the daemon drains or the input fails. - An unavailable device input is not an error: the socket is admitted, gets
UNAVAILABLE_INPUT_CONFIGand its messages are dropped. - A client message that
parseClientMessage(core) refuses is dropped and the socket stays. The device input decides what a valid message does. - A worker closes a socket only with a code
closeOf(modules/relay-channel.ts) lets through; any other code reaches a gateway's client as "the worker stopped answering". wsthrows on a close reason over its byte limit, andsessions.tscuts nothing: it closes only with fixed texts and the lease-end reason. A reason a peer or a driver chose goes throughcloseReason(core) first.- The caps on sockets per lease and on retries after a failed open are
MAX_SOCKETS_PER_LEASEandFAILED_OPEN_MEMORY_MS(sessions.ts); both close the socket as a failure, not as a refusal before the upgrade. - The gateway side holds no rule of its own:
gateway-link.tsgivescreateGatewayChannelLinkits path, frame bound and refusal text, and modules owns the bridge.
On a worker:
- The HTTP layer resolves the lease for the caller, then asks the module's
socket.open, which answers a refusal or an accept. - The upgrade router hands the accept the upgraded socket, and the worker link attaches it to the lease's session.
- The session takes the lease's device input from the daemon and, once it is open, tells the socket it is admitted and sends the screen's config; later config changes go to every admitted socket.
- Client messages go through core's parser to the device input.
- The lease end (
beforeDeviceReclaim) and a drain (beforeDrain) close every socket of the session with their own codes and release the device input.
Through a gateway:
- The same
openon the gateway callsrelayTwoWayto the worker'sinputtarget, naming the worker's lease id. A refusal here is answered before the upgrade. - The worker's
relayTwoWayfinds the lease and attaches achannelSocketto the same session a local socket would join. - The gateway's bridge passes client frames to the channel and channel frames to the client; the worker's close frame closes the client.
- If the handshake is refused after the relay opened, the router calls the accept's
abandon, which ends the relay. - When the gateway sees the lease go, it waits a short time for the worker's close frame, which carries the reason, before it closes the client itself.