Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Manage WebSocket lifecycle in screenshot editor context

Richie McIlroy89fb7b188dbd
diff --git a/apps/desktop/src/routes/screenshot-editor/context.tsx b/apps/desktop/src/routes/screenshot-editor/context.tsx
index 8aab545ef..480e888fd 100644
--- a/apps/desktop/src/routes/screenshot-editor/context.tsx
+++ b/apps/desktop/src/routes/screenshot-editor/context.tsx
@@ -135,6 +135,7 @@ function createScreenshotEditorContext() {
const [latestFrame, setLatestFrame] = createLazySignal<FrameData>();
const [isRenderReady, setIsRenderReady] = createSignal(false);
+ let wsRef: WebSocket | null = null;
const [editorInstance] = createResource(async () => {
const instance = await commands.createScreenshotEditorInstance();
@@ -171,6 +172,7 @@ function createScreenshotEditorContext() {
height: img.naturalHeight,
bitmap,
});
+ setIsRenderReady(true);
} catch (e: unknown) {
console.error("Failed to create ImageBitmap from fallback image:", e);
}
@@ -185,6 +187,7 @@ function createScreenshotEditorContext() {
}
const ws = new WebSocket(instance.framesSocketUrl);
+ wsRef = ws;
ws.binaryType = "arraybuffer";
ws.onmessage = async (event) => {
const buffer = event.data as ArrayBuffer;
@@ -252,6 +255,10 @@ function createScreenshotEditorContext() {
if (frame?.bitmap) {
frame.bitmap.close();
}
+ if (wsRef) {
+ wsRef.close();
+ wsRef = null;
+ }
});
const saveConfig = debounce((config: ProjectConfiguration) => {