Module ws

Module ws 

Source
Expand description

WebSocket handler implementing the tty-web binary protocol.

§Wire protocol

All WebSocket messages are binary frames. The first byte is the command, the rest is the payload.

DirectionCmdPayloadDescription
client → server0x00raw bytesTerminal input
client → server0x01rows(u16 BE) + cols(u16 BE)Resize
server → client0x00raw bytesTerminal output
server → client0x10UUID stringSession ID
server → client0x12Shell exited
server → client0x13rows(u16 BE) + cols(u16 BE)Window size
server → client0x14Replay end

Enums§

ClientCommand 🔒
ResolveError 🔒

Constants§

CLOSE_SESSION_NOT_FOUND 🔒
WebSocket close code: requested session not found.
CMD_INPUT 🔒
Client → Server: terminal input.
CMD_OUTPUT 🔒
Server → Client: terminal output.
CMD_REPLAY_END 🔒
Server → Client: end of scrollback replay.
CMD_RESIZE 🔒
Client → Server: resize (4-byte payload: rows u16 BE, cols u16 BE).
CMD_SESSION_ID 🔒
Server → Client: session UUID string.
CMD_SHELL_EXIT 🔒
Server → Client: shell process exited.
CMD_WINDOW_SIZE 🔒
Server → Client: current PTY window size (4-byte payload: rows u16 BE, cols u16 BE).

Functions§

encode_window_size 🔒
Encode a window size as 4 big-endian bytes (rows, cols).
handle_client_message 🔒
handle_socket 🔒
parse_client_message 🔒
resolve_session 🔒
send_frame 🔒
Send a protocol frame (command byte + payload) over the WebSocket.
ws_handler