diff options
author | metamuffin <metamuffin@disroot.org> | 2022-10-27 08:58:31 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-10-27 08:58:31 +0200 |
commit | 530058d12121816073f1cd2a205e4c93d52084d8 (patch) | |
tree | 88ff328d9377e3e6052fe47744f0a1ec9ea541a4 /client-web/source/sw | |
parent | 058ffca5dde30f5dfa594b3eae3c431fb19489d8 (diff) | |
download | keks-meet-530058d12121816073f1cd2a205e4c93d52084d8.tar keks-meet-530058d12121816073f1cd2a205e4c93d52084d8.tar.bz2 keks-meet-530058d12121816073f1cd2a205e4c93d52084d8.tar.zst |
handle request cancellation
Diffstat (limited to 'client-web/source/sw')
-rw-r--r-- | client-web/source/sw/download_stream.ts | 14 | ||||
-rw-r--r-- | client-web/source/sw/worker.ts | 17 |
2 files changed, 18 insertions, 13 deletions
diff --git a/client-web/source/sw/download_stream.ts b/client-web/source/sw/download_stream.ts index 1a2fec8..0ba6289 100644 --- a/client-web/source/sw/download_stream.ts +++ b/client-web/source/sw/download_stream.ts @@ -26,7 +26,12 @@ function FallbackStreamDownload(size: number, filename?: string, progress?: (pos } } -export function StreamDownload(size: number, filename?: string, progress?: (position: number) => void) { +export function StreamDownload({ size, filename, cancel, progress }: { + size: number, + filename: string, + cancel: () => void, + progress: (position: number) => void +}) { if (!SW) FallbackStreamDownload(size, filename, progress) let position = 0 @@ -41,6 +46,13 @@ export function StreamDownload(size: number, filename?: string, progress?: (posi a.target = "_blank" a.click() + port1.onmessage = ev => { + if (ev.data.abort) { + cancel() + port1.close() + } + } + return { close() { port1.postMessage("end") diff --git a/client-web/source/sw/worker.ts b/client-web/source/sw/worker.ts index 5c185f3..327aba0 100644 --- a/client-web/source/sw/worker.ts +++ b/client-web/source/sw/worker.ts @@ -12,8 +12,6 @@ declare const self: ServiceWorkerGlobalScope; export { }; console.log("hello from the keks-meet service worker"); console.log(self.origin) -// let cache: Cache; - self.addEventListener("install", event => { console.log("install"); self.skipWaiting() @@ -22,13 +20,6 @@ self.addEventListener("install", event => { self.addEventListener("activate", _event => { console.log("activate"); self.clients.claim() - // event.waitUntil((async () => { - // cache = await caches.open("v1") - // cache.addAll([ - // "/assets/bundle.js", - // "/assets/sw.js", - // ]) - // })()) }) self.addEventListener("unload", () => { console.log("unload") @@ -72,14 +63,16 @@ self.addEventListener("fetch", event => { stream.readable, { headers: new Headers({ - "Content-Type": "application/octet-stream; charset=utf-8", // TODO transmit and set accordingly - "Content-Security-Policy": "default-src 'none'", - "Content-Length": `${stream.size}`, + "content-type": "application/octet-stream; charset=utf-8", // TODO transmit and set accordingly + "content-security-policy": "default-src 'none'", + "content-length": `${stream.size}`, }) } ) ) } + if (path == "/swtest") return event.respondWith(new Response("works!", { headers: new Headers({ "content-type": "text/plain" }) })) + event.respondWith(fetch(request)) }) |