-
Notifications
You must be signed in to change notification settings - Fork 105
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
Stop downloading the torrent file when I stop streaming the file #178
Comments
File stopping is implemented: torrent-stream-server/src/api/stream.ts Lines 78 to 80 in 8adae33
But I also noticed that it doesn't work in some cases. I will need to find a better solution for this. |
Added fix for frontend player, now it's destroyed when react component is destoyed. However, file stopping is buggy webtorrent/webtorrent#164. There is a pending PR that could fix it (webtorrent/webtorrent#2115) or I need to find a workaround. |
The issue you're describing is that the download does not stop when the user stops streaming. This is likely due to the fact that the pump function continues to stream data even after the user has stopped requesting it. The pump function does not inherently handle the cancellation of streams when the client disconnects. To address this, you can use the res.on('close', ...) event to detect when the client has disconnected and then stop the streaming process. Here's how you can modify your code to handle this:
Explanation: stream.destroy(): This method is used to destroy the stream, which will stop any further data from being sent. file.stop(): This method is used to stop the file from being read further. By adding these lines, the streaming process will be properly stopped when the client disconnects, preventing unnecessary resource consumption. |
When i stop downloading the file, the torrent may stop downloading and be removed. I see that it is not the correct file and I will download another one, but the old one keeps downloading.
The text was updated successfully, but these errors were encountered: