Skip to content

Commit f76554c

Browse files
committed
Fix decoding of publish command, publishing type is optional
1 parent 73d0006 commit f76554c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

message/body_decoder.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,12 @@ func DecodeBodyPublish(_ io.Reader, d AMFDecoder, v *AMFConvertible) error {
200200
}
201201
var publishingType string
202202
if err := d.Decode(&publishingType); err != nil {
203-
return errors.Wrap(err, "Failed to decode 'publish' args[2]")
203+
// value is optional
204+
if errors.Is(err, io.EOF) {
205+
publishingType = "live"
206+
} else {
207+
return errors.Wrap(err, "Failed to decode 'publish' args[2]")
208+
}
204209
}
205210

206211
var cmd NetStreamPublish

message/body_decoder_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,25 @@ func TestDecodeCmdMessagePublish(t *testing.T) {
112112
}, v)
113113
}
114114

115+
func TestDecodeCmdMessagePublishWithoutPublishingType(t *testing.T) {
116+
bin := []byte{
117+
// nil
118+
0x05,
119+
// string: abc
120+
0x02, 0x00, 0x03, 0x61, 0x62, 0x63,
121+
}
122+
r := bytes.NewReader(bin)
123+
d := amf0.NewDecoder(r)
124+
125+
var v AMFConvertible
126+
err := CmdBodyDecoderFor("publish", 42)(r, d, &v)
127+
require.Nil(t, err)
128+
require.Equal(t, &NetStreamPublish{
129+
PublishingName: "abc",
130+
PublishingType: "live",
131+
}, v)
132+
}
133+
115134
func TestDecodeCmdMessagePlay(t *testing.T) {
116135
bin := []byte{
117136
// nil

0 commit comments

Comments
 (0)