Commit 50535538 authored by Alain Takoudjou's avatar Alain Takoudjou

erp5_web_mynij_search: Customize rtc configuration for webtorrent client.

RTC configuration can be saved in to file and will be downloaded by the app
parent dd63032d
...@@ -77,19 +77,10 @@ ...@@ -77,19 +77,10 @@
return element; return element;
} }
function createWebTorrent() { function createWebTorrent(rtcconfig) {
return new WebTorrent({ return new WebTorrent({
tracker: { tracker: {
rtcConfig: { rtcConfig: 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"
]}
]
}
} }
}); });
} }
...@@ -139,6 +130,36 @@ ...@@ -139,6 +130,36 @@
}); });
}) })
.declareMethod("getRtcconfig", function () {
var default_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"
]}
]
};
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
url : "mynij-config.json"
});
})
.push(undefined, function (error) {
//no rtcconfig file found, use the default
console.log(error);
return undefined;
})
.push(function (rconfig) {
var rtc_config;
if (!rconfig)
return default_rtcconfig;
return rconfig.rtcConfig;
});
})
.declareMethod("index_to_file", function (index_name) { .declareMethod("index_to_file", function (index_name) {
var gadget = this, var gadget = this,
index_id = "index-" + index_name; index_id = "index-" + index_name;
...@@ -577,8 +598,11 @@ ...@@ -577,8 +598,11 @@
}); });
} }
gadget.state.client = createWebTorrent(); return gadget.getRtcconfig()
return seedTorrent(); .push(function (config) {
gadget.state.client = createWebTorrent(config);
return seedTorrent();
});
}) })
.declareJob("download", function (torrent_id, redirect) { .declareJob("download", function (torrent_id, redirect) {
...@@ -589,10 +613,13 @@ ...@@ -589,10 +613,13 @@
if (!torrent_id) { if (!torrent_id) {
return; return;
} }
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.getRtcconfig()
.push(function (config) {
gadget.state.client = createWebTorrent(config);
return gadget.notifySubmitting();
})
.push(function () { .push(function () {
// Download the torrent // Download the torrent
return gadget.state.client.add(torrent_id, function (torrent) { return gadget.state.client.add(torrent_id, function (torrent) {
......
...@@ -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.32134.13599.6348</string> </value> <value> <string>990.12631.48739.25105</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>1611306236.6</float> <float>1614018738.61</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -33,7 +33,8 @@ url_list = [ ...@@ -33,7 +33,8 @@ url_list = [
"mynij_rss-parser.min.js", "mynij_rss-parser.min.js",
"rss-parser.min.js.map", "rss-parser.min.js.map",
"webtorrent.min.js", "webtorrent.min.js",
"jszip.min.js" "jszip.min.js",
"mynij-config.json"
] ]
return url_list return url_list
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