Class HttpTtyConnection

java.lang.Object
org.aesh.terminal.AbstractConnection
org.aesh.terminal.http.HttpTtyConnection
All Implemented Interfaces:
AutoCloseable, Connection

public abstract class HttpTtyConnection extends AbstractConnection
A connection to an http client, independent of the protocol, it could be straight WebSockets or SockJS, etc...

The incoming protocol is based on JSON messages with an "action" field:

init - Client capability reporting (sent on connect)


 {
   "action": "init",
   "type": "xterm-256color",
   "colorDepth": "TRUE_COLOR",
   "features": ["UNICODE", "CLIPBOARD"],
   "cols": 80,
   "rows": 24,
   "userAgent": "Mozilla/5.0 ..."
 }
 

read - User terminal input


 {
   "action": "read",
   "data": "what the user typed"
 }
 

resize - Terminal size change


 {
   "action": "resize",
   "cols": 120,
   "rows": 40
 }
 
Author:
Julien Viet, Matej Lazar
  • Field Details

    • DEFAULT_SIZE

      public static final Size DEFAULT_SIZE
      Default terminal size (80 columns x 24 rows).
  • Constructor Details

    • HttpTtyConnection

      public HttpTtyConnection()
      Creates a new HTTP TTY connection with default charset (UTF-8) and size (80x24).
    • HttpTtyConnection

      public HttpTtyConnection(Charset charset, Size size)
      Creates a new HTTP TTY connection with the specified charset and size.
      Parameters:
      charset - the character encoding for the connection
      size - the initial terminal size
  • Method Details

    • isInitialized

      public boolean isInitialized()
      Returns whether the client has sent an init message.
      Returns:
      true if the client has initialized the connection
    • outputEncoding

      public Charset outputEncoding()
    • inputEncoding

      public Charset inputEncoding()
    • lastAccessedTime

      public long lastAccessedTime()
      Returns the timestamp of the last access to this connection.
      Returns:
      the last accessed time in milliseconds since epoch
    • device

      public Device device()
    • write

      protected abstract void write(byte[] buffer)
      Writes raw bytes to the underlying transport.
      Parameters:
      buffer - the bytes to write
    • writeToDecoder

      public void writeToDecoder(String msg)
      Processes an incoming JSON message from the client and writes it to the decoder.

      Handles the following actions:

      • init - Client capability reporting (type, colorDepth, features, cols, rows)
      • read - Terminal input from the user
      • resize - Terminal resize events
      Parameters:
      msg - the JSON message from the client
    • getTerminalTypeHandler

      public Consumer<String> getTerminalTypeHandler()
      Returns the handler for terminal type events.
      Returns:
      the terminal type handler, or null if not set
    • setTerminalTypeHandler

      public void setTerminalTypeHandler(Consumer<String> handler)
      Sets the handler for terminal type events.
      Parameters:
      handler - the handler to invoke when terminal type is received
    • size

      public Size size()
    • close

      public void close()
    • openBlocking

      public void openBlocking()
    • openNonBlocking

      public void openNonBlocking()
    • put

      public boolean put(Capability capability, Object... params)
    • setAttributes

      public void setAttributes(Attributes attr)
      Specified by:
      setAttributes in interface Connection
      Overrides:
      setAttributes in class AbstractConnection
    • supportsAnsi

      public boolean supportsAnsi()