Commit ec253029 authored by Alain Takoudjou's avatar Alain Takoudjou

erp5_web_mynij_search: fix webtorrent client creation and progressbar during torrent download

parent ddb879ce
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<div class="torrentBoddy {{#if is_seed}}is-seed{{/if}}" id="{{infohash}}"> <div class="torrentBoddy {{#if is_seed}}is-seed{{/if}}" id="{{infohash}}">
<div class="hero"> <div class="hero">
<div class="output"> <div class="output">
<div class="progressBar"></div> <div class="progressBar" {{#if is_seed}}style="width: 100%"{{/if}}></div>
</div> </div>
<div class="status"> <div class="status">
<div> <div>
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>989.27292.54989.38297</string> </value> <value> <string>989.27299.4752.580</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -264,7 +264,7 @@ ...@@ -264,7 +264,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1610966584.34</float> <float>1611306465.06</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -37,19 +37,22 @@ ...@@ -37,19 +37,22 @@
remaining_html = element.querySelector(".remaining"), remaining_html = element.querySelector(".remaining"),
remaining, remaining,
downloadSpeed = element.querySelector(".downloadSpeed"), downloadSpeed = element.querySelector(".downloadSpeed"),
uploadSpeed = element.querySelector(".uploadSpeed"); uploadSpeed = element.querySelector(".uploadSpeed"),
percent;
// Peers // Peers
num_peers.innerHTML = torrent.numPeers + num_peers.innerHTML = torrent.numPeers +
(torrent.numPeers === 1 ? ' peer' : ' peers'); (torrent.numPeers === 1 ? ' peer' : ' peers');
// Progress
var percent = Math.round(torrent.progress * 100 * 100) / 100;
progressBar.style.width = percent + '%';
total.innerHTML = prettyBytes(torrent.length); total.innerHTML = prettyBytes(torrent.length);
if (!downloaded) { if (!downloaded) {
uploadSpeed.innerHTML = prettyBytes(torrent.uploadSpeed) + '/s'; uploadSpeed.innerHTML = prettyBytes(torrent.uploadSpeed) + '/s';
progressBar.style.width = '100%';
return; return;
} }
// Download progress
percent = Math.round(torrent.progress * 100 * 100) / 100;
progressBar.style.width = percent + '%';
downloaded.innerHTML = prettyBytes(torrent.downloaded); downloaded.innerHTML = prettyBytes(torrent.downloaded);
// Remaining time // Remaining time
...@@ -74,6 +77,23 @@ ...@@ -74,6 +77,23 @@
return element; return element;
} }
function createWebTorrent() {
return new WebTorrent({
tracker: {
rtcConfig: {
// XXX - set configurable stun address
iceServers: [
{urls: [
"stun:turn.api.nexedi.net:3478",
"stun:stun.l.google.com:19302",
"stun:global.stun.twilio.com:3478"
]}
]
}
}
});
}
gadget_klass gadget_klass
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
...@@ -470,12 +490,9 @@ ...@@ -470,12 +490,9 @@
status: "success" status: "success"
}) })
.push(function () { .push(function () {
var id; return gadget.state.model_gadget.updateIndexDoc(
for (id in torrent_dict) { id,
if (torrent_dict[id] === torrent.name) { {magnet_uri: torrent.magnetURI});
return gadget.jio_get(id);
}
}
}); });
}; };
...@@ -560,7 +577,7 @@ ...@@ -560,7 +577,7 @@
}); });
} }
gadget.state.client = new WebTorrent(); gadget.state.client = createWebTorrent();
return seedTorrent(); return seedTorrent();
}) })
...@@ -572,7 +589,7 @@ ...@@ -572,7 +589,7 @@
if (!torrent_id) { if (!torrent_id) {
return; return;
} }
gadget.state.client = new WebTorrent(); gadget.state.client = createWebTorrent();
gadget.state.redirect = redirect; gadget.state.redirect = redirect;
container.classList.remove('hidden'); container.classList.remove('hidden');
return gadget.notifySubmitting() return gadget.notifySubmitting()
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>989.30650.55487.8328</string> </value> <value> <string>989.32134.13599.6348</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1611221391.77</float> <float>1611306236.6</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment