Skip to content

Commit

Permalink
rtsp server: make runOnConnect work again (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Jan 22, 2023
1 parent b02d3b8 commit 44fda66
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
31 changes: 31 additions & 0 deletions internal/core/rtmp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,37 @@ import (
"github.com/aler9/rtsp-simple-server/internal/rtmp/message"
)

func TestRTMPServerRunOnConnect(t *testing.T) {
f, err := os.CreateTemp(os.TempDir(), "rtspss-runonconnect-")
require.NoError(t, err)
f.Close()
defer os.Remove(f.Name())

p, ok := newInstance(
"runOnConnect: sh -c 'echo aa > " + f.Name() + "'\n" +
"paths:\n" +
" all:\n")
require.Equal(t, true, ok)
defer p.Close()

u, err := url.Parse("rtmp://127.0.0.1:1935/mystream")
require.NoError(t, err)

nconn, err := net.Dial("tcp", u.Host)
require.NoError(t, err)
defer nconn.Close()
conn := rtmp.NewConn(nconn)

err = conn.InitializeClient(u, true)
require.NoError(t, err)

time.Sleep(500 * time.Millisecond)

byts, err := os.ReadFile(f.Name())
require.NoError(t, err)
require.Equal(t, "aa\n", string(byts))
}

func TestRTMPServerPublishRead(t *testing.T) {
for _, ca := range []string{"plain", "tls"} {
t.Run(ca, func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions internal/core/rtsp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func newRTSPServer(
isTLS: isTLS,
rtspAddress: rtspAddress,
protocols: protocols,
runOnConnect: runOnConnect,
runOnConnectRestart: runOnConnectRestart,
externalCmdPool: externalCmdPool,
metrics: metrics,
pathManager: pathManager,
Expand Down
30 changes: 30 additions & 0 deletions internal/core/rtsp_server_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package core

import (
"os"
"testing"
"time"

"github.com/aler9/gortsplib/v2"
"github.com/aler9/gortsplib/v2/pkg/media"
Expand All @@ -10,6 +12,34 @@ import (
"github.com/stretchr/testify/require"
)

func TestRTSPServerRunOnConnect(t *testing.T) {
f, err := os.CreateTemp(os.TempDir(), "rtspss-runonconnect-")
require.NoError(t, err)
f.Close()
defer os.Remove(f.Name())

p, ok := newInstance(
"runOnConnect: sh -c 'echo aa > " + f.Name() + "'\n" +
"paths:\n" +
" all:\n")
require.Equal(t, true, ok)
defer p.Close()

source := gortsplib.Client{}

err = source.StartRecording(
"rtsp://127.0.0.1:8554/mypath",
media.Medias{testMediaH264})
require.NoError(t, err)
defer source.Close()

time.Sleep(500 * time.Millisecond)

byts, err := os.ReadFile(f.Name())
require.NoError(t, err)
require.Equal(t, "aa\n", string(byts))
}

func TestRTSPServerAuth(t *testing.T) {
for _, ca := range []string{
"internal",
Expand Down

0 comments on commit 44fda66

Please sign in to comment.