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 @@
<div class="torrentBoddy {{#if is_seed}}is-seed{{/if}}" id="{{infohash}}">
<div class="hero">
<div class="output">
<div class="progressBar"></div>
<div class="progressBar" {{#if is_seed}}style="width: 100%"{{/if}}></div>
</div>
<div class="status">
<div>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>989.27292.54989.38297</string> </value>
<value> <string>989.27299.4752.580</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1610966584.34</float>
<float>1611306465.06</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -37,19 +37,22 @@
remaining_html = element.querySelector(".remaining"),
remaining,
downloadSpeed = element.querySelector(".downloadSpeed"),
uploadSpeed = element.querySelector(".uploadSpeed");
uploadSpeed = element.querySelector(".uploadSpeed"),
percent;
// Peers
num_peers.innerHTML = torrent.numPeers +
(torrent.numPeers === 1 ? ' peer' : ' peers');
// Progress
var percent = Math.round(torrent.progress * 100 * 100) / 100;
progressBar.style.width = percent + '%';
total.innerHTML = prettyBytes(torrent.length);
if (!downloaded) {
uploadSpeed.innerHTML = prettyBytes(torrent.uploadSpeed) + '/s';
progressBar.style.width = '100%';
return;
}
// Download progress
percent = Math.round(torrent.progress * 100 * 100) / 100;
progressBar.style.width = percent + '%';
downloaded.innerHTML = prettyBytes(torrent.downloaded);
// Remaining time
......@@ -74,6 +77,23 @@
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
.declareAcquiredMethod("jio_get", "jio_get")
......@@ -470,12 +490,9 @@
status: "success"
})
.push(function () {
var id;
for (id in torrent_dict) {
if (torrent_dict[id] === torrent.name) {
return gadget.jio_get(id);
}
}
return gadget.state.model_gadget.updateIndexDoc(
id,
{magnet_uri: torrent.magnetURI});
});
};
......@@ -560,7 +577,7 @@
});
}
gadget.state.client = new WebTorrent();
gadget.state.client = createWebTorrent();
return seedTorrent();
})
......@@ -572,7 +589,7 @@
if (!torrent_id) {
return;
}
gadget.state.client = new WebTorrent();
gadget.state.client = createWebTorrent();
gadget.state.redirect = redirect;
container.classList.remove('hidden');
return gadget.notifySubmitting()
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>989.30650.55487.8328</string> </value>
<value> <string>989.32134.13599.6348</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1611221391.77</float>
<float>1611306236.6</float>
<string>UTC</string>
</tuple>
</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