Skip to content

Commit

Permalink
Fix decoding format of OnStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
yutopp committed Jul 20, 2023
1 parent 62930c7 commit b40efde
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion message/body_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func DecodeBodyOnStatus(_ io.Reader, d AMFDecoder, v *AMFConvertible) error {
if err := d.Decode(&commandObject); err != nil {
return errors.Wrap(err, "Failed to decode 'OnStatus' args[0]")
}
var infoObject NetStreamOnStatusInfoObject
var infoObject map[string]interface{}
if err := d.Decode(&infoObject); err != nil {
return errors.Wrap(err, "Failed to decode 'OnStatus' args[1]")
}
Expand Down
29 changes: 28 additions & 1 deletion message/net_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package message

import "errors"

type NetStreamPublish struct {
CommandObject interface{}
PublishingName string
Expand Down Expand Up @@ -85,7 +87,32 @@ type NetStreamOnStatusInfoObject struct {

func (t *NetStreamOnStatus) FromArgs(args ...interface{}) error {
// args[0] is nil, ignore
t.InfoObject = args[1].(NetStreamOnStatusInfoObject)

info, ok := args[1].(map[string]interface{})
if !ok {
return errors.New("invalid type") // TODO: fix
}
if v, ok := info["level"]; ok {
level, ok := v.(string)
if !ok {
return errors.New("invalid type") // TODO: fix
}
t.InfoObject.Level = NetStreamOnStatusLevel(level) // TODO: type check
}
if v, ok := info["code"]; ok {
code, ok := v.(string)
if !ok {
return errors.New("invalid type") // TODO: fix
}
t.InfoObject.Code = NetStreamOnStatusCode(code) // TODO: type check
}
if v, ok := info["description"]; ok {
description, ok := v.(string)
if !ok {
return errors.New("invalid type") // TODO: fix
}
t.InfoObject.Description = description
}

return nil
}
Expand Down

0 comments on commit b40efde

Please sign in to comment.