Skip to content

Commit

Permalink
rtmp: fix compatibility with nginx-rtmp-module (#2383)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Oct 17, 2023
1 parent 648e90f commit 1e1456d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
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

0 comments on commit 1e1456d

Please sign in to comment.