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/resource | |
| 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/resource')
| -rw-r--r-- | client-web/source/resource/file.ts | 32 | 
1 files changed, 22 insertions, 10 deletions
| diff --git a/client-web/source/resource/file.ts b/client-web/source/resource/file.ts index 2b4c7fc..97da70b 100644 --- a/client-web/source/resource/file.ts +++ b/client-web/source/resource/file.ts @@ -31,15 +31,30 @@ export const resource_file: ResourceHandlerDecl = {              on_statechange(_s) { },              on_enable(channel, disable) {                  if (!(channel instanceof RTCDataChannel)) throw new Error("not a data channel"); -                const download = StreamDownload( -                    info.size!, info.label ?? "file", -                    position => { -                        display.status = `${display_filesize(position)} / ${display_filesize(info.size!)}` -                    } -                );                  const display = transfer_status_el()                  this.el.appendChild(display.el) +                const reset = () => { +                    download_button.disabled = false +                    download_button.textContent = "Download again" +                    this.el.removeChild(display.el) +                    disable() +                } + +                const download = StreamDownload( +                    { +                        size: info.size!, +                        filename: info.label ?? "file", +                        progress(position) { +                            display.status = `${display_filesize(position)} / ${display_filesize(info.size!)}` +                        }, +                        cancel() { +                            channel.close() +                            log({ scope: "*", warn: true }, "download stream aborted") +                            reset() +                        } +                    } +                );                  channel.onopen = _ev => {                      log("dc", `${user.display_name}: channel open`); @@ -49,11 +64,8 @@ export const resource_file: ResourceHandlerDecl = {                  }                  channel.onclose = _ev => {                      log("dc", `${user.display_name}: channel closed`); -                    this.el.removeChild(display.el)                      download.close() -                    download_button.disabled = false -                    download_button.textContent = "Download" -                    disable() +                    reset()                  }                  channel.onmessage = ev => {                      // console.log(ev.data); | 
