Documentation
¶
Overview ¶
Package relay carries a game stream between the Moonlight host program and a browser. The host program holds Moonlight's GPL-3.0 code and is a separate program, reached only by the messages in WittyCouchHost's PROTOCOL.md: this package contains none of it.
Index ¶
- Constants
- Variables
- func CheckProgram(ctx context.Context, program string, prepare func(*exec.Cmd)) error
- func CheckProgramWith(ctx context.Context, program string, args []string, prepare func(*exec.Cmd)) error
- func ValidInput(m []byte) bool
- type Event
- type Host
- type Options
- type Session
- func (s *Session) Audio(opus []byte)
- func (s *Session) Close()
- func (s *Session) Counts() (video, audio uint64)
- func (s *Session) Ended() <-chan struct{}
- func (s *Session) Event(e Event)
- func (s *Session) Info() Event
- func (s *Session) Input(m []byte)
- func (s *Session) Offer(ctx context.Context, offer string) (string, error)
- func (s *Session) Rumble(controller, low, high uint16)
- func (s *Session) Video(keyframe bool, ts uint32, annexB []byte)
- type Sink
- type Start
Constants ¶
const ( CmdPad = 65 CmdMouseMove = 66 CmdMouseButton = 67 CmdKey = 68 CmdScroll = 69 CmdIDR = 70 CmdMousePosition = 72 CmdText = 73 CmdHScroll = 74 )
What it reads. The numbers from CmdPad up are also what a browser sends.
const (
// ProtocolVersion is the host program this package speaks to.
ProtocolVersion = 1
)
Variables ¶
var ErrNoProgram = errors.New("the Moonlight host program isn't installed on this server")
ErrNoProgram: the program isn't installed here.
Functions ¶
func CheckProgram ¶
CheckProgram runs the program once to see that it can run here and speaks this protocol, given as little as it's given to play a game.
func CheckProgramWith ¶ added in v0.4.0
func CheckProgramWith(ctx context.Context, program string, args []string, prepare func(*exec.Cmd)) error
CheckProgramWith is CheckProgram for a program run with arguments before its own.
func ValidInput ¶
ValidInput checks a message from a browser: its type byte, then its body.
Types ¶
type Event ¶
type Event struct {
Type string `json:"type"`
Stage string `json:"stage,omitempty"`
Code int `json:"code,omitempty"`
Poor bool `json:"poor,omitempty"`
Format int `json:"format,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
FPS int `json:"fps,omitempty"`
Rate int `json:"rate,omitempty"`
Channels int `json:"channels,omitempty"`
Samples int `json:"samples,omitempty"`
Streams int `json:"streams,omitempty"`
Coupled int `json:"coupled,omitempty"`
Protocol int `json:"protocol,omitempty"`
}
Event is something the host program reports.
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host is one running host program, for one stream.
func StartHost ¶
StartHost runs the program. It holds nothing and reads nothing it's not sent: no address, key or user name ever goes on its command line, where other programs could read it.
func StartHostWith ¶ added in v0.4.0
func StartHostWith(program string, args []string, prepare func(*exec.Cmd), log *slog.Logger, sink Sink) (*Host, error)
StartHostWith is StartHost for a program that is run with arguments before its own, such as a sandbox's launcher (the server's answer to where a module's program is: path and args).
type Options ¶
type Options struct {
Program string
Args []string // run before the program's own, when the program is a launcher's (a sandbox)
Prepare func(*exec.Cmd)
Start Start
Log *slog.Logger
STUN []string
PublicIP []string
UDPPort int // one port for every stream, when set, for routers and containers
// OnEnd is told once, when the stream has ended for any reason.
OnEnd func(reason string)
}
Options set up a session.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is one stream from one PC, to one viewer at a time.
func New ¶
New starts the host program and connects it to the PC. It returns when the stream is flowing, or says why it isn't.
func (*Session) Ended ¶
func (s *Session) Ended() <-chan struct{}
Ended closes when the stream has ended.
func (*Session) Offer ¶
Offer takes a browser's WebRTC offer and answers it. A new one replaces any earlier viewer, so a reload or another device simply carries on.
type Sink ¶
type Sink interface {
Video(keyframe bool, timestamp uint32, annexB []byte)
Audio(opus []byte)
Rumble(controller, low, high uint16)
Event(e Event)
}
Sink receives what the host program produces. Calls come from one goroutine.
type Start ¶
type Start struct {
Address string // an IP, resolved and checked by the caller
AppVersion string
GfeVersion string
RTSP string
CodecModes int
Width int
Height int
FPS int
BitrateKbps int
PacketSize int
Remote bool
Key, IV [16]byte
}
Start is what a host program needs to connect. The PC has already been told to start the game, over its own client protocol, by the time this is used.