Documentation
¶
Overview ¶
Package hostscreen serves the host_screen.* methods of one bridge connection (ホストの画面, ADR 0008): it lists what can be shown, runs at most one stream and paces its frames to the app's acks. Each kind of target (browser, Android emulator, iOS simulator) is a Kind in its own package.
Index ¶
- Constants
- Variables
- func CheckInput(in wire.HostScreenInput) error
- func DetectWSL(fsys fs.FS) bool
- func WSLNote(wsl bool) *wire.HostScreenNote
- type Events
- type Frame
- type Inputter
- type Kind
- type PortsKind
- type Server
- func (s *Server) Ack(seq int64) error
- func (s *Server) Input(ctx context.Context, in wire.HostScreenInput) (wire.HostScreenInputResult, error)
- func (s *Server) List(ctx context.Context, p wire.HostScreenListParams) (map[string]any, error)
- func (s *Server) Pause() error
- func (s *Server) Resume() error
- func (s *Server) Serves(kind string) bool
- func (s *Server) Start(ctx context.Context, t wire.HostScreenTarget, started func()) error
- func (s *Server) Stop()
- type Stream
Constants ¶
const ( // MaxInFlight is how many frames may wait for the app's ack. MaxInFlight = 2 // StallAfter is how long the app may hold MaxInFlight frames before // the stream is paused; its next ack resumes it with a full frame. StallAfter = 2 * time.Second // FrameEvery is the least time between two frames sent: at most 10 // a second (ADR 0008 "通信量と電池", #634). FrameEvery = 100 * time.Millisecond )
const ( MaxDragPoints = 1000 MaxDragDuration = 10_000 // ms // MaxScroll bounds dx and dy: the fingers may cross a fitted frame // several times over. MaxScroll = 10 )
Bounds of an input, so one request cannot hold the input queue long.
const WatchEvery = 3 * time.Second
WatchEvery is how often a target that is gone is looked for again (#633).
Variables ¶
var IsWSL = sync.OnceValue(func() bool { return runtime.GOOS == "linux" && DetectWSL(os.DirFS("/")) })
IsWSL is DetectWSL of this host, looked at once; false off Linux.
Functions ¶
func CheckInput ¶
func CheckInput(in wire.HostScreenInput) error
CheckInput refuses with bad_request an input whose shape is wrong for its type: a point outside the frame (0–1), a drag of fewer than two points, a text without text or enter, an unknown key or action, a navigate to an empty url. Whether the target takes it is the stream's to say.
func DetectWSL ¶ added in v0.12.0
DetectWSL tells whether fsys (the root file system) is that of a Linux running inside Windows' WSL: the kernel's release names Microsoft, or WSL's interop with Windows binaries is registered.
func WSLNote ¶ added in v0.12.0
func WSLNote(wsl bool) *wire.HostScreenNote
WSLNote is the note of a kind whose targets a WSL host may run on the Windows side, where it does not look (browsers, Android emulators): nil unless wsl.
Types ¶
type Events ¶
type Events interface {
Frame(Frame)
// State reports wire.HostScreenLive (with the target's title and URL
// when it has them) or wire.HostScreenGone, after which no call
// follows, but for a target that comes back (see Reviving): live
// again, then frames as after Start, the stream not paused.
State(wire.HostScreenState)
}
Events receives what a Stream produces. A Stream calls it from its own goroutines; the calls need not be serialized.
type Frame ¶
type Frame struct {
Data string // base64 of one JPEG
Width, Height int // the target's size in its own coordinates
}
Frame is one picture of a target.
type Inputter ¶
type Inputter interface {
// Input performs in on the target (already checked by CheckInput:
// points within the frame, the fields its type needs) and returns once
// the target took it, with host_screen.input's result (empty but for
// an iOS simulator's text). Inputs come one at a time, in the order the
// app sent them; Input may block on the target, never on the app's
// acks. Errors are *wire.Error: unsupported for an input the kind does
// not take.
Input(ctx context.Context, in wire.HostScreenInput) (wire.HostScreenInputResult, error)
}
Inputter is a Stream that takes host_screen.input; a Stream without it answers every input unsupported.
type Kind ¶
type Kind interface {
// Name is the target kind and the key of its section.
Name() string
// List returns the section (a wire.HostScreenSection).
List(ctx context.Context) (any, error)
// Open connects to t (t.Kind is Name()). Errors are *wire.Error:
// bad_request, not_found or unavailable.
Open(ctx context.Context, t wire.HostScreenTarget) (Stream, error)
}
Kind is one kind of target: its section of host_screen.list and its streams.
type PortsKind ¶
type PortsKind interface {
Kind
// ListPorts is List plus ports (each 1–65535, without repeats).
ListPorts(ctx context.Context, ports []int) (any, error)
}
PortsKind is a Kind whose section also lists the CDP ports the app named by hand (host_screen.list's cdp_ports): the browser kind.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the host_screen.* state of one bridge connection.
func NewServer ¶
NewServer serves kinds, writing notifications with notify (safe for concurrent use).
func (*Server) Input ¶
func (s *Server) Input(ctx context.Context, in wire.HostScreenInput) (wire.HostScreenInputResult, error)
Input answers host_screen.input: it checks in, then has the current stream perform it. The caller runs inputs one at a time in the app's order (with Start and Stop); acks never wait for them.
func (*Server) List ¶
List answers host_screen.list: one section per kind. A port of p.CDPPorts outside 1–65535 is bad_request.
func (*Server) Pause ¶ added in v0.12.0
Pause answers host_screen.pause: the app does not show the stream, so its target is no longer captured and the frame held is dropped. Like Ack, it never waits for the target. Pausing a paused stream does nothing.
func (*Server) Resume ¶ added in v0.12.0
Resume answers host_screen.resume: the target is captured again, beginning with a full frame. Resuming a stream not paused does nothing.
type Stream ¶
type Stream interface {
// Start begins delivery: State live first, then a full frame, then a
// frame whenever the target changes.
Start(Events)
// Pause stops capturing: while the app is stalled, or while it does
// not show the stream (host_screen.pause).
Pause()
// Resume captures again, beginning with a full frame (the target may
// not change by itself).
Resume()
// Close stops the stream and waits for its goroutines: no Events call
// follows its return.
Close()
}
Stream is one target being shown. Its methods do not block on the target, except Close.
func Reviving ¶ added in v0.12.0
Reviving shows a target that may stop and start again (#633): first, then, once that reports gone, whatever reopen opens. While the target is gone, reopen is called every interval until it returns a stream (nil: not back yet), which is started: its live tells the app the target is back. With first nil the target is not running yet: Start reports gone and looks for it the same way. reopen ends when its ctx does; a stream it returns then is closed. Close stops looking and closes the stream.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package android is the Android emulator kind of the host screen (ADR 0008): the emulators `adb devices` lists, matched with the files in which they advertise their gRPC port, and one shown through the emulator's gRPC streamScreenshot.
|
Package android is the Android emulator kind of the host screen (ADR 0008): the emulators `adb devices` lists, matched with the files in which they advertise their gRPC port, and one shown through the emulator's gRPC streamScreenshot. |
|
emupb
Package emupb is the Go code of the Android emulator's gRPC service, generated from emulator_controller.proto.
|
Package emupb is the Go code of the Android emulator's gRPC service, generated from emulator_controller.proto. |
|
Package browser is the browser kind of the host screen (ADR 0008): the Chromium-family browsers of the user that opened a CDP port, and a page target of one shown through Page.startScreencast.
|
Package browser is the browser kind of the host screen (ADR 0008): the Chromium-family browsers of the user that opened a CDP port, and a page target of one shown through Page.startScreencast. |
|
Package ios is the iOS simulator kind of the host screen (ADR 0008, macOS only): the booted simulators simctl lists, one shown through an idb_companion stagent starts for the stream (#630).
|
Package ios is the iOS simulator kind of the host screen (ADR 0008, macOS only): the booted simulators simctl lists, one shown through an idb_companion stagent starts for the stream (#630). |
|
idbpb
Package idbpb is the generated client of idb_companion's gRPC API (idb.proto, a subset of facebook/idb v1.6.8).
|
Package idbpb is the generated client of idb_companion's gRPC API (idb.proto, a subset of facebook/idb v1.6.8). |