MCPcopy Index your code
hub / github.com/Monibuca/engine / Pull

Method Pull

plugin.go:268–321  ·  view source on GitHub ↗
(streamPath string, url string, puller IPuller, save int)

Source from the content-addressed store, hash-verified

266var Pullers sync.Map
267
268func (opt *Plugin) Pull(streamPath string, url string, puller IPuller, save int) (err error) {
269 conf, ok := opt.Config.(config.PullConfig)
270 if !ok {
271 return ErrNoPullConfig
272 }
273 pullConf := conf.GetPullConfig()
274 if save < 2 {
275 zurl := zap.String("url", url)
276 zpath := zap.String("stream", streamPath)
277 opt.Info("pull", zpath, zurl)
278 puller.init(streamPath, url, pullConf)
279 opt.AssignPubConfig(puller.GetPublisher())
280 puller.SetLogger(opt.Logger.With(zpath, zurl))
281 go puller.startPull(puller)
282 }
283 switch save {
284 case 1:
285 pullConf.PullOnStartLocker.Lock()
286 defer pullConf.PullOnStartLocker.Unlock()
287 m := map[string]string{streamPath: url}
288 for id := range pullConf.PullOnStart {
289 m[id] = pullConf.PullOnStart[id]
290 }
291 m[streamPath] = url
292 opt.RawConfig.ParseModifyFile(map[string]any{
293 "pull": map[string]any{
294 "pullonstart": m,
295 },
296 })
297 case 2:
298 pullConf.PullOnSubLocker.Lock()
299 defer pullConf.PullOnSubLocker.Unlock()
300 m := map[string]string{streamPath: url}
301 for id := range pullConf.PullOnSub {
302 m[id] = pullConf.PullOnSub[id]
303 }
304 m[streamPath] = url
305 if pullConf.PullOnSub == nil {
306 pullConf.PullOnSub = make(map[string]string)
307 }
308 pullConf.PullOnSub[streamPath] = url
309 opt.RawConfig.ParseModifyFile(map[string]any{
310 "pull": map[string]any{
311 "pullonsub": m,
312 },
313 })
314 }
315 if save > 0 {
316 if err = opt.Save(); err != nil {
317 opt.Error("save faild", zap.Error(err))
318 }
319 }
320 return
321}
322
323var ErrNoPushConfig = errors.New("no push config")
324var Pushers sync.Map

Callers

nothing calls this directly

Calls 14

AssignPubConfigMethod · 0.95
SaveMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80
ParseModifyFileMethod · 0.80
GetPullConfigMethod · 0.65
InfoMethod · 0.65
initMethod · 0.65
GetPublisherMethod · 0.65
SetLoggerMethod · 0.65
WithMethod · 0.65
startPullMethod · 0.65

Tested by

no test coverage detected