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 @@
return element;
}
function createWebTorrent() {
function createWebTorrent(rtcconfig) {
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"
]}
]
}
rtcConfig: rtcconfig
}
});
}
......@@ -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) {
var gadget = this,
index_id = "index-" + index_name;
......@@ -577,8 +598,11 @@
});
}
gadget.state.client = createWebTorrent();
return seedTorrent();
return gadget.getRtcconfig()
.push(function (config) {
gadget.state.client = createWebTorrent(config);
return seedTorrent();
});
})
.declareJob("download", function (torrent_id, redirect) {
......@@ -589,10 +613,13 @@
if (!torrent_id) {
return;
}
gadget.state.client = createWebTorrent();
gadget.state.redirect = redirect;
container.classList.remove('hidden');
return gadget.notifySubmitting()
return gadget.getRtcconfig()
.push(function (config) {
gadget.state.client = createWebTorrent(config);
return gadget.notifySubmitting();
})
.push(function () {
// Download the torrent
return gadget.state.client.add(torrent_id, function (torrent) {
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>989.32134.13599.6348</string> </value>
<value> <string>990.12631.48739.25105</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1611306236.6</float>
<float>1614018738.61</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -33,7 +33,8 @@ url_list = [
"mynij_rss-parser.min.js",
"rss-parser.min.js.map",
"webtorrent.min.js",
"jszip.min.js"
"jszip.min.js",
"mynij-config.json"
]
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