Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/webtorrent/webtorrent.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChocobozzz <florian.chocobo@gmail.com>2018-09-21 11:56:46 +0300
committerGitHub <noreply@github.com>2018-09-21 11:56:46 +0300
commit7e0d447c3e8cc0c4739fa3c06e13de331da6bc2b (patch)
tree893d13075d15a2256597710b6c285c8517a0e359 /lib
parent0f0b10ee99ffec7fc1fa9db2a9b25c1fb8907ec1 (diff)
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).
Diffstat (limited to 'lib')
-rw-r--r--lib/torrent.js6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/torrent.js b/lib/torrent.js
index 0213f3b..4ceca06 100644
--- a/lib/torrent.js
+++ b/lib/torrent.js
@@ -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))