2020-03-24 21:35:51 +01:00
|
|
|
const { Lbryio } = require('lbryinc/dist/bundle.es.js');
|
2020-01-24 17:25:31 +01:00
|
|
|
const { URL, LBRY_TV_STREAMING_API } = require('../../config');
|
2020-03-17 19:58:34 +01:00
|
|
|
const { getCookie, setCookie } = require('../../ui/util/saved-passwords');
|
|
|
|
|
|
|
|
const CONTINENT_COOKIE = 'continent';
|
2019-12-16 18:44:31 +01:00
|
|
|
|
2020-03-25 22:49:14 +01:00
|
|
|
function generateStreamUrl(claimName, claimId, apiUrl, streamingContinent) {
|
2020-03-17 19:58:34 +01:00
|
|
|
let prefix = LBRY_TV_STREAMING_API || apiUrl;
|
2020-03-25 22:49:14 +01:00
|
|
|
const continent = streamingContinent || getCookie(CONTINENT_COOKIE);
|
2020-03-17 19:58:34 +01:00
|
|
|
|
|
|
|
if (continent && prefix.split('//').length > 1) {
|
|
|
|
prefix = prefix.replace('//', '//' + continent + '.');
|
|
|
|
} else {
|
|
|
|
Lbryio.call('locale', 'get', {}, 'post').then(result => {
|
|
|
|
const userContinent = getSupportedCDN(result.continent);
|
|
|
|
setCookie(CONTINENT_COOKIE, userContinent, 1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-03-12 22:46:37 +01:00
|
|
|
return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
|
2019-10-21 16:50:34 +02:00
|
|
|
}
|
2019-10-22 16:40:57 +02:00
|
|
|
|
2020-03-17 19:58:34 +01:00
|
|
|
function getSupportedCDN(continent) {
|
|
|
|
switch (continent) {
|
|
|
|
case 'NA':
|
|
|
|
case 'EU':
|
|
|
|
return continent;
|
|
|
|
default:
|
|
|
|
return 'NA';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 18:44:31 +01:00
|
|
|
function generateEmbedUrl(claimName, claimId) {
|
2019-12-20 17:26:55 +01:00
|
|
|
return `${URL}/$/embed/${claimName}/${claimId}`;
|
2019-12-16 18:44:31 +01:00
|
|
|
}
|
|
|
|
|
2020-03-25 22:49:14 +01:00
|
|
|
function generateDownloadUrl(claimName, claimId) {
|
2020-03-30 15:14:01 +02:00
|
|
|
return `${URL}/$/download/${claimName}/${claimId}`;
|
2020-01-07 19:17:43 +01:00
|
|
|
}
|
|
|
|
|
2020-03-27 19:57:03 +01:00
|
|
|
function generateDirectUrl(claimName, claimId) {
|
|
|
|
return `${URL}/$/stream/${claimName}/${claimId}`;
|
|
|
|
}
|
|
|
|
|
2019-11-07 20:39:22 +01:00
|
|
|
// module.exports needed since the web server imports this function
|
2020-03-27 19:57:03 +01:00
|
|
|
module.exports = { generateStreamUrl, generateEmbedUrl, generateDownloadUrl, generateDirectUrl, CONTINENT_COOKIE };
|