Improve HomeKit source start time
This commit is contained in:
+16
-8
@@ -7,6 +7,13 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
"github.com/AlexxIT/go2rtc/pkg/mdns"
|
||||
"github.com/brutella/hap"
|
||||
@@ -16,12 +23,6 @@ import (
|
||||
"github.com/brutella/hap/hkdf"
|
||||
"github.com/brutella/hap/tlv8"
|
||||
"github.com/tadglines/go-pkgs/crypto/srp"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Conn for HomeKit. DevicePublic can be null.
|
||||
@@ -105,9 +106,16 @@ func (c *Conn) DialAndServe() error {
|
||||
return c.Handle()
|
||||
}
|
||||
|
||||
func (c *Conn) DeviceHost() string {
|
||||
if i := strings.IndexByte(c.DeviceAddress, ':'); i > 0 {
|
||||
return c.DeviceAddress[:i]
|
||||
}
|
||||
return c.DeviceAddress
|
||||
}
|
||||
|
||||
func (c *Conn) Dial() error {
|
||||
// update device host before dial
|
||||
_ = mdns.Discovery(mdns.ServiceHAP, func(entry *mdns.ServiceEntry) bool {
|
||||
// update device address (host and/or port) before dial
|
||||
_ = mdns.QueryOrDiscovery(c.DeviceHost(), mdns.ServiceHAP, func(entry *mdns.ServiceEntry) bool {
|
||||
if entry.Complete() && entry.Info["id"] == c.DeviceID {
|
||||
c.DeviceAddress = entry.Addr()
|
||||
return true
|
||||
|
||||
@@ -106,6 +106,8 @@ func Query(host, service string) (entry *ServiceEntry, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// QueryOrDiscovery - useful if we know previous device host and want
|
||||
// to update port or any other information. Will work even over VPN.
|
||||
func QueryOrDiscovery(host, service string, onentry func(*ServiceEntry) bool) error {
|
||||
entry, _ := Query(host, service)
|
||||
if entry != nil && onentry(entry) {
|
||||
|
||||
Reference in New Issue
Block a user