Add connect command read code, import amf package

This commit is contained in:
Muaz Ahmad 2023-08-10 23:53:58 +05:00
parent ac5834a12e
commit 7782f14eb5

View file

@ -3,6 +3,7 @@ package rtmp
import ( import (
"net" "net"
"encoding/binary" "encoding/binary"
"stream_server/rtmp/amf"
) )
type ChunkWrapper struct { type ChunkWrapper struct {
@ -17,7 +18,7 @@ func NewChunkWrapper(conn net.Conn) (chnk_wrp_ptr *ChunkWrapper) {
chnk_wrp_ptr = new(ChunkWrapper) chnk_wrp_ptr = new(ChunkWrapper)
chnk_wrp_ptr.conn = conn 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_chnkstrms = make(map[uint32]*ChunkStream)
chnk_wrp_ptr.open_msgs = make(map[uint32]*Message) chnk_wrp_ptr.open_msgs = make(map[uint32]*Message)
buffers := ChunkBuffers{ 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) chnk_wrp_ptr.params.peer_chunk_size = binary.BigEndian.Uint32(set_chunk_size_msg.data)
return nil 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
}