2023-08-09 16:00:21 +05:00
|
|
|
package rtmp
|
|
|
|
|
2023-08-17 14:57:30 +05:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
2023-08-09 16:00:21 +05:00
|
|
|
|
2023-08-10 20:34:10 +05:00
|
|
|
func NegotiateConnect(chnk_wrp_ptr *ChunkWrapper) (bool) {
|
2023-08-10 20:58:01 +05:00
|
|
|
if err := chnk_wrp_ptr.ReadPeerChunkSize(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2023-08-10 23:52:52 +05:00
|
|
|
if err := chnk_wrp_ptr.ReadConnectCommand(); err != nil {
|
|
|
|
return false
|
2023-08-10 03:24:00 +05:00
|
|
|
}
|
2023-08-13 14:30:39 +05:00
|
|
|
if err := chnk_wrp_ptr.WriteWindowAckSize(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2023-08-13 14:43:07 +05:00
|
|
|
if err := chnk_wrp_ptr.WritePeerBandwidth(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if err := chnk_wrp_ptr.WriteChunkSize(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2023-08-15 12:32:44 +05:00
|
|
|
if err := chnk_wrp_ptr.WriteConnectResponse(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2023-08-15 14:27:54 +05:00
|
|
|
return true
|
2023-08-09 16:00:21 +05:00
|
|
|
}
|
2023-08-15 15:29:46 +05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2023-08-15 15:54:04 +05:00
|
|
|
if err := chnk_wrp_ptr.ReadCreateStream(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if err := chnk_wrp_ptr.WriteCreateStreamResponse(); err != nil {
|
|
|
|
return false
|
|
|
|
}
|
2023-08-17 14:57:30 +05:00
|
|
|
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
|
|
|
|
}
|
2023-08-15 17:46:41 +05:00
|
|
|
p, _ := chnk_wrp_ptr.ReadChunk()
|
|
|
|
fmt.Println(p)
|
2023-08-15 15:29:46 +05:00
|
|
|
return true
|
|
|
|
}
|
2023-08-17 14:57:30 +05:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|