🐛 FIX: 调通

This commit is contained in:
dexter
2022-10-03 16:19:49 +08:00
parent 3ab5e3b868
commit f9ef840213
2 changed files with 45 additions and 14 deletions

View File

@@ -1,2 +1,31 @@
# plugin-edge
边缘服务器插件——使得m7s实例可作为边缘服务器
## 插件地址
https://github.com/Monibuca/plugin-edge
## 插件引入
```go
import (
_ "m7s.live/plugin/edge/v4"
)
```
## 配置
```yaml
edge:
origin: "http://localhost:8080/hdl/"
```
origin代表源服务器拉流地址前缀可以由如下几种格式
- http://[host]:[port]/hdl/ 使用hdl协议拉流
- rtmp://[host]:[port]/ 使用rtmp协议拉流
- rtsp://[host]:[port]/ 使用rtsp协议拉流
## 使用
当配置了edge后该实例即可成为边缘服务器即当收到一个订阅者时将自动向源服务器发送拉流请求从而实现级联的效果。

30
main.go
View File

@@ -9,27 +9,29 @@ import (
"m7s.live/plugin/rtsp/v4"
)
type EdgePlugin struct {
type EdgeConfig struct {
Origin string //源服务器地址
config.Pull
puller IPuller
}
func (p *EdgePlugin) OnEvent(event any) {
func (p *EdgeConfig) OnEvent(event any) {
switch v := event.(type) {
case FirstConfig:
if len(p.Origin) < 4 {
plugin.Panic("origin config error")
}
switch p.Origin[:4] {
case "http":
p.puller = new(hdl.HDLPuller)
case "rtmp":
p.puller = new(rtmp.RTMPPuller)
case "rtsp":
p.puller = new(rtsp.RTSPPuller)
default:
plugin.Panic("origin config not support")
plugin.Warn("origin config error plugin disabled")
plugin.RawConfig["enabled"] = false
} else {
switch p.Origin[:4] {
case "http":
p.puller = new(hdl.HDLPuller)
case "rtmp":
p.puller = new(rtmp.RTMPPuller)
case "rtsp":
p.puller = new(rtsp.RTSPPuller)
default:
plugin.Panic("origin config not support")
}
}
case *Stream:
err := plugin.Pull(v.Path, p.Origin+v.Path, p.puller, false)
@@ -39,4 +41,4 @@ func (p *EdgePlugin) OnEvent(event any) {
}
}
var plugin = InstallPlugin(new(EdgePlugin))
var plugin = InstallPlugin(new(EdgeConfig))