From c92c1fc3e9ce81c74776bbb7890243df8955ee86 Mon Sep 17 00:00:00 2001 From: Alexey Khit Date: Tue, 13 Sep 2022 15:42:39 +0300 Subject: [PATCH] Adds echo source --- cmd/echo/echo.go | 29 +++++++++++++++++++++++++++++ main.go | 3 +++ 2 files changed, 32 insertions(+) create mode 100644 cmd/echo/echo.go diff --git a/cmd/echo/echo.go b/cmd/echo/echo.go new file mode 100644 index 00000000..460f5cdc --- /dev/null +++ b/cmd/echo/echo.go @@ -0,0 +1,29 @@ +package echo + +import ( + "bytes" + "github.com/AlexxIT/go2rtc/cmd/app" + "github.com/AlexxIT/go2rtc/cmd/streams" + "github.com/AlexxIT/go2rtc/pkg/shell" + "github.com/AlexxIT/go2rtc/pkg/streamer" + "os/exec" +) + +func Init() { + log := app.GetLogger("echo") + + streams.HandleFunc("echo", func(url string) (streamer.Producer, error) { + args := shell.QuoteSplit(url[5:]) + + b, err := exec.Command(args[0], args[1:]...).Output() + if err != nil { + return nil, err + } + + b = bytes.TrimSpace(b) + + log.Debug().Str("url", url).Msgf("[echo] %s", b) + + return streams.GetProducer(string(b)) + }) +} diff --git a/main.go b/main.go index 6c6f69d2..4b664c48 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "github.com/AlexxIT/go2rtc/cmd/api" "github.com/AlexxIT/go2rtc/cmd/app" "github.com/AlexxIT/go2rtc/cmd/debug" + "github.com/AlexxIT/go2rtc/cmd/echo" "github.com/AlexxIT/go2rtc/cmd/exec" "github.com/AlexxIT/go2rtc/cmd/ffmpeg" "github.com/AlexxIT/go2rtc/cmd/hass" @@ -25,6 +26,8 @@ func main() { app.Init() // init config and logs streams.Init() // load streams list + echo.Init() + rtsp.Init() // add support RTSP client and RTSP server rtmp.Init() // add support RTMP client exec.Init() // add support exec scheme (depends on RTSP server)