mirror of
https://github.com/lkmio/lkm.git
synced 2025-09-27 03:26:01 +08:00
通知播放结束事件携带sink id
This commit is contained in:
@@ -71,7 +71,7 @@ func Hook(event HookEvent, params string, body interface{}) (*http.Response, err
|
||||
}
|
||||
|
||||
func NewHookPlayEventInfo(sink Sink) eventInfo {
|
||||
return eventInfo{Stream: sink.GetSourceID(), Protocol: sink.GetProtocol().String(), RemoteAddr: sink.String()}
|
||||
return eventInfo{Stream: sink.GetSourceID(), Protocol: sink.GetProtocol().String(), RemoteAddr: sink.RemoteAddr()}
|
||||
}
|
||||
|
||||
func NewHookPublishEventInfo(source Source) eventInfo {
|
||||
|
@@ -16,7 +16,7 @@ func PreparePlaySinkWithReady(sink Sink, ok bool) (*http.Response, utils.HookSta
|
||||
if AppConfig.Hooks.IsEnableOnPlay() {
|
||||
hook, err := Hook(HookEventPlay, sink.UrlValues().Encode(), NewHookPlayEventInfo(sink))
|
||||
if err != nil {
|
||||
log.Sugar.Errorf("播放事件-通知失败 err:%s sink:%s-%v source:%s", err.Error(), sink.GetProtocol().String(), sink.GetID(), sink.GetSourceID())
|
||||
log.Sugar.Errorf("播放事件-通知失败 err: %s sink: %s-%v source: %s", err.Error(), sink.GetProtocol().String(), sink.GetID(), sink.GetSourceID())
|
||||
|
||||
return hook, utils.HookStateFailure
|
||||
}
|
||||
@@ -27,14 +27,14 @@ func PreparePlaySinkWithReady(sink Sink, ok bool) (*http.Response, utils.HookSta
|
||||
sink.SetReady(ok)
|
||||
source := SourceManager.Find(sink.GetSourceID())
|
||||
if source == nil {
|
||||
log.Sugar.Infof("添加sink到等待队列 sink:%s-%v source:%s", sink.GetProtocol().String(), sink.GetID(), sink.GetSourceID())
|
||||
log.Sugar.Infof("添加%s sink到等待队列 id: %v source: %s", sink.GetProtocol().String(), sink.GetID(), sink.GetSourceID())
|
||||
|
||||
{
|
||||
sink.Lock()
|
||||
defer sink.UnLock()
|
||||
|
||||
if SessionStateClosed == sink.GetState() {
|
||||
log.Sugar.Warnf("添加到sink到等待队列失败, sink已经断开连接 %s", sink.GetID())
|
||||
log.Sugar.Warnf("添加到%s sink到等待队列失败, sink已经断开连接 %s", sink.GetProtocol(), sink.GetID())
|
||||
return response, utils.HookStateFailure
|
||||
} else {
|
||||
sink.SetState(SessionStateWaiting)
|
||||
@@ -52,9 +52,17 @@ func HookPlayDoneEvent(sink Sink) (*http.Response, bool) {
|
||||
var response *http.Response
|
||||
|
||||
if AppConfig.Hooks.IsEnableOnPlayDone() {
|
||||
hook, err := Hook(HookEventPlayDone, sink.UrlValues().Encode(), NewHookPlayEventInfo(sink))
|
||||
body := struct {
|
||||
eventInfo
|
||||
Sink string `json:"sink"`
|
||||
}{
|
||||
eventInfo: NewHookPlayEventInfo(sink),
|
||||
Sink: SinkId2String(sink.GetID()),
|
||||
}
|
||||
|
||||
hook, err := Hook(HookEventPlayDone, sink.UrlValues().Encode(), body)
|
||||
if err != nil {
|
||||
log.Sugar.Errorf("播放结束事件-通知失败 err:%s sink:%s-%v source:%s", err.Error(), sink.GetProtocol().String(), sink.GetID(), sink.GetSourceID())
|
||||
log.Sugar.Errorf("播放结束事件-通知失败 err: %s sink: %s-%v source: %s", err.Error(), sink.GetProtocol().String(), sink.GetID(), sink.GetSourceID())
|
||||
return hook, false
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,7 @@ package stream
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
)
|
||||
@@ -48,3 +49,7 @@ func SinkId2String(id SinkID) string {
|
||||
|
||||
return id.(string)
|
||||
}
|
||||
|
||||
func CreateSinkDisconnectionMessage(sink Sink) string {
|
||||
return fmt.Sprintf("%s sink断开连接. id: %s", sink.GetProtocol(), sink.GetID())
|
||||
}
|
||||
|
Reference in New Issue
Block a user