Documentation
¶
Overview ¶
Package mobile is the Go core of the RemoHop Android and iOS apps.
The apps are controllers first: a native shell around a WebView that shows the `remohop web` page. They can also let the phone itself be viewed and, with its owner's consent, controlled (host mode, host.go). This package runs that gateway in the app's own process, on 127.0.0.1 with a random port and a fresh random token per start, and keeps every piece of state (identity key, saved peers, pairing tokens, settings) in a directory the app passes in: its private files directory. Nothing here looks at HOME.
The API is shaped for gomobile: package-level functions taking and returning strings, booleans, integers and errors, with lists as JSON. gomobile cannot bind a package under internal/ (its generated wrapper lives outside this module tree), so mobile/remohopcore re-exports these functions one for one and is what `gomobile bind` is pointed at.
Security: the gateway listens on loopback only, but on Android every app on the device can reach 127.0.0.1, so the token in the URL is the only thing between another app and the user's hosts. The URL is returned to the caller and never logged here; callers must not log it either, and should hand it to the WebView's initial load and nowhere else.
Index ¶
- Constants
- func BreakGatewayListenerForTest(stall bool)
- func CancelPair()
- func CheckRendezvous(addr string) (string, error)
- func CheckSessions()
- func ClearDiagnostics() error
- func CoreVersion() string
- func DecideHostRequest(n int, allow, control bool) error
- func DefaultDeviceName() string
- func DevicesJSON(checkOnline bool) (string, error)
- func DiagnosticsEnabled() bool
- func DiagnosticsExport(appInfoJSON, format, outDir string) (string, error)
- func DiagnosticsLog(source, message string)
- func DiagnosticsReport(appInfoJSON, format string) (string, error)
- func DiagnosticsSize() int64
- func DisconnectAll()
- func DisconnectHostSession(id int) error
- func DropSessionsForTest()
- func EnsureGateway() (string, error)
- func Forget(ref string) (int, error)
- func ForgetSavedPassword(target string) error
- func FreeOSMemory()
- func GatewayRunning() bool
- func GetSetting(key string) (string, error)
- func HoldHostRequest(n int) error
- func HostHintsOn() bool
- func HostReadmitMinutes() int
- func HostRequestLeftMillis(n int) int64
- func HostRunning() bool
- func HostScreenCodec() string
- func HostSharingEnded() error
- func HostStateJSON() (string, error)
- func Identity() (string, error)
- func Init(configDir, tempDir string) error
- func KeepAcrossShares() bool
- func MemoryStatsJSON() string
- func PairWithPassword(target, password, alias string) (string, error)
- func PauseGateway()
- func PendingConnections() int
- func PublicKeyLine() (string, error)
- func PushAudioPacket(data []byte, captureMicros int64) error
- func PushScreenFrame(data []byte, captureMicros int64) error
- func Redact(s string) string
- func RegenerateHostPassword() error
- func ReloadHostPassword() error
- func SavedPassword(target string) (string, error)
- func SessionsJSON() (string, error)
- func SetAlias(target, alias string) error
- func SetAppVersion(v string)
- func SetAudioSource(a AudioSource)
- func SetDeviceName(name string)
- func SetDiagnosticsEnabled(on bool) error
- func SetHintListener(l HintListener)
- func SetHostFixedPassword(password string) error
- func SetHostHints(on bool) error
- func SetHostListener(l HostListener)
- func SetHostMicrophone(on bool)
- func SetHostReadmit(minutes int) error
- func SetHostScreenSharing(on bool)
- func SetHostSessionControl(id int, control bool) error
- func SetInputInjector(i InputInjector)
- func SetKeepAcrossShares(on bool) error
- func SetLocalAddresses(list string)
- func SetMaxProcs(n int) int
- func SetMemoryLimit(limitBytes int64, gcPercent int)
- func SetScreenCodecs(list string)
- func SetScreenInfo(width, height, rotation int)
- func SetScreenOptions(encoder string, maxFPS int)
- func SetScreenSource(s ScreenSource)
- func SetSetting(key, value string) error
- func SetSettingJSON(key, value string) (string, error)
- func SettingsJSON() (string, error)
- func StartGateway() (string, error)
- func StartHost() error
- func StopGateway()
- func StopHost()
- func StopHostWithReason(reason string)
- type AudioSource
- type HintListener
- type HostListener
- type InputInjector
- type ScreenSource
Constants ¶
const HostAnswerHold = 30 * time.Second
HostAnswerHold is how long a request still waits, at least, once its owner has started to allow it (HoldHostRequest): long enough for the system's own screen recording prompt that follows Allow on Android.
const HostAskTimeout = 60 * time.Second
HostAskTimeout is how long a connection request waits for the owner.
const ReadmitAlways = -1
ReadmitAlways, as SetHostReadmit's minutes, lets an allowed device come back for as long as host mode runs (unattended).
const ReadmitWindow = 10 * time.Minute
ReadmitWindow is how long after its session ended a device the owner allowed may log in again without being asked, unless the owner chose another time (SetHostReadmit).
const WeakPasswordPrefix = "weak_password"
WeakPasswordPrefix starts SetHostFixedPassword's refusal of a password that breaks the rule, so the apps can tell it apart (and say the rule in their own words) without matching English text.
Variables ¶
This section is empty.
Functions ¶
func BreakGatewayListenerForTest ¶
func BreakGatewayListenerForTest(stall bool)
BreakGatewayListenerForTest breaks the running gateway's listener the way iOS does to a suspended app's socket, for tests of EnsureGateway: the socket goes away underneath the server. With stall the server cannot tell (GatewayRunning stays true, connections are refused: iOS's case); without, it notices. It is harmless in production (the next EnsureGateway repairs it) but nothing but tests should call it.
func CheckRendezvous ¶
CheckRendezvous connects to a rendezvous server the way a connection by ID does, and reports what answered, for the Settings screen to show when the user saves the server. addr is HOST[:PORT]; empty checks the configured server. The configured key pin is used when addr is the configured server (a new address has no pin yet: SetSetting drops the old one when the address changes).
The outcome is a JSON object either way:
{"ok":true,"code":"ok","server":"HOST:PORT","key":"<server key>"}
{"ok":false,"code":"...","error":"..."}
where key is the server's public key in the form the "signal-pin" setting takes, and code is one of
ok a RemoHop rendezvous server answered
no_rendezvous addr is empty and none is configured
bad_address addr is not HOST or HOST:PORT
unreachable no answer (wrong address or port, UDP blocked, down)
signal_is_host the address is a RemoHop host, not a rendezvous
server (connect to it by address instead)
signal_wrong_protocol something else answered
key_mismatch the server's key is not the pinned one
error anything else
The returned error is reserved for calling it before Init.
func CheckSessions ¶
func CheckSessions()
CheckSessions pings every host session and re-establishes the ones that do not answer, at once. The apps call it when the network changes (and EnsureGateway does on every return to the foreground).
func ClearDiagnostics ¶
func ClearDiagnostics() error
ClearDiagnostics deletes the recorded log (recording goes on if it is on).
func CoreVersion ¶
func CoreVersion() string
CoreVersion describes the Go core: the version stamped at build time (-ldflags "-X github.com/readori/RemoHop/internal/cli.Version=...", see mobile/android/build.sh and mobile/ios/build-xcframework.sh), or else its module version or revision, and the Go release it was built with.
func DecideHostRequest ¶
DecideHostRequest answers request n. For a login, control says whether the device may also control the phone (otherwise it only views). For an access request of a connected session, allow grants what it asked for. The phone offers no file transfer or clipboard: there is no files choice.
func DefaultDeviceName ¶
func DefaultDeviceName() string
DefaultDeviceName is the name this device gives itself when the user has not chosen one: the one SetDeviceName set, or else what this system is.
func DevicesJSON ¶
DevicesJSON lists the saved hosts as a JSON array of objects with target, alias, login ("pairing", "key", "saved_password" (a password the user asked to remember, for a host that does not pair) or "password"), presence ("online", "offline", "unknown", "not_checked", "error", ...), error, last_seen and host_identity. With checkOnline it asks the configured rendezvous server which of them are online (bounded to 10 seconds); without one configured the presence is "error" with the reason.
func DiagnosticsEnabled ¶
func DiagnosticsEnabled() bool
DiagnosticsEnabled reports whether the diagnostic log is recording.
func DiagnosticsExport ¶
DiagnosticsExport writes the report (see DiagnosticsReport) to a new file in outDir (the app's cache directory, from which it shares the file) and returns the file's path. Older reports in outDir are removed first.
func DiagnosticsLog ¶
func DiagnosticsLog(source, message string)
DiagnosticsLog records an event of the app itself (source is a short word such as "ios", "android" or "web"), when the log is on. The message is redacted like everything else.
func DiagnosticsReport ¶
DiagnosticsReport returns the report as text ("txt") or JSON ("json"): a header (app and core versions, OS and device, language, connection settings without secrets) and the recorded log lines.
func DiagnosticsSize ¶
func DiagnosticsSize() int64
DiagnosticsSize returns the size of the recorded log in bytes.
func DisconnectAll ¶
func DisconnectAll()
DisconnectAll ends every host session, as Disconnect in the page does (the Android notification's Disconnect).
func DisconnectHostSession ¶
DisconnectHostSession ends connected session id; 0 ends them all.
func DropSessionsForTest ¶
func DropSessionsForTest()
DropSessionsForTest closes every host session's connection as a network outage would; the sessions reconnect by themselves. Tests only.
func EnsureGateway ¶
EnsureGateway is what the apps call whenever they come to the foreground, and when the page reports that it cannot reach the gateway. It returns the URL of a gateway that has just answered a request from inside this process:
- nothing runs: it starts one (new port and token), like StartGateway;
- the listener answers: the same URL;
- the listener is paused (PauseGateway) or dead: iOS takes a suspended app's listening socket away, and Go's accept loop does not notice (see internal/web/listener.go). It listens again, on the same port if it can, which keeps the URL, the token, the page and every host session. If the port is gone it moves to a new port with a new token (the sessions stay in the gateway, but the page must load the new URL and starts a new browser session);
- that fails too: it stops the gateway and starts a new one.
It also checks the host sessions in the background (CheckSessions): one whose connection died while the app was away is re-established now.
The caller compares the URL with the one its web view has and loads it only if it changed.
func Forget ¶
Forget discards what is saved for a host (pinned key, pairing token, alias), named by target or alias, and returns how many entries went. Its open sessions end too.
func ForgetSavedPassword ¶
ForgetSavedPassword deletes the password saved for target, keeping the rest of what is saved for it.
func FreeOSMemory ¶
func FreeOSMemory()
FreeOSMemory runs a garbage collection and returns as much memory to the system as possible (on the system's memory warning).
func GatewayRunning ¶
func GatewayRunning() bool
GatewayRunning reports whether the gateway runs and its listener is open and has not failed as far as the server can tell. It does no I/O, so it cannot see a listener that iOS took away while the app was suspended; EnsureGateway checks for real.
func GetSetting ¶
GetSetting returns one of the settings the app manages: "signal" (the rendezvous server, HOST[:PORT]), "signal-pin" (its public key), "relay" (on/off), "outcomes" (on/off: connection outcome reports to the server, see internal/dial) and "name" (this device's name shown to peers). Unset values are returned as "".
func HoldHostRequest ¶
HoldHostRequest tells the core that the owner has started to allow request n and needs a moment (Android asks them to allow screen recording in a prompt of its own after Allow): the request then waits at least HostAnswerHold more, within the host's limit, and its deadline in the state moves. An error says it no longer waits.
func HostHintsOn ¶
func HostHintsOn() bool
HostHintsOn reports whether viewers' hints are accepted (default: yes).
func HostReadmitMinutes ¶
func HostReadmitMinutes() int
HostReadmitMinutes is the readmission time SetHostReadmit set: minutes, or ReadmitAlways.
func HostRequestLeftMillis ¶
HostRequestLeftMillis is how long request n still waits for the owner's answer, in milliseconds; 0 when it no longer waits (answered, refused at its deadline, or its device gave up). The apps ask before they start what follows an Allow, such as the screen recording prompt, so that nothing starts for a request that has expired.
func HostScreenCodec ¶
func HostScreenCodec() string
HostScreenCodec is the codec the native encoder is to produce, "h264" until the hub chooses otherwise (all viewers decode HEVC).
func HostSharingEnded ¶
func HostSharingEnded() error
HostSharingEnded tells the core that the system ended the screen sharing by itself, not through the owner's Stop (Android: the MediaProjection stopped from the status bar's screen sharing chip, because the phone locked, or because another app started sharing the screen). Every session ends: its picture is gone. The screen counts as not shared from now on (SetHostScreenSharing(false)).
With unattended readmission (ReadmitAlways) the devices the owner allowed stay remembered: while the screen is not shared their next login asks the owner (marked returning, with Allow on the notification), and once the owner allows the sharing again they come back without asking, as before. With a time limit they are forgotten, as by DisconnectHostSession(0). Either way nobody gets a session until someone at the phone allows the screen to be shared again.
func HostStateJSON ¶
HostStateJSON returns host mode's state as one JSON object:
on, phase (off, starting, ready, no_server, error), error,
id (formatted "123 456 789"), password (the password in force:
the temporary one, or the owner's own), password_mode ("temporary"
or "fixed": SetHostFixedPassword, also while host mode is off),
online (registered with the server right now), server, addresses
(ip:port this device is reachable at on its networks: shown when
there is no server or the host is offline), waited (seconds since
start while starting), device (this device's name), viewers (open
screen streams), control_available and control_unavailable (whether
the input injector works, and why not), control_offered (an
injector is set: offer control at all), readmit_minutes
(SetHostReadmit, also while host mode is off), ask_timeout (seconds),
requests [{n, name, device, identity, from, auth, left, deadline
(Unix ms), first_seen, access, session, returning, control}],
sessions [{id, label, device, identity, from, path, seconds, since
(Unix ms), control}], allowed [{identity, label, control,
connected}] (the devices that may come back without asking) and
unattended (readmit_minutes is ReadmitAlways and allowed is not
empty), codec ("h264" or "hevc": what the encoder is to produce)
and hints (viewers may send hints: SetHostHints).
func Identity ¶
Identity returns this device's identity fingerprint, creating the identity key on first use.
func Init ¶
Init points the core at the app's private configuration directory and, optionally, a directory for temporary files (the app's cache directory; Android and iOS have no writable /tmp). It must be called before anything else and may be called again with the same directory, for example when an Activity is recreated.
The directory is created with mode 0700 if needed. RemoHop's settings and rendezvous lookup read the configuration directory from REMOHOP_CONFIG_DIR, so Init sets that variable for this process.
func KeepAcrossShares ¶
func KeepAcrossShares() bool
KeepAcrossShares reports whether the carry is kept (default on).
func MemoryStatsJSON ¶
func MemoryStatsJSON() string
MemoryStatsJSON reports the Go runtime's memory as JSON, in bytes: "total" (everything the runtime mapped, minus what it released to the system), "heap" (heap objects), "gcs", "goroutines" and "limit" (the soft limit, 0 for none). It does not stop the world.
func PairWithPassword ¶
PairWithPassword logs in to target (a 9-digit ID, a saved alias or host:port) with the host's password, asks the host for a pairing token and saves it, under alias if one is given, so later connections from the app need no password. It may wait minutes for the host's owner to approve the login; CancelPair stops it.
gomobile hands errors to Java and Swift as text only, so the outcome is a JSON object either way: {"ok":true,"target","alias","host_identity", "new_host"} or {"ok":false,"code","error"}. The apps show the code in their own words and keep the error text for the diagnostic log only (it is the core's English, and may name CLI commands).
A request turned down before anything was tried has code bad_request and a "reason": target_required, password_required (a field is empty), bad_target (not an ID, a saved name or HOST:PORT), bad_alias or already_pairing. Otherwise code is one of
bad_password, unknown_id, host_offline, host_unreachable (no answer from the host, by ID or at the address), cannot_resolve (the address's name does not resolve), no_path, no_rendezvous, rendezvous_unreachable, rendezvous_rate_limited, signal_is_host (the rendezvous setting names a RemoHop host), signal_wrong_protocol (it names something else), host_key_changed, denied, locked_out, host_busy, pairing_rejected, key_rejected, password_login_disabled, timeout, canceled or error.
The returned error is reserved for calling it before Init.
The password is used for this one login and not kept.
func PauseGateway ¶
func PauseGateway()
PauseGateway closes the gateway's listening socket and keeps everything else (the server, its token, the browser and host sessions). The iOS app calls it when it goes to the background, as Apple's TN2277 asks of listening sockets: then the system has nothing to take away from the suspended app, the port is released cleanly, and EnsureGateway opens it again on return with the same URL. Safe to call when nothing runs.
func PendingConnections ¶
func PendingConnections() int
PendingConnections counts connection attempts in the page that have not finished: dialing, or waiting for the host's owner to approve. The apps keep the process alive for them as for an open session (the user often switches to a chat to say "please press Allow" exactly then).
func PublicKeyLine ¶
PublicKeyLine returns this device's public key as the one-line form `remohop authorize` takes on a host, so the device can log in by key with no password at all.
func PushAudioPacket ¶
PushAudioPacket hands the core one Opus packet from the native encoder. captureMicros is when it was captured, in Unix microseconds (0 if unknown). The bytes are copied.
func PushScreenFrame ¶
PushScreenFrame hands the core one buffer of the native encoder's output: H.264 in Annex B form, the parameter sets alone (codec config) or an access unit (with or without the parameter sets in front). captureMicros is when the picture was captured, in Unix microseconds (0 if unknown). The bytes are copied.
func RegenerateHostPassword ¶
func RegenerateHostPassword() error
RegenerateHostPassword replaces the temporary password.
func ReloadHostPassword ¶
func ReloadHostPassword() error
ReloadHostPassword gives the running host the owner's own password as saved in the configuration directory now, if it changed there since the host started or last got one; nothing when host mode is off (StartHost reads it anyway). It is for a host in another process than the one that calls SetHostFixedPassword, sharing its configuration directory (iOS: the app sets the password, its broadcast extension runs the host). Cheap when nothing changed: one small file read.
func SavedPassword ¶
SavedPassword returns the password saved for target (the page saves one when the user asks it to remember a host that does not pair), for the app's Saved hosts screen to show. With none saved it is an error.
func SessionsJSON ¶
SessionsJSON lists the gateway's host sessions as a JSON array of {"key","target","state",...} (state: connected, reconnecting, waiting_approval, failed), "[]" when there are none. The Android app polls it to keep its foreground service and notification while a session exists.
func SetAlias ¶
SetAlias names a saved host, paired or recent; an empty alias removes the name. The alias is trimmed; dial.CheckAlias says what it may be (letters of any script, digits, single spaces, '.', '_', '-').
func SetAppVersion ¶
func SetAppVersion(v string)
SetAppVersion sets the version the page shows ("RemoHop <version>").
func SetAudioSource ¶
func SetAudioSource(a AudioSource)
SetAudioSource sets (nil clears) the native microphone capture.
func SetDeviceName ¶
func SetDeviceName(name string)
SetDeviceName sets the name this device gives itself when the user has not chosen one (the "name" setting, which wins): the label it pairs with (shown in `remohop host paired` on the host) and the device name a host's approval prompt shows when it logs in. The apps pass the phone's model: on Android its device name or model, on iOS its model identifier ("iPhone15,2"), which is shown as the model's name ("iPhone 14 Pro"). Without one it is "iPhone" or "Android phone". It is not persisted.
func SetDiagnosticsEnabled ¶
SetDiagnosticsEnabled turns the diagnostic log on or off; the choice is kept across launches. Turning it off deletes what was recorded.
func SetHintListener ¶
func SetHintListener(l HintListener)
SetHintListener sets (nil clears) the receiver of viewers' hints.
func SetHostFixedPassword ¶
SetHostFixedPassword sets the owner's own password for host mode, kept across starts, instead of a new temporary one at every start; "" goes back to temporary passwords. Every login still waits for the owner's answer. The rule is hostd.CheckOwnPassword (8 characters, two of letters, digits and others); a refusal's message says what is missing. It applies at once when host mode is on.
func SetHostHints ¶
SetHostHints turns on or off accepting hints from viewers. Reported as HostStateJSON's "hints".
func SetHostListener ¶
func SetHostListener(l HostListener)
SetHostListener sets (or with nil clears) the receiver of host events.
func SetHostMicrophone ¶
func SetHostMicrophone(on bool)
SetHostMicrophone tells the core whether the owner lets the microphone be shared (default: on). Off ends live audio streams with an error and refuses new ones; the audio service is offered only while it is on.
func SetHostReadmit ¶
SetHostReadmit sets how long a device the owner allowed may log in again without being asked after its session ended (its app went to the background, its network dropped): minutes, or ReadmitAlways for as long as host mode runs (unattended); 0 goes back to ReadmitWindow. It is kept across starts and applies at once, also to devices that are away now. Either way it ends for a device when the owner disconnects it and for all when host mode stops; a new device is always asked, and every device still needs the key it was allowed with and the password. The devices it lets in are listed in HostStateJSON's "allowed".
func SetHostScreenSharing ¶
func SetHostScreenSharing(on bool)
SetHostScreenSharing tells the core whether the owner's screen sharing runs right now (Android: whether the app holds a MediaProjection the owner allowed). While it does not, a device the owner allowed earlier in this sharing is not let in again silently: it would get a session with no picture and nobody at the phone asked to share the screen again. Instead the owner is asked as for any request (the request's "returning" says why), and allowing it starts the sharing again. An app that never calls this (iOS, whose host runs only while the screen is broadcast) keeps silent readmission as it was.
With unattended readmission (ReadmitAlways) the Android app keeps the sharing running, paused, while nobody is connected, so it stays on and an allowed device comes back without anyone at the phone; when the system ends the sharing anyway, the app calls HostSharingEnded.
func SetHostSessionControl ¶
SetHostSessionControl gives connected session id control of the phone, or takes it away (it keeps viewing).
func SetInputInjector ¶
func SetInputInjector(i InputInjector)
SetInputInjector sets (nil clears) the native input injector.
func SetKeepAcrossShares ¶
SetKeepAcrossShares chooses whether the temporary password and the devices the owner allowed carry over to the next sharing (default on). Off deletes what was carried.
func SetLocalAddresses ¶
func SetLocalAddresses(list string)
SetLocalAddresses tells the core this device's own IP addresses, as a list separated by commas or spaces. Android 11 and later refuse apps the netlink requests Go's interface enumeration uses, so without this a phone advertises no LAN candidates and two devices on the same Wi-Fi cannot find the direct path between them. The Android app calls it with the active network's link addresses whenever the network changes. Loopback, link-local and unparsable entries are ignored.
func SetMaxProcs ¶
SetMaxProcs sets GOMAXPROCS when n > 0 and returns the previous value.
func SetMemoryLimit ¶
SetMemoryLimit sets the Go runtime's soft memory limit in bytes (0 or less leaves it unchanged; math.MaxInt64 removes it) and, if gcPercent is not 0, the GC target percentage (GOGC; negative turns the proportional GC off, leaving only the limit).
func SetScreenCodecs ¶
func SetScreenCodecs(list string)
SetScreenCodecs lists the codecs the native encoder offers, comma separated, with the desktop protocol's names ("h264", "hevc"). Unknown names are ignored; an empty result means "h264". It applies from the next StartHost.
func SetScreenInfo ¶
func SetScreenInfo(width, height, rotation int)
SetScreenInfo reports the screen's size in pixels and rotation in degrees (0, 90, 180, 270) whenever it changes.
func SetScreenOptions ¶
SetScreenOptions names the native video encoder, as viewers see it (e.g. "mediacodec" on Android, the default, or "videotoolbox" on iOS), and caps the frame rate the core asks of it and plans bitrates for (1..60; 0 keeps 60). It applies from the next StartHost.
func SetScreenSource ¶
func SetScreenSource(s ScreenSource)
SetScreenSource sets (nil clears) the native screen capture.
func SetSetting ¶
SetSetting validates and stores one of the settings GetSetting reads; an empty value removes it. There is no default rendezvous server: until the user sets "signal", hosts can only be reached by address (host:port).
func SetSettingJSON ¶
SetSettingJSON is SetSetting with an outcome the apps can show in their own language: {"ok":true} or {"ok":false,"code","error"}, where code is
bad_address "signal" is not HOST or HOST:PORT bad_key "signal-pin" is not a server public key bad_name "name" is too long or has control characters bad_value "relay" or "outcomes" is not on or off error anything else (the text says what)
The returned error is reserved for calling it before Init.
func SettingsJSON ¶
SettingsJSON returns the managed settings and this device's identity as one JSON object: {"signal","signal-pin","relay","outcomes","name","fingerprint"}.
func StartGateway ¶
StartGateway starts the in-process web gateway on 127.0.0.1 with a random port and a fresh token and returns the URL to load, which contains the token. If the gateway is already running it returns its URL: the token changes per start, not per call. A listener that is paused or known to have failed is opened again first; EnsureGateway also checks one that looks fine.
func StartHost ¶
func StartHost() error
StartHost starts host mode. It is safe to call while it runs.
func StopGateway ¶
func StopGateway()
StopGateway stops the gateway and ends every host session it holds. It is safe to call when nothing runs.
func StopHost ¶
func StopHost()
StopHost stops host mode and ends every session. Safe when it is off.
The owner turned sharing off (the app's switch, the notification's Stop, iOS's broadcast ending), so each session is told that a person ended it (hostd.ReasonDisconnectedOnPhone), not the host's "host shutting down", which a client takes for a restart and reconnects to.
func StopHostWithReason ¶
func StopHostWithReason(reason string)
StopHostWithReason is StopHost with the owner's reason: "locked" (the phone was locked) ends the sessions with hostd.ReasonPhoneLocked; anything else, "" included, with hostd.ReasonDisconnectedOnPhone.
Types ¶
type AudioSource ¶
type AudioSource interface {
// StartAudio starts capturing and encoding: channels (1) at 48000 Hz,
// Opus frames of frameMS milliseconds. An error refuses the listener.
StartAudio(channels, frameMS int) error
// StopAudio stops capturing (nobody listens).
StopAudio()
}
AudioSource is the native microphone capture and Opus encoder. The encoded packets come back via PushAudioPacket.
type HintListener ¶
type HintListener interface {
// HostHint reports a hint from the viewer called from (its label, or its
// short identity), already cleaned and at most 120 characters.
HostHint(from, text string)
}
HintListener receives the text hints viewers send to the phone's owner. The app implements it; its methods may be called from any goroutine.
type HostListener ¶
type HostListener interface {
// HostChanged reports the whole state, as HostStateJSON returns it,
// whenever something in it changed (at most a few times a second; once
// a second while a request waits, for its countdown).
HostChanged(state string)
// HostRequest reports a request that has just started waiting for the
// owner: one entry of the state's "requests".
HostRequest(request string)
}
HostListener receives host-mode events. The app implements it; its methods are called from the core's goroutines and must return quickly.
type InputInjector ¶
type InputInjector interface {
// e.g. that the accessibility service is off.
Unavailable() string
// Move moves the pointer (a finger already down drags).
Move(x, y float64) error
// Button presses or releases a mouse button (DOM numbering: 0 left,
// 1 middle, 2 right, 3 back, 4 forward) at x, y.
Button(button int, down bool, x, y float64) error
// Wheel scrolls by dx, dy notches (positive: right, down) where the
// pointer is.
Wheel(dx, dy float64) error
// Key presses or releases a key named by its DOM KeyboardEvent.code.
Key(code string, down bool) error
// TypeText enters text into the focused field.
TypeText(text string) error
// ReleaseAll lets go of everything held.
ReleaseAll()
}
InputInjector delivers a controller's input on the device (Android: the accessibility service). Coordinates are fractions of the shared picture, 0..1 from its top-left corner, whatever its size or rotation: mapping them onto the display is the injector's job.
type ScreenSource ¶
type ScreenSource interface {
// StartScreen starts capturing and encoding (or applies new limits):
// long edge at most maxSize pixels, at most fps frames per second,
// bitrate bits per second. The output comes back via PushScreenFrame.
// An error says why the screen cannot be captured right now.
StartScreen(maxSize, fps int, bitrate int64) error
// StopScreen stops capturing (nobody watches).
StopScreen()
// RequestKeyframe asks for an IDR frame soon.
RequestKeyframe()
// SetBitrate changes the target bitrate of the running encoder.
SetBitrate(bitrate int64)
}
ScreenSource is the native screen capture and encoder. See internal/svc/desktop.ScreenSource, which it is.