From 2e4f91f668ea867d768291e9efd3e1c1eb825b97 Mon Sep 17 00:00:00 2001 From: Cas <6506529+ThaUnknown@users.noreply.github.com> Date: Thu, 23 Jun 2022 21:03:37 +0200 Subject: fix: support stream cancelling (#2335) --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'index.js') diff --git a/index.js b/index.js index e7b56a8..1476004 100644 --- a/index.js +++ b/index.js @@ -222,7 +222,11 @@ class WebTorrent extends EventEmitter { this.workerPortCount++ port.postMessage(response) }) - cb(this.serviceWorker) + // test if browser supports cancelling sw Readable Streams + fetch(`${this.serviceWorker.scriptURL.slice(0, this.serviceWorker.scriptURL.lastIndexOf('/') + 1).slice(window.location.origin.length)}webtorrent/cancel/`).then(res => { + res.body.cancel() + }) + cb(null, this.serviceWorker) } get downloadSpeed () { return this._downloadSpeed() } -- cgit v1.2.3