Skip to content

Commit

Permalink
Adding checks for the stream being active
Browse files Browse the repository at this point in the history
  • Loading branch information
COMTOP1 committed Feb 18, 2024
1 parent d950e9a commit fd4c7c8
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions server/views/startUnique.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package views

import (
"encoding/xml"
"fmt"
"github.com/ystv/streamer/server/helper"
"log"
"math"
"net/http"
Expand Down Expand Up @@ -31,7 +33,7 @@ func (v *Views) StartUniqueFunc(c echo.Context) error {

log.Printf("%#v", c.Request().Form)

return c.JSON(http.StatusOK, `{"error": "testing"}`)
//return c.JSON(http.StatusOK, `{"error": "testing"}`)

var response struct {
Unique string `json:"unique"`
Expand Down Expand Up @@ -63,12 +65,54 @@ func (v *Views) StartUniqueFunc(c echo.Context) error {
Unique: unique,
}

inputEndpoint := c.FormValue("endpointsTable")
inputStream := c.FormValue("stream_input")

streamPageContent, err := helper.GetBody("http://" + v.conf.StreamServer + "stat")
if err != nil {
log.Printf("failed to get streams from stream server: %+v", err)
response.Error = fmt.Sprintf("failed to get streams from stream server: %+v", err)
return c.JSON(http.StatusOK, response)
}

var rtmp RTMP

err = xml.Unmarshal([]byte(streamPageContent), &rtmp)
if err != nil {
log.Printf("failed to unmarshal xml: %+v", err)
response.Error = fmt.Sprintf("failed to unmarshal xml: %+v", err)
return c.JSON(http.StatusOK, response)
}

found := false

var streamIn string
endpoint := strings.Split(inputEndpoint, "~")
applicationFor:
for i := 0; i < len(rtmp.Server.Applications); i++ {
if rtmp.Server.Applications[i].Name == endpoint[1] {
for j := 0; j < len(rtmp.Server.Applications[i].Live.Streams); j++ {
if rtmp.Server.Applications[i].Live.Streams[j].Name == inputStream {
found = true
streamIn = endpoint[1] + "/" + rtmp.Server.Applications[i].Live.Streams[j].Name
break applicationFor
}
}
}
}

if !found {
log.Printf("unable to find current stream input")
response.Error = "unable to find current stream input"
return c.JSON(http.StatusOK, response)
}

fStart := commonTransporter.ForwarderStart{
StreamIn: c.FormValue("stream_selector"),
StreamIn: streamIn,
}

rStart := commonTransporter.RecorderStart{
StreamIn: c.FormValue("stream_selector"),
StreamIn: streamIn,
PathOut: c.FormValue("save_path"),
}

Expand Down Expand Up @@ -172,7 +216,7 @@ func (v *Views) StartUniqueFunc(c echo.Context) error {
var s *storage.Stream
s, err = v.store.AddStream(&storage.Stream{
Stream: unique,
Input: c.FormValue("stream_selector"),
Input: streamIn,
Recording: recording,
Website: websiteStream,
Streams: uint64(len(streams)),
Expand Down

0 comments on commit fd4c7c8

Please sign in to comment.