diff --git a/cmd/api/api.go b/cmd/api/api.go index c196a986..9f0be64a 100644 --- a/cmd/api/api.go +++ b/cmd/api/api.go @@ -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) { diff --git a/cmd/mp4/mp4.go b/cmd/mp4/mp4.go index 6e9d1ef4..ac751f1d 100644 --- a/cmd/mp4/mp4.go +++ b/cmd/mp4/mp4.go @@ -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 } diff --git a/cmd/mp4/mse.go b/cmd/mp4/mse.go index d632ed12..abbbc711 100644 --- a/cmd/mp4/mse.go +++ b/cmd/mp4/mse.go @@ -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 }