🏡 index : ~doyle/hkbi.git

Diff

 characteristic/event_snapshots_active.go    | 19 +++++++++++++++++++
 characteristic/homekit_camera_active.go     | 19 +++++++++++++++++++
 characteristic/periodic_snapshots_active.go | 19 +++++++++++++++++++
 service/camera_operating_mode.go            | 32 ++++++++++++++++++++++++++++++++
 service/data_stream_management.go           |  1 +
 cmd/hkbi/main.go                            | 12 +++++++++++-
 6 files changed, 100 insertions(+), 2 deletions(-)

diff --git a/characteristic/event_snapshots_active.go b/characteristic/event_snapshots_active.go
new file mode 100644
index 0000000..7d030ea 100644
--- /dev/null
+++ a/characteristic/event_snapshots_active.go
@@ -1,0 +1,19 @@
package characteristic

import "github.com/brutella/hap/characteristic"

const TypeEventSnapshotsActive = "223"

type EventSnapshotsActive struct {
	*characteristic.Bool
}

func NewEventSnapshotsActive() *EventSnapshotsActive {
	c := characteristic.NewBool(TypeEventSnapshotsActive)
	c.Format = characteristic.FormatBool
	c.Permissions = []string{characteristic.PermissionRead, characteristic.PermissionWrite, characteristic.PermissionEvents}

	c.SetValue(false)

	return &EventSnapshotsActive{c}
}
diff --git a/characteristic/homekit_camera_active.go b/characteristic/homekit_camera_active.go
new file mode 100644
index 0000000..5e072a1 100644
--- /dev/null
+++ a/characteristic/homekit_camera_active.go
@@ -1,0 +1,19 @@
package characteristic

import "github.com/brutella/hap/characteristic"

const TypeHomeKitCameraActive = "21B"

type HomeKitCameraActive struct {
	*characteristic.Bool
}

func NewHomeKitCameraActive() *HomeKitCameraActive {
	c := characteristic.NewBool(TypeHomeKitCameraActive)
	c.Format = characteristic.FormatBool
	c.Permissions = []string{characteristic.PermissionRead, characteristic.PermissionWrite, characteristic.PermissionEvents}

	c.SetValue(false)

	return &HomeKitCameraActive{c}
}
diff --git a/characteristic/periodic_snapshots_active.go b/characteristic/periodic_snapshots_active.go
new file mode 100644
index 0000000..c758e30 100644
--- /dev/null
+++ a/characteristic/periodic_snapshots_active.go
@@ -1,0 +1,19 @@
package characteristic

import "github.com/brutella/hap/characteristic"

const TypePeriodicSnapshotsActive = "225"

type PeriodicSnapshotsActive struct {
	*characteristic.Bool
}

func NewPeriodicSnapshotsActive() *PeriodicSnapshotsActive {
	c := characteristic.NewBool(TypePeriodicSnapshotsActive)
	c.Format = characteristic.FormatBool
	c.Permissions = []string{characteristic.PermissionRead, characteristic.PermissionWrite, characteristic.PermissionEvents}

	c.SetValue(false)

	return &PeriodicSnapshotsActive{c}
}
diff --git a/service/camera_operating_mode.go b/service/camera_operating_mode.go
new file mode 100644
index 0000000..3767df4 100644
--- /dev/null
+++ a/service/camera_operating_mode.go
@@ -1,0 +1,32 @@
package service

import (
	"github.com/brutella/hap/service"
	characteristic2 "github.com/w4/hkbi/characteristic"
)

const TypeCameraOperatingMode = "21A"

type CameraOperatingMode struct {
	*service.S

	EventSnapshotsActive    *characteristic2.EventSnapshotsActive
	HomeKitCameraActive     *characteristic2.HomeKitCameraActive
	PeriodicSnapshotsActive *characteristic2.PeriodicSnapshotsActive
}

func NewCameraOperatingMode() *CameraOperatingMode {
	s := CameraOperatingMode{}
	s.S = service.New(TypeCameraOperatingMode)

	s.EventSnapshotsActive = characteristic2.NewEventSnapshotsActive()
	s.AddC(s.EventSnapshotsActive.C)

	s.HomeKitCameraActive = characteristic2.NewHomeKitCameraActive()
	s.AddC(s.HomeKitCameraActive.C)

	s.PeriodicSnapshotsActive = characteristic2.NewPeriodicSnapshotsActive()
	s.AddC(s.PeriodicSnapshotsActive.C)

	return &s
}
diff --git a/service/data_stream_management.go b/service/data_stream_management.go
new file mode 100644
index 0000000..6d43c33 100644
--- /dev/null
+++ a/service/data_stream_management.go
@@ -1,0 +1,1 @@
package service
diff --git a/cmd/hkbi/main.go b/cmd/hkbi/main.go
index abbface..0cefdbb 100644
--- a/cmd/hkbi/main.go
+++ a/cmd/hkbi/main.go
@@ -15,6 +15,7 @@
	"github.com/brutella/hap/service"
	"github.com/brutella/hap/tlv8"
	"github.com/w4/hkbi/blueiris"
	service2 "github.com/w4/hkbi/service"
	"io"
	"math/rand"
	"net"
@@ -132,10 +133,13 @@
			hasDiscoveredNewCameras = true
		}

		// setup stream request handling on management channels 1 & 2
		// setup stream request handling on channel 1
		startListeningForStreams(camera.Id, cam.StreamManagement1, globalState, &config, bi.BaseUrl)
		startListeningForStreams(camera.Id, cam.StreamManagement2, globalState, &config, bi.BaseUrl)

		// create the camera operating mode service
		cameraOperatingMode := service2.NewCameraOperatingMode()
		cam.AddS(cameraOperatingMode.S)

		// create the HomeKit motion sensor service
		motionSensor := service.NewMotionSensor()
		motionSensorActive := characteristic.NewActive()
@@ -316,6 +320,10 @@

// sets up a camera accessory for streaming
func startListeningForStreams(cameraName string, mgmt *service.CameraRTPStreamManagement, globalState *GlobalState, config *Config, blueirisBase *url.URL) {
	// add active characteristic to rtpstream
	active := characteristic.NewActive()
	mgmt.AddC(active.C)

	// set up some basic parameters for HomeKit to know that the camera is available
	setTlv8Payload(mgmt.StreamingStatus.Bytes, rtp.StreamingStatus{Status: rtp.StreamingStatusAvailable})
	setTlv8Payload(mgmt.SupportedRTPConfiguration.Bytes, rtp.NewConfiguration(rtp.CryptoSuite_AES_CM_128_HMAC_SHA1_80))