Skip to content
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

Try to reduce dl impact on slow computers (web) #1513

Merged
merged 2 commits into from Sep 28, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Try to reduce dl impact on slow computers (web)

On slow computers with a fast network, web browsers may no longer respond because webtorrent is downloading chunks too fast.

The main issue is that you cannot stream a torrent video: the web browser does not have time to play the video, it is too busy downloading the video chunks.

On web browser supporting [requestIdleCallback](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback#See_also), we download chunks with a lower priority allowing the web browser to execute other tasks (like playing the video).
  • Loading branch information
Chocobozzz committed Sep 21, 2018
commit 7e0d447c3e8cc0c4739fa3c06e13de331da6bc2b
@@ -1156,7 +1156,11 @@ class Torrent extends EventEmitter {
if (wire.requests.length >= minOutstandingRequests) return
const maxOutstandingRequests = getBlockPipelineLength(wire, PIPELINE_MAX_DURATION)

trySelectWire(false) || trySelectWire(true)
if (typeof window !== 'undefined' && typeof window.requestIdleCallback === 'function') {
window.requestIdleCallback(function () { trySelectWire(false) || trySelectWire(true) })
} else {
trySelectWire(false) || trySelectWire(true)
}

function genPieceFilterFunc (start, end, tried, rank) {
return i => i >= start && i <= end && !(i in tried) && wire.peerPieces.get(i) && (!rank || rank(i))
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.