forked from langhuihui/monibuca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpusher.go
62 lines (52 loc) · 1.38 KB
/
pusher.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package m7s
import (
"net/http"
"m7s.live/v5/pkg"
"m7s.live/v5/pkg/task"
"m7s.live/v5/pkg/config"
)
type IPusher interface {
task.ITask
GetPushJob() *PushJob
}
type Pusher = func() IPusher
type PushJob struct {
Connection
Subscriber *Subscriber
SubConf config.Subscribe
pusher IPusher
}
func (p *PushJob) GetKey() string {
return p.Connection.RemoteURL
}
func (p *PushJob) Init(pusher IPusher, plugin *Plugin, streamPath string, conf config.Push, subConf *config.Subscribe) *PushJob {
p.Connection.Init(plugin, streamPath, conf.URL, conf.Proxy, http.Header(conf.Header))
p.pusher = pusher
if subConf == nil {
p.SubConf = plugin.config.Subscribe
} else {
p.SubConf = *subConf
}
p.SubConf.SubType = SubscribeTypePush
p.SetDescriptions(task.Description{
"plugin": plugin.Meta.Name,
"streamPath": streamPath,
"url": conf.URL,
"maxRetry": conf.MaxRetry,
})
pusher.SetRetry(conf.MaxRetry, conf.RetryInterval)
plugin.Server.Pushs.Add(p, plugin.Logger.With("pushURL", conf.URL, "streamPath", streamPath))
return p
}
func (p *PushJob) Subscribe() (err error) {
p.Subscriber, err = p.Plugin.SubscribeWithConfig(p.pusher.GetTask().Context, p.StreamPath, p.SubConf)
return
}
func (p *PushJob) Start() (err error) {
s := p.Plugin.Server
if _, ok := s.Pushs.Get(p.GetKey()); ok {
return pkg.ErrPushRemoteURLExist
}
p.AddTask(p.pusher, p.Logger)
return
}