Code refactoring for RtspToWeb format support #1632
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
urlParser "net/url"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -64,8 +63,8 @@ func syncHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// 2. application/sdp - receive/response SDP via WebRTC-HTTP Egress Protocol (WHEP)
|
// 2. application/sdp - receive/response SDP via WebRTC-HTTP Egress Protocol (WHEP)
|
||||||
// 3. other - receive/response raw SDP
|
// 3. other - receive/response raw SDP
|
||||||
func outputWebRTC(w http.ResponseWriter, r *http.Request) {
|
func outputWebRTC(w http.ResponseWriter, r *http.Request) {
|
||||||
url := r.URL.Query().Get("src")
|
u := r.URL.Query().Get("src")
|
||||||
stream := streams.Get(url)
|
stream := streams.Get(u)
|
||||||
if stream == nil {
|
if stream == nil {
|
||||||
http.Error(w, api.StreamNotFound, http.StatusNotFound)
|
http.Error(w, api.StreamNotFound, http.StatusNotFound)
|
||||||
return
|
return
|
||||||
@@ -90,26 +89,19 @@ func outputWebRTC(w http.ResponseWriter, r *http.Request) {
|
|||||||
offer = desc.SDP
|
offer = desc.SDP
|
||||||
|
|
||||||
case "application/x-www-form-urlencoded":
|
case "application/x-www-form-urlencoded":
|
||||||
body, err := io.ReadAll(r.Body)
|
if err := r.ParseForm(); err != nil {
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Caller().Send()
|
log.Error().Err(err).Caller().Send()
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
values, err := urlParser.ParseQuery(string(body))
|
offerB64 := r.Form.Get("data")
|
||||||
|
b, err := base64.StdEncoding.DecodeString(offerB64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Caller().Send()
|
log.Error().Err(err).Caller().Send()
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
encodedOffer := values.Get("data")
|
offer = string(b)
|
||||||
decodedOffer, err := base64.StdEncoding.DecodeString(encodedOffer)
|
|
||||||
if err != nil {
|
|
||||||
log.Error().Err(err).Caller().Send()
|
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
offer = string(decodedOffer)
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
body, err := io.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
@@ -150,8 +142,8 @@ func outputWebRTC(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
case "application/x-www-form-urlencoded":
|
case "application/x-www-form-urlencoded":
|
||||||
w.Header().Set("Content-Type", mediaType)
|
w.Header().Set("Content-Type", mediaType)
|
||||||
encodedAnswer := base64.StdEncoding.EncodeToString([]byte(answer))
|
answerB64 := base64.StdEncoding.EncodeToString([]byte(answer))
|
||||||
_, err = w.Write([]byte(encodedAnswer))
|
_, err = w.Write([]byte(answerB64))
|
||||||
|
|
||||||
case MimeSDP:
|
case MimeSDP:
|
||||||
w.Header().Set("Content-Type", mediaType)
|
w.Header().Set("Content-Type", mediaType)
|
||||||
|
|||||||
Reference in New Issue
Block a user