Add stream redirect handler

This commit is contained in:
Alexey Khit
2023-09-01 10:18:50 +03:00
parent 69da64a49c
commit 7d65c60711
4 changed files with 70 additions and 38 deletions
+7 -4
View File
@@ -37,12 +37,15 @@ func Init() {
api.HandleFunc("/streams", apiOK)
api.HandleFunc("/stream/", apiStream)
streams.HandleFunc("hass", func(url string) (core.Producer, error) {
// check entity by name
if url2 := entities[url[5:]]; url2 != "" {
return streams.GetProducer(url2)
streams.RedirectFunc("hass", func(url string) (string, error) {
if location := entities[url[5:]]; location != "" {
return location, nil
}
return "", nil
})
streams.HandleFunc("hass", func(url string) (core.Producer, error) {
// support hass://supervisor?entity_id=camera.driveway_doorbell
client, err := hass.NewClient(url)
if err != nil {