diff --git a/rtmp/chunk_wrap.go b/rtmp/chunk_wrap.go index 550c8ac..490eb42 100644 --- a/rtmp/chunk_wrap.go +++ b/rtmp/chunk_wrap.go @@ -3,6 +3,7 @@ package rtmp import ( "net" "encoding/binary" + "stream_server/rtmp/amf" ) type ChunkWrapper struct { @@ -17,7 +18,7 @@ func NewChunkWrapper(conn net.Conn) (chnk_wrp_ptr *ChunkWrapper) { chnk_wrp_ptr = new(ChunkWrapper) chnk_wrp_ptr.conn = conn - chnk_wrp_ptr.params = &ProtocolParams{1024, 512, 0, 0} + chnk_wrp_ptr.params = &ProtocolParams{1024, 512, 0, 0, ""} chnk_wrp_ptr.open_chnkstrms = make(map[uint32]*ChunkStream) chnk_wrp_ptr.open_msgs = make(map[uint32]*Message) buffers := ChunkBuffers{ @@ -55,3 +56,16 @@ func (chnk_wrp_ptr *ChunkWrapper) ReadPeerChunkSize() (error) { chnk_wrp_ptr.params.peer_chunk_size = binary.BigEndian.Uint32(set_chunk_size_msg.data) return nil } + +func (chnk_wrp_ptr *ChunkWrapper) ReadConnectCommand() (error) { + connect_cmd_msg, err := chnk_wrp_ptr.ReadChunk() + if err != nil || connect_cmd_msg.msg_type != 20 { + return err + } + amf_obj, err := amf.DecodeAMF(&(connect_cmd_msg.data)) + if err != nil { + return err + } + chnk_wrp_ptr.params.stream_key = amf_obj[2].(amf.AMFObj)["tcUrl"].(string) + return nil +}