mirror of
https://github.com/Monibuca/plugin-hdl.git
synced 2025-10-06 01:07:04 +08:00
HDL插件导出
This commit is contained in:
16
main.go
16
main.go
@@ -28,8 +28,8 @@ func (c *HDLConfig) OnEvent(event any) {
|
|||||||
case FirstConfig:
|
case FirstConfig:
|
||||||
if c.PullOnStart {
|
if c.PullOnStart {
|
||||||
for streamPath, url := range c.PullList {
|
for streamPath, url := range c.PullList {
|
||||||
if err := plugin.Pull(streamPath, url, new(HDLPuller), false); err != nil {
|
if err := HDLPlugin.Pull(streamPath, url, new(HDLPuller), false); err != nil {
|
||||||
plugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err))
|
HDLPlugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,8 +37,8 @@ func (c *HDLConfig) OnEvent(event any) {
|
|||||||
if c.PullOnSubscribe {
|
if c.PullOnSubscribe {
|
||||||
for streamPath, url := range c.PullList {
|
for streamPath, url := range c.PullList {
|
||||||
if streamPath == v.Path {
|
if streamPath == v.Path {
|
||||||
if err := plugin.Pull(streamPath, url, new(HDLPuller), false); err != nil {
|
if err := HDLPlugin.Pull(streamPath, url, new(HDLPuller), false); err != nil {
|
||||||
plugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err))
|
HDLPlugin.Error("pull", zap.String("streamPath", streamPath), zap.String("url", url), zap.Error(err))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -48,9 +48,11 @@ func (c *HDLConfig) OnEvent(event any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *HDLConfig) API_Pull(rw http.ResponseWriter, r *http.Request) {
|
func (c *HDLConfig) API_Pull(rw http.ResponseWriter, r *http.Request) {
|
||||||
err := plugin.Pull(r.URL.Query().Get("streamPath"), r.URL.Query().Get("target"), new(HDLPuller), r.URL.Query().Has("save"))
|
err := HDLPlugin.Pull(r.URL.Query().Get("streamPath"), r.URL.Query().Get("target"), new(HDLPuller), r.URL.Query().Has("save"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(rw, err.Error(), http.StatusBadRequest)
|
http.Error(rw, err.Error(), http.StatusBadRequest)
|
||||||
|
} else {
|
||||||
|
rw.Write([]byte("ok"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +62,7 @@ func (*HDLConfig) API_List(rw http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// 确保HDLConfig实现了PullPlugin接口
|
// 确保HDLConfig实现了PullPlugin接口
|
||||||
|
|
||||||
var plugin = InstallPlugin(new(HDLConfig))
|
var HDLPlugin = InstallPlugin(new(HDLConfig))
|
||||||
|
|
||||||
type HDLSubscriber struct {
|
type HDLSubscriber struct {
|
||||||
Subscriber
|
Subscriber
|
||||||
@@ -124,7 +126,7 @@ func (*HDLConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
sub.ID = r.RemoteAddr
|
sub.ID = r.RemoteAddr
|
||||||
sub.SetParentCtx(r.Context())
|
sub.SetParentCtx(r.Context())
|
||||||
sub.SetIO(w)
|
sub.SetIO(w)
|
||||||
if err := plugin.SubscribeBlock(streamPath, sub, SUBTYPE_FLV); err != nil {
|
if err := HDLPlugin.SubscribeBlock(streamPath, sub, SUBTYPE_FLV); err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
pull.go
2
pull.go
@@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (puller *HDLPuller) Connect() (err error) {
|
func (puller *HDLPuller) Connect() (err error) {
|
||||||
plugin.Info("connect", zap.String("remoteURL", puller.RemoteURL))
|
HDLPlugin.Info("connect", zap.String("remoteURL", puller.RemoteURL))
|
||||||
if strings.HasPrefix(puller.RemoteURL, "http") {
|
if strings.HasPrefix(puller.RemoteURL, "http") {
|
||||||
var res *http.Response
|
var res *http.Response
|
||||||
if res, err = http.Get(puller.RemoteURL); err == nil {
|
if res, err = http.Get(puller.RemoteURL); err == nil {
|
||||||
|
Reference in New Issue
Block a user