mirror of
https://github.com/bluenviron/mediamtx
synced 2025-01-10 08:59:57 +00:00
rtsp server: make runOnConnect work again (#1409)
This commit is contained in:
parent
b02d3b83c7
commit
44fda6650f
@ -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) {
|
||||
|
@ -134,6 +134,8 @@ func newRTSPServer(
|
||||
isTLS: isTLS,
|
||||
rtspAddress: rtspAddress,
|
||||
protocols: protocols,
|
||||
runOnConnect: runOnConnect,
|
||||
runOnConnectRestart: runOnConnectRestart,
|
||||
externalCmdPool: externalCmdPool,
|
||||
metrics: metrics,
|
||||
pathManager: pathManager,
|
||||
|
@ -1,7 +1,9 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/aler9/gortsplib/v2"
|
||||
"github.com/aler9/gortsplib/v2/pkg/media"
|
||||
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user