Documentation
¶
Overview ¶
Package homekit puts reostream's cameras in Apple's Home app (#32): one bridge, named reostream unless the config says otherwise, with a camera accessory per wired camera, so the Home app pairs once for all of them.
The HomeKit Accessory Protocol itself (pairing, the encrypted session, mDNS) is github.com/brutella/hap. This package decides what the bridge holds and answers the Home app's snapshot requests with the camera's own still.
Index ¶
Constants ¶
const DefaultPort = 51827
DefaultPort is the HomeKit server's port when the config sets none. A fixed one, so a firewall rule written for it keeps working.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bridge ¶
type Bridge struct {
// contains filtered or unexported fields
}
Bridge is a running HomeKit bridge.
func (*Bridge) Alert ¶
Alert feeds the camera's motion sensor from the camera's own alerts: motion while the camera reports motion or any object. Some cameras send only objects (a pano reported vehicles and never plain motion, 12-01), so motion alone would leave their sensor dark. A camera the bridge does not hold is ignored.
type Camera ¶
type Camera struct {
Name string
Model string
// Motion is a camera whose motion reaches reostream: its own alert
// connection, or a motion_topic. Only it gets a motion sensor, since
// one that can never trip says "no motion" when nobody knows.
Motion bool
// Doorbell is a camera that has reported a doorbell press: it gets a
// Doorbell service, which makes it a video doorbell in the Home app.
Doorbell bool
}
Camera is one camera the bridge offers.
type Feed ¶
Feed subscribes to a camera stream's access units in process: marshaled frames.Record values, the first a keyframe, until cancel. choice 0 is the camera's first choice for live view; a session that finds it H.265 asks for 1, and so on, until ok is false.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager runs the bridge the config asks for, and builds it again when the homekit section or the cameras it holds change, so the page's changes apply without a restart.
func NewManager ¶
func NewManager(opts ManagerOptions) *Manager
func (*Manager) Alert ¶
Alert passes a camera alert to the running bridge's motion sensors and doorbells. A camera's first doorbell press makes it a doorbell: the bridge is built again with the Doorbell service on it, and that press is not rung, since the Home app learns of the new service only when the bridge is added again.
func (*Manager) Apply ¶
Apply follows cfg: starts, rebuilds or stops the bridge. It returns once the old bridge has let go of its port.
func (*Manager) Reset ¶
Reset forgets every pairing and the bridge's identity, so the Home app sees a new accessory and can add it again. The old one stays in the Home app, not responding, until it is removed there.
type ManagerOptions ¶
type ManagerOptions struct {
Dir string
Version string
Snap func(ctx context.Context, camera, stream string) ([]byte, error)
// Subscribe reads one camera stream's access units in process, as
// Feed does for a camera; nil offers stills only.
Subscribe func(camera, stream string) (records <-chan []byte, cancel func(), ok bool)
// Talk opens a camera's speaker; nil leaves the Home app's talk
// button out.
Talk Talker
// TalkSound gives silence while a talk session is open on a camera.
TalkSound TalkSound
}
ManagerOptions are what the bridge needs beyond the config.
type Options ¶
type Options struct {
// Dir holds the pairing keys, the pairings, the setup code reostream
// made and the accessory ids: <data>/homekit.
Dir string
Name string
Port int
Pin string
Version string
Cameras []Camera
// Snap returns the camera's own still, stream "main" or "sub".
Snap func(ctx context.Context, camera, stream string) ([]byte, error)
// Feed is the camera's video for live view; nil offers stills only.
Feed Feed
// Talk opens a camera's speaker for the Home app's talk button; nil
// leaves the button out.
Talk Talker
// TalkSound gives silence while a talk session is open on a camera;
// nil plays the stream's sound throughout.
TalkSound TalkSound
}
Options are what Run needs.
type Status ¶
type Status struct {
On bool
Name string
Port int
Code string // 123-45-678
SetupURI string // what the QR code holds
Paired bool
Cameras []string
Err string
}
Status is what the page shows.
type TalkSession ¶ added in v0.2.15
TalkSession plays sound through one camera's speaker: internal/talk's Session, as the RTSP back channel opens it.
type TalkSound ¶ added in v0.2.16
TalkSound signals, a block at a time, while someone talking through a camera has spoken lately (talk.Listen), for a live view to fade the camera's sound out so the talker never hears themselves: the Home app only ever plays live, and the streams a recorder reads keep both sides.