diff --git a/internal/homekit/homekit.go b/internal/homekit/homekit.go index edd67bc1..8ecea806 100644 --- a/internal/homekit/homekit.go +++ b/internal/homekit/homekit.go @@ -95,7 +95,7 @@ func Init() { srv.hap.Handler = homekit.ServerHandler(srv) } - entry := &mdns.ServiceEntry{ + srv.mdns = &mdns.ServiceEntry{ Name: name, Port: uint16(api.Port()), Info: map[string]string{ @@ -110,9 +110,11 @@ func Init() { hap.TXTSetupHash: srv.hap.SetupHash(), }, } - entries = append(entries, entry) + entries = append(entries, srv.mdns) - host := entry.Host(mdns.ServiceHAP) + srv.UpdateStatus() + + host := srv.mdns.Host(mdns.ServiceHAP) servers[host] = srv } diff --git a/internal/homekit/server.go b/internal/homekit/server.go index 90fc64aa..a1cc9144 100644 --- a/internal/homekit/server.go +++ b/internal/homekit/server.go @@ -19,12 +19,14 @@ import ( "github.com/AlexxIT/go2rtc/pkg/hap/tlv8" "github.com/AlexxIT/go2rtc/pkg/homekit" "github.com/AlexxIT/go2rtc/pkg/magic" + "github.com/AlexxIT/go2rtc/pkg/mdns" "github.com/AlexxIT/go2rtc/pkg/srtp" ) type server struct { stream string // stream name from YAML hap *hap.Server // server for HAP connection and encryption + mdns *mdns.ServiceEntry srtp *srtp.Server accessory *hap.Accessory // HAP accessory pairings []string // pairings list @@ -33,6 +35,15 @@ type server struct { consumer *homekit.Consumer } +func (s *server) UpdateStatus() { + // true status is important, or device may be offline in Apple Home + if len(s.pairings) == 0 { + s.mdns.Info[hap.TXTStatusFlags] = hap.StatusNotPaired + } else { + s.mdns.Info[hap.TXTStatusFlags] = hap.StatusPaired + } +} + func (s *server) GetAccessories(_ net.Conn) []*hap.Accessory { return []*hap.Accessory{s.accessory} } @@ -188,6 +199,7 @@ func (s *server) AddPair(conn net.Conn, id string, public []byte, permissions by "permissions": []string{string('0' + permissions)}, } s.pairings = append(s.pairings, query.Encode()) + s.UpdateStatus() s.PatchConfig() } @@ -201,6 +213,7 @@ func (s *server) DelPair(conn net.Conn, id string) { } s.pairings = append(s.pairings[:i], s.pairings[i+1:]...) + s.UpdateStatus() s.PatchConfig() break }