mirror of
https://github.com/elobuff/gortmp
synced 2025-09-26 23:15:51 +08:00
Yank app-specific response stuff out of rtmp library
This commit is contained in:
@@ -19,7 +19,7 @@ func (c *Client) connect() (id string, err error) {
|
||||
return id, Error("client connect: unable to complete connect: %s", err)
|
||||
}
|
||||
|
||||
if !response.IsResult() {
|
||||
if response.Name != "_result" {
|
||||
return id, Error("client connect: connect result unsuccessful: %#v", response)
|
||||
}
|
||||
|
||||
|
@@ -16,6 +16,12 @@ type Message struct {
|
||||
Buffer *bytes.Buffer
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Name string
|
||||
TransactionId float64
|
||||
Objects []interface{}
|
||||
}
|
||||
|
||||
func (m *Message) RemainingBytes() uint32 {
|
||||
if m.Buffer == nil {
|
||||
return m.Length
|
||||
|
87
response.go
87
response.go
@@ -1,87 +0,0 @@
|
||||
package rtmp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/elobuff/goamf"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Name string
|
||||
TransactionId float64
|
||||
Objects []interface{}
|
||||
}
|
||||
|
||||
type ResponseError struct {
|
||||
Code string
|
||||
Message string
|
||||
Substitution string
|
||||
}
|
||||
|
||||
func (r *Response) IsResult() bool {
|
||||
return r.Name == "_result"
|
||||
}
|
||||
|
||||
func (r *Response) IsError() bool {
|
||||
return r.Name == "_error"
|
||||
}
|
||||
|
||||
func (r *Response) HasBody() (result bool) {
|
||||
for _, obj := range r.Objects {
|
||||
if obj, ok := obj.(amf.Object); ok == true {
|
||||
if _, ok := obj["body"]; ok == true {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *Response) DecodeBody() (result interface{}, err error) {
|
||||
for _, obj := range r.Objects {
|
||||
if obj, ok := obj.(amf.Object); ok == true {
|
||||
if body := obj["body"]; body != nil {
|
||||
return body, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *Response) DecodeError() (result ResponseError, err error) {
|
||||
for _, obj := range r.Objects {
|
||||
if obj, ok := obj.(amf.Object); ok == true {
|
||||
if rc := obj["rootCause"]; rc != nil {
|
||||
if rcobj, ok := rc.(amf.Object); ok == true {
|
||||
result = *new(ResponseError)
|
||||
|
||||
if tmp, ok := rcobj["errorCode"].(string); ok {
|
||||
result.Code = tmp
|
||||
}
|
||||
|
||||
if tmp, ok := rcobj["message"].(string); ok {
|
||||
result.Message = tmp
|
||||
}
|
||||
|
||||
if sa := rcobj["substitutionArguments"]; sa != nil {
|
||||
if subArgs, ok := sa.(amf.Array); ok {
|
||||
length := len(subArgs)
|
||||
if length > 0 {
|
||||
if tmp, ok := subArgs[length-1].(string); ok {
|
||||
result.Substitution = tmp
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result.Message = fmt.Sprintf("%+v", r)
|
||||
|
||||
return result, Error("Could not decode object error")
|
||||
}
|
Reference in New Issue
Block a user