droboticflow/internal/api/client_movi_stats.go
d-robotics 54e47906c1 🎬 movi-player D-layer: vendor 0.4.1 slim dist, MoviVideo wrapper on E′ direct pipeline, telemetry endpoint, spikes pass
- vendor public/vendor/movi-player-0.4.1/ (element.slim.js 4.9MB + movi.wasm 5.4MB,
  Apache-2.0, SHA-256 pinned, upgrade = new versioned dir + MOVI_VERSION bump)
- src/lib/movi-player.ts: lazy loader (@vite-ignore dynamic import), runtime
  force flag (movi default / native fleet kill-switch / wasm canary), throttled
  best-effort telemetry reporter
- src/components/MoviVideo.tsx: engine="native wasm" + nohotkeys, HTMLMediaElement
  event bridge, #t= fragment split (startat + wrapper-managed end bound),
  in-place custom-element upgrade preserving node identity, wasmurl before connect
- mount points: LazyVideoPreview (evidence/artifact/object-storage previews),
  MaterializedSliceWorkbench dual-camera, CaptureAnnotationWorkbench main videos
  (moviElementReady gate: transport seek queue needs the element on first render;
  falls back to native E′ path until defined), page-level preload on
  AnnotationOperations
- POST /api/client/movi-stats: session-attributed, field-truncated, store errors
  swallowed (202); Mongo clientMoviStats collection w/ 14d TTL + org/kind indexes
- spikes (CDP, headless Edge 155, production hev1 480p30 sample): key conflicts
  PASS (17 keys all reach container dispatcher, zero playback-state interference,
  nohotkeys effective); frame-seek parity PASS (movi deltas identical to native
  <video>, ±1/30s steps both directions); deep probe: engine=native-wasm hands
  playback to shadow <video> with zero WASM fetches on HW-decode clients
- verification: tsc clean, gofmt/build/vet pass, frontend 644 tests net-zero new
  failures vs E′ baseline (6 new pass), Go API suite net-zero new failures
  (75 pre-existing; the one delta traced to a colleague's uncommitted part-index
  working-tree change), replica E2E: vendor assets served, module registers,
  telemetry lands in Mongo with TTL
2026-10-11 20:06:22 +05:30

63 lines
2.1 KiB
Go

package api
import (
"net/http"
"strings"
"droboticflow/internal/domain"
)
// POST /api/client/movi-stats — browser-player telemetry for the post-release
// fleet survey (which decoding layer carries playback, fallbacks, failures).
//
// Client fire-and-forget: failures return 202 with no body so the browser
// never retries a dropped report, and a failed insert must never surface to
// the user. Authenticated session users only; the org/user identity comes
// from the session, never the payload.
func (server *server) handleClientMoviStats(w http.ResponseWriter, r *http.Request) {
principal, ok := currentPrincipal(r)
if !ok || principal == nil {
renderJSON(w, http.StatusUnauthorized, map[string]string{"error": "authentication required"})
return
}
var payload domain.ClientMoviStatRecord
if !decodeJSON(w, r, &payload) {
return
}
record := domain.ClientMoviStatRecord{
OrganizationID: principal.User.OrganizationID,
UserID: principal.User.ID,
Kind: truncateString(payload.Kind, 64),
Decoder: truncateString(payload.Decoder, 64),
Engine: truncateString(payload.Engine, 64),
Src: truncateString(payload.Src, 256),
StartupMs: payload.StartupMs,
DroppedFrames: payload.DroppedFrames,
RebufferRatio: payload.RebufferRatio,
Message: truncateString(payload.Message, 300),
Fatal: payload.Fatal,
Smooth: payload.Smooth,
UserAgent: truncateString(r.UserAgent(), 256),
}
if record.Kind == "" {
// No kind means nothing meaningful to survey; accept silently.
renderJSON(w, http.StatusAccepted, map[string]bool{"ok": true})
return
}
if err := server.store.InsertClientMoviStat(r.Context(), record); err != nil {
// Best-effort telemetry: swallow the error, still 202 so the client
// does not retry or log noise for a survey write.
renderJSON(w, http.StatusAccepted, map[string]bool{"ok": true})
return
}
renderJSON(w, http.StatusAccepted, map[string]bool{"ok": true})
}
func truncateString(input string, maxLength int) string {
value := strings.TrimSpace(input)
if len(value) <= maxLength {
return value
}
return value[:maxLength]
}