refactor: isolate Canvas, Webcam and ML logic from DoubleCalibrationR…#116
Open
Sidhant185 wants to merge 1 commit intoruxailab:mainfrom
Open
refactor: isolate Canvas, Webcam and ML logic from DoubleCalibrationR…#116Sidhant185 wants to merge 1 commit intoruxailab:mainfrom
Sidhant185 wants to merge 1 commit intoruxailab:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
♻️ Refactor: Decouple UI and ML Pipeline in
DoubleCalibrationRecord.vue📋 Summary
This PR breaks apart a monolithic 1,262-line Vue component into four clean, single-responsibility modules. It extracts Canvas rendering, Webcam stream lifecycle management, and TensorFlow.js inference into dedicated components and a plain JavaScript service class — leaving
DoubleCalibrationRecord.vueas a thin orchestrator with no direct DOM or ML dependencies.🎯 Problem Statement
DoubleCalibrationRecord.vuehad grown into a God Component — a single file responsible for too many concerns simultaneously:<v-stepper>transitionsnavigator.mediaDevices.getUserMedia, managing hidden<video>elements, and handlingMediaRecorderstatectx.fillRect/ctx.arccalls, coordinate interpolation, and animation frame logicmodel.estimateFaceson the main thread, parsing annotation arrays, running blink-detection heuristics inlineImpact of the monolith
@vue/test-utils.TypeErrorswhen a user moved out of frame too quickly.🛠️ Solution
The monolith was split into three new modules and a refactored orchestrator:
1.
src/components/calibration/CalibrationCanvas.vue(New Component)Encapsulates all
<canvas>drawing logic.drawPoint(x, y, options)andtriggerAnimation()as a clean component API.CanvasRenderingContext2D.2.
src/components/calibration/WebcamManager.vue(New Component)An invisible service component managing the video stream lifecycle.
<video autoplay playsinline>element internally.navigator.mediaDevicestracks onbeforeUnmount, preventing the camera indicator light from hanging after navigation.MediaRecorderstate and emits@stream-ready/@stream-errorevents for the parent to react to declaratively.3.
src/services/ml/FaceDetector.js(New Service Class)A plain JavaScript class abstracting the
@tensorflow-models/face-landmarks-detectiondependency.estimateFacesprediction loop.#processPrediction()(private method) with explicit safety bounds guarding against empty annotation arrays — the root cause of previousTypeErrorcrashes.4.
DoubleCalibrationRecord.vue→ Orchestrator (Refactored)Stripped of all raw DOM manipulation, Canvas operations, and ML calls.
CalibrationCanvas,WebcamManager, andFaceDetectorvia Vue refs and events.📐 Architecture: Before vs. After
📈 Metrics
DoubleCalibrationRecord.vueline countTypeErrorcrashes✅ Testing
FaceDetector.js: Unit tests can now be run in isolation — seetests/unit/services/ml/FaceDetector.spec.js.TypeErrorthrown.🔍 Files Changed
src/views/DoubleCalibrationRecord.vuesrc/components/calibration/CalibrationCanvas.vuesrc/components/calibration/WebcamManager.vuesrc/services/ml/FaceDetector.jstests/unit/services/ml/FaceDetector.spec.js💬 Notes for Reviewer
FaceDetector.jsuses a private class field (#processPrediction) requiring Node ≥ 12 / modern bundler. Please flag if the project targets an environment where this is a concern.WebcamManagercomponent is designed to be reused by future recording views — it is not tightly coupled to the calibration flow.Part of the GSoC Codebase Improvement Initiative. Happy to discuss design decisions in review.