mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-06 16:57:29 +08:00
Update RTSPtoWebRTC errors output
This commit is contained in:
@@ -3,12 +3,13 @@ package hass
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/AlexxIT/go2rtc/internal/api"
|
|
||||||
"github.com/AlexxIT/go2rtc/internal/streams"
|
|
||||||
"github.com/AlexxIT/go2rtc/internal/webrtc"
|
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/AlexxIT/go2rtc/internal/api"
|
||||||
|
"github.com/AlexxIT/go2rtc/internal/streams"
|
||||||
|
"github.com/AlexxIT/go2rtc/internal/webrtc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func apiOK(w http.ResponseWriter, r *http.Request) {
|
func apiOK(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -21,6 +22,7 @@ func apiStream(w http.ResponseWriter, r *http.Request) {
|
|||||||
case strings.HasSuffix(r.RequestURI, "/add"):
|
case strings.HasSuffix(r.RequestURI, "/add"):
|
||||||
var v addJSON
|
var v addJSON
|
||||||
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,32 +43,32 @@ func apiStream(w http.ResponseWriter, r *http.Request) {
|
|||||||
default:
|
default:
|
||||||
i := strings.IndexByte(r.RequestURI[8:], '/')
|
i := strings.IndexByte(r.RequestURI[8:], '/')
|
||||||
if i <= 0 {
|
if i <= 0 {
|
||||||
log.Warn().Msgf("wrong request: %s", r.RequestURI)
|
http.Error(w, "", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
name := r.RequestURI[8 : 8+i]
|
|
||||||
|
|
||||||
|
name := r.RequestURI[8 : 8+i]
|
||||||
stream := streams.Get(name)
|
stream := streams.Get(name)
|
||||||
if stream == nil {
|
if stream == nil {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
http.Error(w, api.StreamNotFound, http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
log.Error().Err(err).Msg("[api.hass] parse form")
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s := r.FormValue("data")
|
s := r.FormValue("data")
|
||||||
offer, err := base64.StdEncoding.DecodeString(s)
|
offer, err := base64.StdEncoding.DecodeString(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("[api.hass] sdp64 decode")
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err = webrtc.ExchangeSDP(stream, string(offer), "WebRTC/Hass sync", r.UserAgent())
|
s, err = webrtc.ExchangeSDP(stream, string(offer), "WebRTC/Hass sync", r.UserAgent())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("[api.hass] exchange SDP")
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user