Code refactoring

This commit is contained in:
Alexey Khit
2022-09-16 17:04:00 +03:00
parent 407ccc45bc
commit a45d0b507b
3 changed files with 8 additions and 7 deletions
+5 -4
View File
@@ -88,7 +88,7 @@ func streamsHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "PUT":
streams.Get(src)
streams.New(src, src)
return
case "DELETE":
streams.Delete(src)
@@ -101,13 +101,14 @@ func streamsHandler(w http.ResponseWriter, r *http.Request) {
} else {
v = streams.All()
}
data, err := json.Marshal(v)
if err != nil {
log.Error().Err(err).Msg("[api.streams] marshal")
return
}
if _, err = w.Write(data); err != nil {
log.Error().Err(err).Msg("[api.streams] write")
}
_, _ = w.Write(data)
}
func apiWS(w http.ResponseWriter, r *http.Request) {
+2 -2
View File
@@ -28,7 +28,7 @@ func handlerKeyframe(w http.ResponseWriter, r *http.Request) {
}
src := r.URL.Query().Get("src")
stream := streams.Get(src)
stream := streams.GetOrNew(src)
if stream == nil {
return
}
@@ -75,7 +75,7 @@ func handlerMP4(w http.ResponseWriter, r *http.Request) {
log.Trace().Msgf("[api.mp4] %+v", r)
src := r.URL.Query().Get("src")
stream := streams.Get(src)
stream := streams.GetOrNew(src)
if stream == nil {
return
}
+1 -1
View File
@@ -11,7 +11,7 @@ const MsgTypeMSE = "mse" // fMP4
func handlerWS(ctx *api.Context, msg *streamer.Message) {
src := ctx.Request.URL.Query().Get("src")
stream := streams.Get(src)
stream := streams.GetOrNew(src)
if stream == nil {
return
}