Stream key not involved until publish stage, just check if proper command and app

This commit is contained in:
Muaz Ahmad 2023-08-11 15:21:49 +05:00
parent 3d7e00169b
commit ca36226491
2 changed files with 18 additions and 38 deletions

View file

@ -2,30 +2,31 @@ package amf
import "errors" import "errors"
func (amf_obj_root AMFObj) ProcessConnect() (string, error) { func (amf_obj_root AMFObj) ProcessConnect() (err error) {
err := errors.New("Bad AMF connect command") err = errors.New("Bad AMF connect command")
if _, ok := amf_obj_root[0]; !ok { if _, ok := amf_obj_root[0]; !ok {
return "", err return
} else if command_string, ok := amf_obj_root[0].(string); !ok || command_string != "connect" { } else if command_string, ok := amf_obj_root[0].(string); !ok || command_string != "connect" {
return "", err return
} }
if _, ok := amf_obj_root[1]; !ok { if _, ok := amf_obj_root[1]; !ok {
return "", err return
} else if transac_id_float, ok := amf_obj_root[1].(float64); !ok || transac_id_float != 1.0 { } else if transac_id_float, ok := amf_obj_root[1].(float64); !ok || transac_id_float != 1.0 {
return "", err return
} }
if _, ok := amf_obj_root[2]; !ok { if _, ok := amf_obj_root[2]; !ok {
return "", err return
} else if _, ok := amf_obj_root[2].(AMFObj); !ok { } else if _, ok := amf_obj_root[2].(AMFObj); !ok {
return "", err return
} else if _, ok := amf_obj_root[2].(AMFObj)["tcUrl"]; !ok { } else if _, ok := amf_obj_root[2].(AMFObj)["app"]; !ok {
return "", err return
} else if tcUrl, ok := amf_obj_root[2].(AMFObj)["tcUrl"].(string); ok { } else if _, ok := amf_obj_root[2].(AMFObj)["app"].(string); !ok {
return tcUrl, nil return
} else { } else if amf_obj_root[2].(AMFObj)["app"].(string) != "live" {
return "", err return
} }
err = nil
return
} }

View file

@ -4,10 +4,6 @@ import (
"net" "net"
"encoding/binary" "encoding/binary"
"stream_server/rtmp/amf" "stream_server/rtmp/amf"
"errors"
"strings"
"fmt"
"os"
) )
type ChunkWrapper struct { type ChunkWrapper struct {
@ -70,27 +66,10 @@ func (chnk_wrp_ptr *ChunkWrapper) ReadConnectCommand() (error) {
if err != nil { if err != nil {
return err return err
} }
tcUrl, err := amf_obj.ProcessConnect() err = amf_obj.ProcessConnect()
if err != nil { if err != nil {
return err return err
} }
if chnk_wrp_ptr.params.stream_key, err = check_stream_key(tcUrl); err != nil {
return err return err
}
return nil
}
func check_stream_key(tcUrl string) (string, error) {
err := errors.New("bad stream key")
tcUrl_split := strings.Split(tcUrl, "/")
if len(tcUrl_split) != 5 {
return "", err
}
base_dir, _ := os.UserHomeDir()
stream_dir := base_dir + "/live/" + tcUrl_split[4]
fileinfo, err := os.Stat(stream_dir)
if err == nil && fileinfo.IsDir() {
return tcUrl_split[4], nil
}
return "", err
} }