Documentation
¶
Overview ¶
Package wire is the protocol between the host and the on-device agents.
One TCP connection carries everything in both directions. Each message is a single line of JSON. A message may carry binary data (a screenshot): it then has a "bin" field with the byte count, and that many raw bytes follow the newline.
The host sends requests: {"id":7,"op":"tap","x":100,"y":200} The agent answers each: {"id":7,"ok":true,...} or {"id":7,"ok":false,"error":"..."} The agent also pushes events without being asked (no "id"):
{"ev":"changed","seq":41} the UI changed (an accessibility event arrived)
{"ev":"settled","seq":41} no change for the quiet window since seq 41
The host never polls: it waits on these events.
Index ¶
- type AgentError
- type Conn
- func (c *Conn) Abandoned() int
- func (c *Conn) Call(op string, params map[string]any, timeout time.Duration) (*Msg, error)
- func (c *Conn) CallContext(ctx context.Context, op string, params map[string]any, timeout time.Duration) (*Msg, error)
- func (c *Conn) CallUnqueued(ctx context.Context, op string, params map[string]any, timeout time.Duration) (*Msg, error)
- func (c *Conn) Close() error
- func (c *Conn) Done() <-chan struct{}
- func (c *Conn) Err() error
- func (c *Conn) Hello() *Msg
- func (c *Conn) HelloVersion() string
- func (c *Conn) Seq() int64
- func (c *Conn) SettledSeq() int64
- func (c *Conn) Subscribe() chan *Msg
- func (c *Conn) Unsubscribe(ch chan *Msg)
- type Msg
- type ReplyTimeout
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentError ¶
AgentError is an error the agent reported for a request. Transient is the reply's "transient": the agent says asking again may succeed.
func (*AgentError) Error ¶
func (e *AgentError) Error() string
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a connection to one agent.
func (*Conn) Abandoned ¶ added in v0.5.3
Abandoned is how many requests given up on (CallContext) the device may still be running: a request sent now waits behind them.
func (*Conn) Call ¶
Call sends a request and waits for its answer. params is merged into the request.
func (*Conn) CallContext ¶ added in v0.5.3
func (c *Conn) CallContext(ctx context.Context, op string, params map[string]any, timeout time.Duration) (*Msg, error)
CallContext is Call that also ends with ctx (issue #202):
- a ctx already done when CallContext is called sends nothing and returns ctx.Err() (context.Canceled, or context.DeadlineExceeded for a deadline already past);
- a wait for the answer that ctx ends returns ctx.Err() when ctx was cancelled, and a *ReplyTimeout when its deadline passed, as a wait cut to the time left did before: callers tell a late answer by its type;
- an answer that has arrived when ctx ends (or the timeout passes) is returned as the answer: what the agent did is reported done.
The connection stays usable after a call ctx ended. Answers are matched to requests by id, not by order: the call's id leaves pending when it gives up, so the agent's late answer to it finds no caller and is dropped (dispatch), and the next call waits for its own id.
The agents run requests one at a time, in order (Android: one reader thread; iOS: a serial queue), so a request sent after one that was given up on waits on the device until that one is done. The given-up request is remembered with the time it was bounded by (sent + its timeout): a later call's reply timeout starts once the answers to the given-up requests sent before it have arrived, or their bounds have passed, so it is not charged for the time they still take. ctx's own deadline is not moved.
func (*Conn) CallUnqueued ¶ added in v0.5.3
func (c *Conn) CallUnqueued(ctx context.Context, op string, params map[string]any, timeout time.Duration) (*Msg, error)
CallUnqueued is CallContext whose reply timeout starts at once, even with given-up requests still ahead of it on the device. For requests whose answer only says they arrived, sent on the way out (exit, keep): a timeout is better there than waiting, request after request, for every given-up one's bound (issue #202). The request still runs on the device once the ones ahead of it are done.
func (*Conn) HelloVersion ¶
HelloVersion is the agent build version from its greeting.
func (*Conn) SettledSeq ¶
SettledSeq is the change sequence number the latest "settled" event covered.
func (*Conn) Unsubscribe ¶
type Msg ¶
type Msg struct {
ID int64 `json:"id,omitempty"`
OK bool `json:"ok,omitempty"`
Error string `json:"error,omitempty"`
// Transient marks an error the agent says is the device's passing state, not the
// request's own failure: the host may ask again (iOS launch, issue #126).
Transient bool `json:"transient,omitempty"`
Ev string `json:"ev,omitempty"`
Seq int64 `json:"seq,omitempty"`
Bin int `json:"bin,omitempty"`
Raw json.RawMessage `json:"-"`
Data []byte `json:"-"`
}
Msg is a decoded message. Raw keeps the full JSON so callers can decode op-specific fields.
type ReplyTimeout ¶ added in v0.5.0
ReplyTimeout means the request was sent but the agent's answer did not arrive. Queued: ctx's deadline ended it while it waited, at least in part, behind requests given up on (CallContext).
func (*ReplyTimeout) Error ¶ added in v0.5.0
func (e *ReplyTimeout) Error() string