homekit

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: AGPL-3.0 Imports: 39 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 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

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

func New(opts Options) (*Bridge, error)

New builds the bridge. Nothing listens until Run.

func (*Bridge) Alert

func (b *Bridge) Alert(camera, kind string, on bool)

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.

func (*Bridge) Paired

func (b *Bridge) Paired() bool

Paired reports whether a Home app has paired with the bridge.

func (*Bridge) Pin

func (b *Bridge) Pin() string

Pin is the setup code, as the Home app shows it: 123-45-678.

func (*Bridge) Run

func (b *Bridge) Run(ctx context.Context) error

Run serves until ctx ends.

func (*Bridge) SetupURI

func (b *Bridge) SetupURI() string

SetupURI is what the bridge's QR code holds.

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

type Feed func(camera string, choice int) (records <-chan []byte, cancel func(), ok bool)

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

func (m *Manager) Alert(camera, kind string, on bool)

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

func (m *Manager) Apply(cfg *config.Config) error

Apply follows cfg: starts, rebuilds or stops the bridge. It returns once the old bridge has let go of its port.

func (*Manager) Reset

func (m *Manager) Reset() error

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.

func (*Manager) Status

func (m *Manager) Status() Status

Status reports the bridge as it runs now.

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the bridge, when reostream exits.

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

type TalkSession interface {
	Write(rate int, pcm []int16) error
	Close() error
}

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

type TalkSound func(camera string) (<-chan []int16, func())

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.

type Talker added in v0.2.15

type Talker func(ctx context.Context, camera string) (TalkSession, error)

Talker opens a talk session on a camera.

Jump to

Keyboard shortcuts

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