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/download_stream.ts | |
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/download_stream.ts')
-rw-r--r-- | client-web/source/sw/download_stream.ts | 14 |
1 files changed, 13 insertions, 1 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") |