remote

package
v0.1.0-alpha.73 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: GPL-3.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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 reports a command for a surface the desktop is not showing.
	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")
)
View Source
var ErrCommandUnavailable = errors.New("the remote command is no longer available")

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.

func (Command) Validate

func (c Command) Validate() error

Validate checks that a command is complete and within bounds.

type EdgeHold

type EdgeHold struct {
	Active          bool   `json:"active"`
	Phase           string `json:"phase"`
	Automatic       bool   `json:"automatic"`
	ResumeInSeconds int    `json:"resume_in_seconds,omitempty"`
	Message         string `json:"message,omitempty"`
}

EdgeHold mirrors the backend-owned Edge holding status.

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 NewHub

func NewHub(now func() time.Time) *Hub

NewHub returns an empty hub; now defaults to time.Now.

func (*Hub) Cancel

func (h *Hub) Cancel(id, reason string)

Cancel retires one command without disturbing newer requests.

func (*Hub) Claim

func (h *Hub) Claim(executor Identity, id string) (Command, time.Duration, error)

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

func (h *Hub) Clear(reason string)

Clear drops every waiting command. Emergency Stop calls it: a command requested before a Stop must not run after it.

func (*Hub) CommandSender

func (h *Hub) CommandSender(executor Identity, id string) (Identity, bool)

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

func (h *Hub) Commands(executor Identity, after uint64) ([]Command, <-chan struct{})

Commands returns the queued commands after a sequence for the current executor, and a channel that closes on the next change.

func (*Hub) ExecutorAccount

func (h *Hub) ExecutorAccount(sessionKey string) (string, bool)

ExecutorAccount names the account of the last tab that reported with this login. It outlives presence: a desktop that hides withdraws its presence but still holds control, and its phone may keep that control alive.

func (*Hub) Report

func (h *Hub) Report(executor Identity, presence Presence) State

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.

func (*Hub) Send

func (h *Hub) Send(sender Identity, command Command) (Command, error)

Send validates a command from a remote and queues it for the desktop.

func (*Hub) State

func (h *Hub) State(viewer Identity) (State, <-chan struct{})

State returns what a viewer may see and a channel that closes on the next change. A viewer on another account learns only that a desktop is present; its revision stays zero so a stream has nothing new to send it.

func (*Hub) Withdraw

func (h *Hub) Withdraw(executor Identity, reason string)

Withdraw ends a tab's presence: it closed its video and chat, or it lost control. Commands still waiting for it are dropped with the reason.

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

func (i Identity) DesktopAccount() string

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"`
	// Background is set while the desktop tab is hidden and stays awake only
	// because this account's phone remote keeps its session alive.
	Background bool           `json:"background,omitempty"`
	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 Session

type Session struct {
	Alive        bool      `json:"alive"`
	StopOnExpiry bool      `json:"stop_on_expiry,omitempty"`
	Running      bool      `json:"running,omitempty"`
	Paused       bool      `json:"paused,omitempty"`
	EdgeAllowed  bool      `json:"edge_allowed,omitempty"`
	Edge         *EdgeHold `json:"edge,omitempty"`
}

Session is the desktop's control session as its phone may see it: whether a desktop of the phone's account still holds control, and the live motion and Edge state the phone's Edge button needs. It names no account or tab.

func (*Session) Equal

func (s *Session) Equal(other *Session) bool

Equal reports whether two session views would render the same.

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"`
	Background   bool           `json:"background,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"`
	// Session is filled by the server, not the hub: it outlives the desktop's
	// presence, because a hidden desktop withdraws presence but keeps control.
	Session *Session `json:"session,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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL