refactor: remove some stupid code

This commit is contained in:
langhuihui
2023-05-25 14:14:37 +08:00
parent 0f616832c5
commit d92e00ac9b

26
main.go
View File

@@ -22,6 +22,11 @@ type RTMPConfig struct {
KeepAlive bool //保持rtmp连接默认随着stream的close而主动断开 KeepAlive bool //保持rtmp连接默认随着stream的close而主动断开
} }
func pull(streamPath, url string) {
if err := RTMPPlugin.Pull(streamPath, url, new(RTMPPuller), 0); err != nil {
RTMPPlugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err))
}
}
func (c *RTMPConfig) OnEvent(event any) { func (c *RTMPConfig) OnEvent(event any) {
switch v := event.(type) { switch v := event.(type) {
case FirstConfig: case FirstConfig:
@@ -30,9 +35,7 @@ func (c *RTMPConfig) OnEvent(event any) {
go c.Listen(RTMPPlugin, c) go c.Listen(RTMPPlugin, c)
} }
for streamPath, url := range c.PullOnStart { for streamPath, url := range c.PullOnStart {
if err := RTMPPlugin.Pull(streamPath, url, new(RTMPPuller), 0); err != nil { pull(streamPath, url)
RTMPPlugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err))
}
} }
case config.Config: case config.Config:
RTMPPlugin.CancelFunc() RTMPPlugin.CancelFunc()
@@ -42,21 +45,14 @@ func (c *RTMPConfig) OnEvent(event any) {
go c.Listen(RTMPPlugin, c) go c.Listen(RTMPPlugin, c)
} }
case SEpublish: case SEpublish:
for streamPath, url := range c.PushList { if url, ok := c.PushList[v.Target.Path]; ok {
if streamPath == v.Target.Path { if err := RTMPPlugin.Push(v.Target.Path, url, new(RTMPPusher), false); err != nil {
if err := RTMPPlugin.Push(streamPath, url, new(RTMPPusher), false); err != nil { RTMPPlugin.Error("push", zap.String("streamPath", v.Target.Path), zap.String("url", url), zap.Error(err))
RTMPPlugin.Error("push", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err))
}
} }
} }
case *Stream: //按需拉流 case *Stream: //按需拉流
for streamPath, url := range c.PullOnSub { if url, ok := c.PullOnSub[v.Path]; ok {
if streamPath == v.Path { pull(v.Path, url)
if err := RTMPPlugin.Pull(streamPath, url, new(RTMPPuller), 0); err != nil {
RTMPPlugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err))
}
break
}
} }
} }
} }