Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add getActiveCaptionText helper for VTTCues

Richie McIlroy185a0de46eb0
diff --git a/apps/web/app/s/[videoId]/_components/caption-cues.ts b/apps/web/app/s/[videoId]/_components/caption-cues.ts
new file mode 100644
index 000000000..c6dfb5663
--- /dev/null
+++ b/apps/web/app/s/[videoId]/_components/caption-cues.ts
@@ -0,0 +1,18 @@
+export function getActiveCaptionText(
+ activeCues: TextTrackCueList | null | undefined,
+): string {
+ if (!activeCues?.length) {
+ return "";
+ }
+
+ let selectedCue: VTTCue | null = null;
+
+ for (let index = 0; index < activeCues.length; index++) {
+ const cue = activeCues.item(index) as VTTCue | null;
+ if (cue && (!selectedCue || cue.startTime >= selectedCue.startTime)) {
+ selectedCue = cue;
+ }
+ }
+
+ return selectedCue?.text.replace(/<[^>]*>/g, "") ?? "";
+}