mirror of
https://github.com/kerberos-io/onvif.git
synced 2026-08-23 15:08:33 +00:00
Adds a background renew loop alongside the pull loop. ONVIF pull-point subscriptions expire at the InitialTerminationTime supplied to Create; without periodic Renew calls the camera silently drops the subscription and subsequent pulls start returning empty messages — the shape the existing agent's heartbeat code in cloud/Cloud.go has been papering over by occasionally recreating subscriptions. Design ------ * New Options.RenewMargin (default 10s) — how far before InitialTermination expiry the renew fires. Smaller margins mean fewer SOAP round-trips; larger margins tolerate slow networks. With default 60s termination + 10s margin we renew every 50s, which is in line with what production NVRs (Milestone, Genetec) use. * The renew loop runs in a separate goroutine sharing ctx with the pull loop. WaitGroup synchronisation in run() ensures both have exited before close()-of-channels happens, so a renew in flight during Close() cannot send on a closed Errors channel. * Pathological config (RenewMargin >= InitialTermination) falls back to renewing at termination/2 rather than busy-looping or never renewing. * renewPullPoint sends a wsnt:Renew SOAP against the SubscriptionRef Address with the same InitialTermination duration; renew errors surface on Errors non-blockingly, identically to pull errors. Tests use very short termination/margin (80-100ms / 10ms) so a single test run observes multiple renews within ~500ms, and assert that renew calls target the SubscriptionReference endpoint (not the device endpoint). -race clean.