From 3d7e00169b038908e6f5c618f5cf447903020808 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Fri, 11 Aug 2023 13:12:12 +0500 Subject: [PATCH] Refactor command process to separate file --- rtmp/amf/command.go | 31 +++++++++++++++++++++++++++++++ rtmp/amf/decode.go | 32 -------------------------------- 2 files changed, 31 insertions(+), 32 deletions(-) create mode 100644 rtmp/amf/command.go diff --git a/rtmp/amf/command.go b/rtmp/amf/command.go new file mode 100644 index 0000000..e9c2609 --- /dev/null +++ b/rtmp/amf/command.go @@ -0,0 +1,31 @@ +package amf + +import "errors" + +func (amf_obj_root AMFObj) ProcessConnect() (string, error) { + err := errors.New("Bad AMF connect command") + if _, ok := amf_obj_root[0]; !ok { + return "", err + } else if command_string, ok := amf_obj_root[0].(string); !ok || command_string != "connect" { + return "", err + } + + if _, ok := amf_obj_root[1]; !ok { + return "", err + } else if transac_id_float, ok := amf_obj_root[1].(float64); !ok || transac_id_float != 1.0 { + return "", err + } + + if _, ok := amf_obj_root[2]; !ok { + return "", err + } else if _, ok := amf_obj_root[2].(AMFObj); !ok { + return "", err + } else if _, ok := amf_obj_root[2].(AMFObj)["tcUrl"]; !ok { + return "", err + } else if tcUrl, ok := amf_obj_root[2].(AMFObj)["tcUrl"].(string); ok { + return tcUrl, nil + } else { + return "", err + } + +} diff --git a/rtmp/amf/decode.go b/rtmp/amf/decode.go index 053e69e..68b62b4 100644 --- a/rtmp/amf/decode.go +++ b/rtmp/amf/decode.go @@ -1,9 +1,5 @@ package amf -import ( - "errors" -) - type AMFObj map[interface{}]interface{} func DecodeAMF(data *[]byte) (AMFObj, error) { @@ -15,31 +11,3 @@ func DecodeAMF(data *[]byte) (AMFObj, error) { test["tcUrl"] = "rtmp://test-domain.nil/Desktop/tmp" return obj, nil } - -func (amf_obj_root AMFObj) ProcessConnect() (string, error) { - err := errors.New("Bad AMF connect command") - if _, ok := amf_obj_root[0]; !ok { - return "", err - } else if command_string, ok := amf_obj_root[0].(string); !ok || command_string != "connect" { - return "", err - } - - if _, ok := amf_obj_root[1]; !ok { - return "", err - } else if transac_id_float, ok := amf_obj_root[1].(float64); !ok || transac_id_float != 1.0 { - return "", err - } - - if _, ok := amf_obj_root[2]; !ok { - return "", err - } else if _, ok := amf_obj_root[2].(AMFObj); !ok { - return "", err - } else if _, ok := amf_obj_root[2].(AMFObj)["tcUrl"]; !ok { - return "", err - } else if tcUrl, ok := amf_obj_root[2].(AMFObj)["tcUrl"].(string); ok { - return tcUrl, nil - } else { - return "", err - } - -}