2023-08-10 23:53:23 +05:00
|
|
|
package amf
|
|
|
|
|
2023-08-11 13:09:36 +05:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
2023-08-10 23:53:23 +05:00
|
|
|
|
|
|
|
type AMFObj map[interface{}]interface{}
|
|
|
|
|
|
|
|
func DecodeAMF(data *[]byte) (AMFObj, error) {
|
|
|
|
obj := make(AMFObj)
|
|
|
|
test := make(AMFObj)
|
2023-08-11 13:09:36 +05:00
|
|
|
obj[0] = "connect"
|
|
|
|
obj[1] = float64(1)
|
2023-08-10 23:53:23 +05:00
|
|
|
obj[2] = test
|
2023-08-11 13:09:36 +05:00
|
|
|
test["tcUrl"] = "rtmp://test-domain.nil/Desktop/tmp"
|
2023-08-10 23:53:23 +05:00
|
|
|
return obj, nil
|
|
|
|
}
|
2023-08-11 13:09:36 +05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|