-
-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send user-initiated cancel event from service worker back to streamsaver #105
Conversation
@@ -201,6 +203,9 @@ | |||
} | |||
|
|||
channel.port1.onmessage = evt => { | |||
// Track whether readable stream was cancelled by user | |||
streamSaver.isUserAborted = !!evt.data.userAborted; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not set a global flag for all streams.
It should abort/close the writable stream
I'm not going to accept this pr unless that is changed
@@ -24,7 +25,8 @@ | |||
WritableStream: window.WritableStream || ponyfill.WritableStream, | |||
supported: true, | |||
version: { full: '2.0.0', major: 2, minor: 0, dot: 0 }, | |||
mitm: 'https://jimmywarting.github.io/StreamSaver.js/mitm.html?version=2.0.0' | |||
mitm: 'https://jimmywarting.github.io/StreamSaver.js/mitm.html?version=2.0.0', | |||
isUserAborted, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove (revert)
@@ -38,6 +38,7 @@ self.onmessage = event => { | |||
metadata[0] = evt.data.readableStream | |||
} | |||
} else { | |||
port.postMessage({ userAborted: false }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably would have called it just abort, cancel, aborted or cancelled. The stream can abort without user interaction like having a timed AbortController
Thanks for the feedback! Will make the changes as soon as possible. |
This solved a missing piece for me, which is to stop the writeable stream if the readable stream is cancelled by the user, by dismissing the download dialog (in FF for example).
Here's how I use it: