Skip to content

Commit

Permalink
Merge pull request #59 from jbreich/master
Browse files Browse the repository at this point in the history
Fix decoding of publish command, publishing type is optional
  • Loading branch information
yutopp authored Jul 19, 2023
2 parents 73d0006 + f76554c commit 2ae4e86
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
7 changes: 6 additions & 1 deletion message/body_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ func DecodeBodyPublish(_ io.Reader, d AMFDecoder, v *AMFConvertible) error {
}
var publishingType string
if err := d.Decode(&publishingType); err != nil {
return errors.Wrap(err, "Failed to decode 'publish' args[2]")
// value is optional
if errors.Is(err, io.EOF) {
publishingType = "live"
} else {
return errors.Wrap(err, "Failed to decode 'publish' args[2]")
}
}

var cmd NetStreamPublish
Expand Down
19 changes: 19 additions & 0 deletions message/body_decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ func TestDecodeCmdMessagePublish(t *testing.T) {
}, v)
}

func TestDecodeCmdMessagePublishWithoutPublishingType(t *testing.T) {
bin := []byte{
// nil
0x05,
// string: abc
0x02, 0x00, 0x03, 0x61, 0x62, 0x63,
}
r := bytes.NewReader(bin)
d := amf0.NewDecoder(r)

var v AMFConvertible
err := CmdBodyDecoderFor("publish", 42)(r, d, &v)
require.Nil(t, err)
require.Equal(t, &NetStreamPublish{
PublishingName: "abc",
PublishingType: "live",
}, v)
}

func TestDecodeCmdMessagePlay(t *testing.T) {
bin := []byte{
// nil
Expand Down

0 comments on commit 2ae4e86

Please sign in to comment.