stream-server/rtmp/connect.go
2023-08-17 16:35:06 +05:00

64 lines
1.4 KiB
Go

package rtmp
import (
"os"
)
func NegotiateConnect(chnk_wrp_ptr *ChunkWrapper) (bool) {
if err := chnk_wrp_ptr.ReadPeerChunkSize(); err != nil {
return false
}
if err := chnk_wrp_ptr.ReadConnectCommand(); err != nil {
return false
}
if err := chnk_wrp_ptr.WriteWindowAckSize(); err != nil {
return false
}
if err := chnk_wrp_ptr.WritePeerBandwidth(); err != nil {
return false
}
if err := chnk_wrp_ptr.WriteChunkSize(); err != nil {
return false
}
if err := chnk_wrp_ptr.WriteConnectResponse(); err != nil {
return false
}
return true
}
func CreateStream(chnk_wrp_ptr *ChunkWrapper) (bool) {
if _, err := chnk_wrp_ptr.ReadChunk(); err != nil {
return false
}
if _, err := chnk_wrp_ptr.ReadChunk(); err != nil {
return false
}
if err := chnk_wrp_ptr.ReadCreateStream(); err != nil {
return false
}
if err := chnk_wrp_ptr.WriteCreateStreamResponse(); err != nil {
return false
}
return true
}
func PublishAsKey(chnk_wrp_ptr *ChunkWrapper) (bool) {
if err := chnk_wrp_ptr.ReadPublish(); err != nil {
return false
}
if !check_stream_key(chnk_wrp_ptr.params.stream_key) {
return false
}
if err := chnk_wrp_ptr.WritePublishResponse(); err != nil {
return false
}
return true
}
func check_stream_key(stream_key string) (bool) {
base_dir, _ := os.UserHomeDir()
if fileinfo, err := os.Stat(base_dir + "/live/" + stream_key); err == nil && fileinfo.IsDir() {
return true
}
return false
}