mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-10-23 15:43:17 +08:00
rtsp server: make runOnConnect work again (#1409)
This commit is contained in:
@@ -17,6 +17,37 @@ import (
|
|||||||
"github.com/aler9/rtsp-simple-server/internal/rtmp/message"
|
"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) {
|
func TestRTMPServerPublishRead(t *testing.T) {
|
||||||
for _, ca := range []string{"plain", "tls"} {
|
for _, ca := range []string{"plain", "tls"} {
|
||||||
t.Run(ca, func(t *testing.T) {
|
t.Run(ca, func(t *testing.T) {
|
||||||
|
@@ -134,6 +134,8 @@ func newRTSPServer(
|
|||||||
isTLS: isTLS,
|
isTLS: isTLS,
|
||||||
rtspAddress: rtspAddress,
|
rtspAddress: rtspAddress,
|
||||||
protocols: protocols,
|
protocols: protocols,
|
||||||
|
runOnConnect: runOnConnect,
|
||||||
|
runOnConnectRestart: runOnConnectRestart,
|
||||||
externalCmdPool: externalCmdPool,
|
externalCmdPool: externalCmdPool,
|
||||||
metrics: metrics,
|
metrics: metrics,
|
||||||
pathManager: pathManager,
|
pathManager: pathManager,
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/aler9/gortsplib/v2"
|
"github.com/aler9/gortsplib/v2"
|
||||||
"github.com/aler9/gortsplib/v2/pkg/media"
|
"github.com/aler9/gortsplib/v2/pkg/media"
|
||||||
@@ -10,6 +12,34 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"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) {
|
func TestRTSPServerAuth(t *testing.T) {
|
||||||
for _, ca := range []string{
|
for _, ca := range []string{
|
||||||
"internal",
|
"internal",
|
||||||
|
Reference in New Issue
Block a user