Cache waveform peaks and use direct URLs for faster replay loads#1223
Cache waveform peaks and use direct URLs for faster replay loads#1223hilsonshrestha wants to merge 8 commits into
Conversation
|
A preview of 1cb2444 is uploaded and can be seen here: ✨ https://revisit.dev/study/PR1223 ✨ Changes may take a few minutes to propagate. |
There was a problem hiding this comment.
Pull request overview
Improves replay performance by avoiding repeated full audio decode for waveform rendering and by switching replay media loading from full-blob fetches to direct URLs so the browser can stream/buffer.
Changes:
- Added support for caching/loading WaveSurfer waveform peaks via the storage engine.
- Updated replay components to use direct screen recording URLs instead of blob/object URLs.
- Updated audio provenance visualization to load cached peaks when available and persist peaks after first load.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/storage/engines/types.ts | Adds WaveformPeaks type + storage helpers for saving/loading cached peaks; adds screen recording URL getter. |
| src/components/screenRecording/ScreenRecordingReplay.tsx | Switches screen recording replay source to direct URL loading. |
| src/components/audioAnalysis/AudioProvenanceVis.tsx | Adds waveform peak caching logic and switches to direct media URLs for faster load. |
| src/analysis/individualStudy/thinkAloud/ThinkAloudFooter.tsx | Switches think-aloud footer screen recording load to direct URL. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async getWaveformPeaks(taskName: string, participantId: string): Promise<WaveformPeaks | null> { | ||
| const result = await this._getFromStorage(`audio/${participantId}_${taskName}`, 'waveform.peaks.json'); | ||
| if (!result || !('peaks' in result)) return null; | ||
| return result as WaveformPeaks; |
JackWilb
left a comment
There was a problem hiding this comment.
Two blocking issues need to be addressed before merge. CI also needs to be fixed: the committed ScreenRecordingReplay unit tests still mock the old storage method, causing the Vitest workflow to fail with one failed assertion and unhandled rejections.
| } | ||
|
|
||
| const fileName = path.basename(filePath); | ||
| const tmpInput = path.join(os.tmpdir(), fileName); |
There was a problem hiding this comment.
[P1] Second-generation functions can process events concurrently, but these temp paths use only the object basename. Identically named participant/task recordings from different studies can overwrite each other and corrupt the converted upload. Please create a unique temp directory per event (for example with fs.mkdtemp) or include a full-path hash/event ID in both paths, then clean it up in finally.
| throw new Error('Participant ID is required to load audio'); | ||
| } | ||
| const url = await storageEngine.getScreenRecording(identifier, participantId); | ||
| const url = await storageEngine.getScreenRecordingUrl(identifier, participantId); |
There was a problem hiding this comment.
[P1] This method was renamed to getScreenRecordingUrl, but the sibling spec still mocks getScreenRecording. The focused Vitest run fails and emits unhandled rejections because the new method is missing. Please update the null, success, and video-src test mocks to expose getScreenRecordingUrl; CI needs to pass before merge.
Does this PR close any open issues?
Closes #1174
Give a longer description of what this PR addresses and why it's needed
Audio and screen recording replays were slow because WaveSurfer had to fully decode audio on every load to render the waveform. This PR caches decoded waveform peaks to storage after the first load so subsequent visits skip decoding. It also replaces entire blob fetches of audio and video with direct URL calls so that the media player can buffer stream.
PR also shows a warning when participant used a browser different.
PR adds a Firebase Cloud Function that runs ffmpeg on uploaded screen recordings to re-encode them as webm using a stream copy (no re-encoding when the source is already webm-compatible).
Provide pictures/videos of the behavior before and after these changes (optional)
Are there any additional TODOs before this PR is ready to go?
x