diff --git a/main.go b/main.go index e980a4e..308e471 100755 --- a/main.go +++ b/main.go @@ -146,7 +146,7 @@ func Run(ctx context.Context, conf any) (err error) { plugin.assign() } UUID := uuid.NewString() - reportTimer := time.NewTicker(time.Minute) + contentBuf := bytes.NewBuffer(nil) req, _ := http.NewRequestWithContext(ctx, http.MethodPost, "https://console.monibuca.com/report", nil) req.Header.Set("Content-Type", "application/json") @@ -212,8 +212,19 @@ func Run(ctx context.Context, conf any) (err error) { if EngineConfig.Secret != "" { EngineConfig.OnEvent(ctx) } - var c http.Client - c.Do(req) + go func() { + var c http.Client + reportTimer := time.NewTimer(time.Minute) + c.Do(req) + for { + <-reportTimer.C + contentBuf.Reset() + contentBuf.WriteString(fmt.Sprintf(`{"uuid":"`+UUID+`","streams":%d}`, Streams.Len())) + req.Body = io.NopCloser(contentBuf) + c.Do(req) + reportTimer.Reset(time.Minute) + } + }() for _, plugin := range enabledPlugins { plugin.Config.OnEvent(EngineConfig) //引擎初始化完成后,通知插件 } @@ -234,11 +245,6 @@ func Run(ctx context.Context, conf any) (err error) { } case <-ctx.Done(): return - case <-reportTimer.C: - contentBuf.Reset() - contentBuf.WriteString(fmt.Sprintf(`{"uuid":"`+UUID+`","streams":%d}`, Streams.Len())) - req.Body = io.NopCloser(contentBuf) - c.Do(req) } } }