diff --git a/README.md b/README.md index 6f174ce..fdcc873 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ rtmp: repush: 0 # 当断开后是否自动重新推流,0代表不进行重新推流,-1代表无限次重新推流 pushlist: {} # 推流列表,以 streamPath为key,远程地址为value chunksize: 4096 + keepalive: false #保持rtmp连接,默认随着stream的close而主动断开 ``` :::tip 配置覆盖 publish diff --git a/main.go b/main.go index bce826f..bfb0ab0 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ type RTMPConfig struct { config.Pull config.Push ChunkSize int + KeepAlive bool //保持rtmp连接,默认随着stream的close而主动断开 } func (c *RTMPConfig) OnEvent(event any) { @@ -59,6 +60,7 @@ func (c *RTMPConfig) OnEvent(event any) { } } } + var conf = &RTMPConfig{ ChunkSize: 4096, TCP: config.TCP{ListenAddr: ":1935"}, diff --git a/server.go b/server.go index f4fd024..f7edce3 100644 --- a/server.go +++ b/server.go @@ -130,6 +130,9 @@ func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) { }, } receiver.SetParentCtx(ctx) + if !config.KeepAlive { + receiver.SetIO(conn) + } if plugin.Publish(nc.appName+"/"+cmd.PublishingName, receiver) == nil { receivers[cmd.StreamId] = receiver receiver.absTs = make(map[uint32]uint32) @@ -146,6 +149,9 @@ func (config *RTMPConfig) ServeTCP(conn *net.TCPConn) { cmd.StreamId, } sender.SetParentCtx(ctx) + if !config.KeepAlive { + sender.SetIO(conn) + } sender.ID = fmt.Sprintf("%s|%d", conn.RemoteAddr().String(), sender.StreamID) if plugin.Subscribe(streamPath, sender) != nil { sender.Response(cmd.TransactionId, NetStream_Play_Failed, Level_Error)