Skip to content

Commit b7f3d2f

Browse files
committed
Manage WebSocket reference in screenshot editor context
1 parent e51e3ff commit b7f3d2f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

apps/desktop/src/routes/screenshot-editor/context.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ function createScreenshotEditorContext() {
134134
});
135135

136136
const [latestFrame, setLatestFrame] = createLazySignal<FrameData>();
137+
const [wsRef, setWsRef] = createSignal<WebSocket | null>(null);
137138

138139
const [editorInstance] = createResource(async () => {
139140
const instance = await commands.createScreenshotEditorInstance();
@@ -176,6 +177,7 @@ function createScreenshotEditorContext() {
176177

177178
const ws = new WebSocket(instance.framesSocketUrl);
178179
ws.binaryType = "arraybuffer";
180+
setWsRef(ws);
179181
ws.onmessage = async (event) => {
180182
const buffer = event.data as ArrayBuffer;
181183
if (buffer.byteLength < 24) return;
@@ -239,6 +241,10 @@ function createScreenshotEditorContext() {
239241
if (frame?.bitmap) {
240242
frame.bitmap.close();
241243
}
244+
const ws = wsRef();
245+
if (ws) {
246+
ws.close();
247+
}
242248
});
243249

244250
const saveConfig = debounce((config: ProjectConfiguration) => {

0 commit comments

Comments
 (0)