55
66 "github.com/AlexxIT/go2rtc/internal/api"
77 "github.com/AlexxIT/go2rtc/internal/app"
8+ "github.com/AlexxIT/go2rtc/pkg/core"
89 "github.com/AlexxIT/go2rtc/pkg/probe"
910)
1011
@@ -27,7 +28,7 @@ func apiStreams(w http.ResponseWriter, r *http.Request) {
2728 return
2829 }
2930
30- cons := probe .NewProbe ( query )
31+ cons := probe .Create ( "probe" , query )
3132 if len (cons .Medias ) != 0 {
3233 cons .WithRequest (r )
3334 if err := stream .AddConsumer (cons ); err != nil {
@@ -122,3 +123,51 @@ func apiStreamsDOT(w http.ResponseWriter, r *http.Request) {
122123
123124 api .Response (w , dot , "text/vnd.graphviz" )
124125}
126+
127+ func apiPreload (w http.ResponseWriter , r * http.Request ) {
128+ query := r .URL .Query ()
129+ src := query .Get ("src" )
130+
131+ // check if stream exists
132+ stream := Get (src )
133+ if stream == nil {
134+ http .Error (w , "" , http .StatusNotFound )
135+ return
136+ }
137+
138+ switch r .Method {
139+ case "PUT" :
140+ // it's safe to delete from map while iterating
141+ for k := range query {
142+ switch k {
143+ case core .KindVideo , core .KindAudio , "microphone" :
144+ default :
145+ delete (query , k )
146+ }
147+ }
148+
149+ rawQuery := query .Encode ()
150+
151+ if err := AddPreload (stream , rawQuery ); err != nil {
152+ http .Error (w , err .Error (), http .StatusInternalServerError )
153+ return
154+ }
155+
156+ if err := app .PatchConfig ([]string {"preload" , src }, rawQuery ); err != nil {
157+ http .Error (w , err .Error (), http .StatusInternalServerError )
158+ }
159+
160+ case "DELETE" :
161+ if err := DelPreload (stream ); err != nil {
162+ http .Error (w , err .Error (), http .StatusInternalServerError )
163+ return
164+ }
165+
166+ if err := app .PatchConfig ([]string {"preload" , src }, nil ); err != nil {
167+ http .Error (w , err .Error (), http .StatusInternalServerError )
168+ }
169+
170+ default :
171+ http .Error (w , "" , http .StatusMethodNotAllowed )
172+ }
173+ }
0 commit comments