Documentation
¶
Overview ¶
Package remote relays intent from a signed-in phone to the desktop tab that holds control: play, pause or seek its open video, open another video, or open the chat and send it a message. The desktop tab carries each command out through its own controls, with its own controller authority, so this package adds no motion path and never talks to the engine or a transport. It only queues commands, records what the desktop reports about itself, and tells remotes.
Index ¶
- Constants
- Variables
- type ChatPresence
- type Command
- type Hub
- func (h *Hub) Cancel(id, reason string)
- func (h *Hub) Claim(executor Identity, id string) (Command, time.Duration, error)
- func (h *Hub) Clear(reason string)
- func (h *Hub) CommandSender(executor Identity, id string) (Identity, bool)
- func (h *Hub) Commands(executor Identity, after uint64) ([]Command, <-chan struct{})
- func (h *Hub) Report(executor Identity, presence Presence) State
- func (h *Hub) Send(sender Identity, command Command) (Command, error)
- func (h *Hub) State(viewer Identity) (State, <-chan struct{})
- func (h *Hub) Withdraw(executor Identity, reason string)
- type Identity
- type Outcome
- type Presence
- type State
- type VideoPresence
Constants ¶
const ( // PresenceTTL is how long a desktop counts as present after its last report. PresenceTTL = 20 * time.Second // CommandTTL bounds how long a command may wait. An older command is // dropped rather than carried out late. CommandTTL = 10 * time.Second // MaxChatRunes matches the chat composer's limit. MaxChatRunes = 1000 )
Variables ¶
var ( // ErrNoDesktop reports that no desktop tab is showing a video or chat. ErrNoDesktop = errors.New("no desktop is showing a video or a chat") // ErrOtherAccount reports that the desktop is signed in to another account. ErrOtherAccount = errors.New("the desktop is signed in to another account") // ErrInvalidCommand reports a malformed command. ErrInvalidCommand = errors.New("invalid remote command") ErrTargetUnavailable = errors.New("the desktop is not showing that") // ErrBusy reports a full queue. ErrBusy = errors.New("too many remote commands are waiting; try again") )
ErrCommandUnavailable covers expired, canceled, already claimed and stale-target commands.
Functions ¶
This section is empty.
Types ¶
type ChatPresence ¶
type ChatPresence struct {
SessionID string `json:"session_id"`
PersonaName string `json:"persona_name,omitempty"`
LatestSeq int64 `json:"latest_seq,omitempty"`
Revision int64 `json:"revision,omitempty"`
Busy bool `json:"busy"`
Ready bool `json:"ready"`
}
ChatPresence describes the desktop's open conversation.
type Command ¶
type Command struct {
ID string `json:"id"`
Sequence uint64 `json:"sequence"`
Target string `json:"target"`
Action string `json:"action"`
VideoID string `json:"video_id,omitempty"`
SessionID string `json:"session_id,omitempty"`
StopSequence uint64 `json:"stop_sequence"`
Millis *int64 `json:"ms,omitempty"`
Value *float64 `json:"value,omitempty"`
Flag *bool `json:"flag,omitempty"`
Text string `json:"text,omitempty"`
// Source is the video's motion source for the "source" action.
Source string `json:"source,omitempty"`
IssuedAt time.Time `json:"issued_at"`
// contains filtered or unexported fields
}
Command is one request from a remote. Fields beyond Target and Action depend on the action; Validate states which ones are required.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub holds one desktop's presence and its queue. It starts no goroutines: expiry is applied whenever the hub is read or written, and waiters use the change channel.
func (*Hub) Claim ¶
Claim admits one execution, including after SSE redelivery or a page reload. Delivery alone is never permission to execute a buffered browser event.
func (*Hub) Clear ¶
Clear drops every waiting command. Emergency Stop calls it: a command requested before a Stop must not run after it.
func (*Hub) CommandSender ¶
CommandSender permits the HTTP edge to revalidate the originating login outside the hub lock. Claim rechecks the queue afterwards; Stop never waits for a database operation holding this lock.
func (*Hub) Commands ¶
Commands returns the queued commands after a sequence for the current executor, and a channel that closes on the next change.
func (*Hub) Report ¶
Report records the executing tab's presence and the outcomes it reports. A different tab replaces the executor; commands queued for the old one are dropped, because they were meant for the screen it was showing.
type Identity ¶
type Identity struct {
ClientID string
AccountID string
// Private, non-bearer session identity, never exposed in remote payloads.
SessionKey string `json:"-"`
DesktopAccountID string `json:"-"`
GrantID string `json:"-"`
}
Identity names one browser tab and the account it is signed in with. The account is empty on an unprotected local install, where every tab is local.
func (Identity) DesktopAccount ¶
DesktopAccount is the backend-authorized desktop audience. HTTP constructs it from a live grant; this value is never accepted from a command payload.
type Outcome ¶
type Outcome struct {
CommandID string `json:"command_id"`
OK bool `json:"ok"`
Error string `json:"error,omitempty"`
At time.Time `json:"at"`
}
Outcome reports what happened to a command.
type Presence ¶
type Presence struct {
Route string `json:"route"`
Video *VideoPresence `json:"video,omitempty"`
Chat *ChatPresence `json:"chat,omitempty"`
Outcomes []Outcome `json:"outcomes,omitempty"`
}
Presence is what the desktop tab reports about itself.
type State ¶
type State struct {
StopSequence uint64 `json:"stop_sequence"`
CanControl bool `json:"can_control"`
Revision uint64 `json:"revision"`
Connected bool `json:"connected"`
// OtherAccount is set, and every detail withheld, when the desktop is
// signed in to an account other than the viewer's.
OtherAccount bool `json:"other_account,omitempty"`
Route string `json:"route,omitempty"`
Video *VideoPresence `json:"video,omitempty"`
Chat *ChatPresence `json:"chat,omitempty"`
Pending int `json:"pending"`
Recent []Outcome `json:"recent"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
State is what remotes see. It carries no account or tab identity.
type VideoPresence ¶
type VideoPresence struct {
VideoID string `json:"video_id"`
Title string `json:"title"`
Playing bool `json:"playing"`
PositionMillis int64 `json:"position_ms"`
DurationMillis int64 `json:"duration_ms"`
Volume float64 `json:"volume"`
Muted bool `json:"muted"`
Rate float64 `json:"rate"`
Synchronized bool `json:"synchronized"`
SyncState string `json:"sync_state,omitempty"`
// Ready is false while a paired script is still loading.
Ready bool `json:"ready"`
// MotionSource is what moves the device for this video: script, chat or off.
MotionSource string `json:"motion_source,omitempty"`
// HasScript reports a paired script, which the script source needs.
HasScript bool `json:"has_script"`
}
VideoPresence describes the desktop's open video.