mirror of
https://github.com/elobuff/gortmp
synced 2025-12-24 13:08:13 +08:00
Add decoding of amf external via handler
This commit is contained in:
@@ -2,6 +2,7 @@ package rtmp
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"github.com/elobuff/goamf"
|
||||
"net"
|
||||
"net/url"
|
||||
"sync"
|
||||
@@ -33,6 +34,8 @@ type Client struct {
|
||||
|
||||
lastTransactionId uint32
|
||||
connectionId string
|
||||
|
||||
amfExternalHandlers map[string]amf.ExternalHandler
|
||||
}
|
||||
|
||||
func NewClient(url string) (c *Client) {
|
||||
@@ -78,11 +81,16 @@ func (c *Client) Reset() {
|
||||
c.inChunkSize = DEFAULT_CHUNK_SIZE
|
||||
c.inWindowSize = DEFAULT_WINDOW_SIZE
|
||||
c.inChunkStreams = make(map[uint32]*InboundChunkStream)
|
||||
c.amfExternalHandlers = make(map[string]amf.ExternalHandler)
|
||||
c.responses = make(map[uint32]*Response)
|
||||
c.lastTransactionId = 0
|
||||
c.connectionId = ""
|
||||
}
|
||||
|
||||
func (c *Client) RegisterExternalHandler(name string, fn amf.ExternalHandler) {
|
||||
c.amfExternalHandlers[name] = fn
|
||||
}
|
||||
|
||||
func (c *Client) Disconnect() {
|
||||
c.Reset()
|
||||
log.Info("disconnected from %s", c.url)
|
||||
|
||||
@@ -23,7 +23,7 @@ func (c *Client) routeLoop() {
|
||||
}
|
||||
|
||||
func (c *Client) routeCommandMessage(msg *Message) {
|
||||
response, err := msg.DecodeResponse()
|
||||
response, err := msg.DecodeResponse(c)
|
||||
if err != nil {
|
||||
log.Error("unable to decode message type %d on stream %d into command, discarding: %s", msg.Type, msg.ChunkStreamId, err)
|
||||
return
|
||||
|
||||
@@ -24,10 +24,14 @@ func (m *Message) RemainingBytes() uint32 {
|
||||
return m.Length - uint32(m.Buffer.Len())
|
||||
}
|
||||
|
||||
func (m *Message) DecodeResponse() (response *Response, err error) {
|
||||
dec := new(amf.Decoder)
|
||||
func (m *Message) DecodeResponse(c *Client) (response *Response, err error) {
|
||||
dec := amf.NewDecoder()
|
||||
response = new(Response)
|
||||
|
||||
for nam, fn := range c.amfExternalHandlers {
|
||||
dec.RegisterExternalHandler(nam, fn)
|
||||
}
|
||||
|
||||
if m.ChunkStreamId != CHUNK_STREAM_ID_COMMAND {
|
||||
return response, Error("message is not a command message")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user