Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtmp: fix compatibility with nginx-rtmp-module (#2383) #2520

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/rtmp/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func readCommandResult(
}

if cmd, ok := msg.(*message.CommandAMF0); ok {
if cmd.CommandID == commandID && cmd.Name == commandName {
if (cmd.CommandID == commandID || cmd.CommandID == 0) && cmd.Name == commandName {
if !isValid(cmd) {
return fmt.Errorf("server refused connect request")
}
Expand Down
25 changes: 19 additions & 6 deletions internal/rtmp/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import (
)

func TestNewClientConn(t *testing.T) {
for _, ca := range []string{"read", "publish"} {
for _, ca := range []string{
"read",
"read nginx rtmp",
"publish",
} {
t.Run(ca, func(t *testing.T) {
ln, err := net.Listen("tcp", "127.0.0.1:9121")
require.NoError(t, err)
Expand Down Expand Up @@ -92,7 +96,8 @@ func TestNewClientConn(t *testing.T) {
})
require.NoError(t, err)

if ca == "read" {
switch ca {
case "read", "read nginx rtmp":
msg, err = mrw.Read()
require.NoError(t, err)
require.Equal(t, &message.CommandAMF0{
Expand Down Expand Up @@ -138,7 +143,12 @@ func TestNewClientConn(t *testing.T) {
ChunkStreamID: 5,
MessageStreamID: 0x1000000,
Name: "onStatus",
CommandID: 3,
CommandID: func() int {
if ca == "read nginx rtmp" {
return 0
}
return 3
}(),
Arguments: []interface{}{
nil,
flvio.AMFMap{
Expand All @@ -149,7 +159,8 @@ func TestNewClientConn(t *testing.T) {
},
})
require.NoError(t, err)
} else {

case "publish":
msg, err = mrw.Read()
require.NoError(t, err)
require.Equal(t, &message.CommandAMF0{
Expand Down Expand Up @@ -240,10 +251,12 @@ func TestNewClientConn(t *testing.T) {
conn, err := NewClientConn(nconn, u, ca == "publish")
require.NoError(t, err)

if ca == "read" {
switch ca {
case "read", "read nginx rtmp":
require.Equal(t, uint64(3421), conn.BytesReceived())
require.Equal(t, uint64(3409), conn.BytesSent())
} else {

case "publish":
require.Equal(t, uint64(3427), conn.BytesReceived())
require.Equal(t, uint64(3466), conn.BytesSent())
}
Expand Down