mirror of
https://github.com/lkmio/lkm.git
synced 2025-10-04 14:52:44 +08:00
完善hook通知事件
This commit is contained in:
78
stream/hook_source.go
Normal file
78
stream/hook_source.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package stream
|
||||
|
||||
import (
|
||||
"github.com/yangjiechina/avformat/utils"
|
||||
"github.com/yangjiechina/lkm/log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func PreparePublishSource(source Source, hook bool) (*http.Response, utils.HookState) {
|
||||
var response *http.Response
|
||||
|
||||
if hook && AppConfig.Hook.EnablePublishEvent() {
|
||||
rep, state := HookPublishEvent(source)
|
||||
if utils.HookStateOK != state {
|
||||
return rep, state
|
||||
}
|
||||
|
||||
response = rep
|
||||
}
|
||||
|
||||
if err := SourceManager.Add(source); err != nil {
|
||||
log.Sugar.Errorf("添加源失败 source:%s err:%s", source.Id(), err.Error())
|
||||
return nil, utils.HookStateOccupy
|
||||
}
|
||||
|
||||
if AppConfig.ReceiveTimeout > 0 {
|
||||
source.StartReceiveDataTimer()
|
||||
}
|
||||
|
||||
if AppConfig.IdleTimeout > 0 {
|
||||
source.StartIdleTimer()
|
||||
}
|
||||
|
||||
return response, utils.HookStateOK
|
||||
}
|
||||
|
||||
func HookPublishEvent(source Source) (*http.Response, utils.HookState) {
|
||||
var response *http.Response
|
||||
|
||||
if AppConfig.Hook.EnablePublishEvent() {
|
||||
hook, err := Hook(HookEventPublish, NewHookPublishEventInfo(source))
|
||||
if err != nil {
|
||||
log.Sugar.Errorf("通知推流事件失败 source:%s err:%s", source.Id(), err.Error())
|
||||
return hook, utils.HookStateFailure
|
||||
}
|
||||
|
||||
response = hook
|
||||
}
|
||||
|
||||
return response, utils.HookStateOK
|
||||
}
|
||||
|
||||
func HookPublishDoneEvent(source Source) {
|
||||
if AppConfig.Hook.EnablePublishEvent() {
|
||||
_, err := Hook(HookEventPublishDone, NewHookPublishEventInfo(source))
|
||||
if err != nil {
|
||||
log.Sugar.Errorf("通知推流结束事件失败 source:%s err:%s", source.Id(), err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func HookReceiveTimeoutEvent(source Source) {
|
||||
if AppConfig.Hook.EnableOnReceiveTimeout() {
|
||||
_, err := Hook(HookEventReceiveTimeout, NewHookPublishEventInfo(source))
|
||||
if err != nil {
|
||||
log.Sugar.Errorf("通知收流超时事件失败 source:%s err:%s", source.Id(), err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func HookIdleTimeoutEvent(source Source) {
|
||||
if AppConfig.Hook.EnableOnIdleTimeout() {
|
||||
_, err := Hook(HookEventIdleTimeout, NewHookPublishEventInfo(source))
|
||||
if err != nil {
|
||||
log.Sugar.Errorf("通知空闲超时时间失败 source:%s err:%s", source.Id(), err.Error())
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user