Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean HASS Urls that come from UniFi Protect #867

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion internal/hass/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import (
"encoding/json"
"net"
"net/http"
"regexp"
"strings"

"github.com/AlexxIT/go2rtc/internal/api"
"github.com/AlexxIT/go2rtc/internal/streams"
"github.com/AlexxIT/go2rtc/internal/webrtc"
)

// UniFi streams will start with rtsps and end with ?enableSrtp
// this is not compatible with go2rtc and requires some manipulation
var UnifiMatch = regexp.MustCompile(`rtsps://.+[?]enableSrtp`)

func apiOK(w http.ResponseWriter, r *http.Request) {
api.Response(w, `{"status":1,"payload":{}}`, api.MimeJSON)
}
Expand All @@ -30,7 +35,15 @@ func apiStream(w http.ResponseWriter, r *http.Request) {
// 1. link to go2rtc stream: rtsp://...:8554/{stream_name}
// 2. static link to Hass camera
// 3. dynamic link to Hass camera
if streams.Patch(v.Name, v.Channels.First.Url) != nil {

// Mutate incompatible UniFi URLs
streamURL := v.Channels.First.Url
if UnifiMatch.MatchString(streamURL) {
streamURL = strings.Replace(streamURL, "rtsps", "rtspx", 1)
streamURL = strings.Replace(streamURL, "?enableSrtp", "", 1)
log.Debug().Msgf("Cleaning UniFi stream URL: %v", streamURL)
}
if streams.Patch(v.Name, streamURL) != nil {
apiOK(w, r)
} else {
http.Error(w, "", http.StatusBadRequest)
Expand Down