mirror of
https://github.com/datarhei/core.git
synced 2025-10-05 16:07:07 +08:00
Add SRT proxying
This commit is contained in:
17
rtmp/rtmp.go
17
rtmp/rtmp.go
@@ -196,7 +196,7 @@ type Config struct {
|
||||
// with methods like tls.Config.SetSessionTicketKeys.
|
||||
TLSConfig *tls.Config
|
||||
|
||||
Cluster cluster.Cluster
|
||||
Cluster cluster.ClusterReader
|
||||
}
|
||||
|
||||
// Server represents a RTMP server
|
||||
@@ -231,7 +231,7 @@ type server struct {
|
||||
channels map[string]*channel
|
||||
lock sync.RWMutex
|
||||
|
||||
cluster cluster.Cluster
|
||||
cluster cluster.ClusterReader
|
||||
}
|
||||
|
||||
// New creates a new RTMP server according to the given config
|
||||
@@ -256,6 +256,10 @@ func New(config Config) (Server, error) {
|
||||
s.collector = session.NewNullCollector()
|
||||
}
|
||||
|
||||
if s.cluster == nil {
|
||||
s.cluster = cluster.NewDummyClusterReader()
|
||||
}
|
||||
|
||||
s.server = &rtmp.Server{
|
||||
Addr: config.Addr,
|
||||
HandlePlay: s.handlePlay,
|
||||
@@ -404,16 +408,15 @@ func (s *server) handlePlay(conn *rtmp.Conn) {
|
||||
s.log("PLAY", "STOP", conn.URL.Path, "", client)
|
||||
} else {
|
||||
// Check in the cluster for that stream
|
||||
if s.cluster != nil {
|
||||
url, err := s.cluster.GetURL("rtmp:" + conn.URL.Path)
|
||||
url, err := s.cluster.GetURL("rtmp:" + conn.URL.Path)
|
||||
if err == nil {
|
||||
src, err := avutil.Open(url)
|
||||
if err != nil {
|
||||
s.logger.Error().WithField("address", url).WithError(err).Log("Proxying address failed")
|
||||
s.log("PLAY", "NOTFOUND", conn.URL.Path, "", client)
|
||||
} else {
|
||||
s.log("PLAY", "PROXYSTART", url, "", client)
|
||||
|
||||
src, _ := avutil.Open(url)
|
||||
avutil.CopyFile(conn, src)
|
||||
|
||||
s.log("PLAY", "PROXYSTOP", url, "", client)
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user