stream-server/rtmp/connect.go

79 lines
2.2 KiB
Go
Raw Permalink Normal View History

2023-08-09 16:00:21 +05:00
package rtmp
import (
"os"
)
2023-08-09 16:00:21 +05:00
2023-08-21 20:25:54 +05:00
// series of messages sent from the client and responses
// window ack and peer bw seem to be completely useless to obs
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
2023-08-10 03:24:00 +05:00
}
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
}
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-21 20:25:54 +05:00
// next sequence
func CreateStream(chnk_wrp_ptr *ChunkWrapper) (bool) {
2023-08-21 20:25:54 +05:00
// first 2 messages are "releaseStream" and "FCPublish"
// no idea why the second exists since the next command is Publish
// the first has no docs since flash server docs are gone
// assuming it just signals a delete on any streams the current connection had
// it can be ignored for a pure stream intake server
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
}
2023-08-21 20:25:54 +05:00
// Publish command handling, this is where stream keys are exchanged which means
// auth checking happens here
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
}
2023-08-21 20:25:54 +05:00
// auth checking. again db would be the goal, for now just using a dir system
// pre generate a directory under ~/live/___/. Set the stream key to the folder name
// and this just checks if the folder exists (like a known public key)
// not secure at all but works for a demo
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
}