lbry-desktop/ui/util/lbrytv.js

44 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-03-17 14:58:34 -04:00
const { Lbryio } = require('lbryinc');
2020-01-24 11:25:31 -05:00
const { URL, LBRY_TV_STREAMING_API } = require('../../config');
2020-03-17 14:58:34 -04:00
const { getCookie, setCookie } = require('../../ui/util/saved-passwords');
const CONTINENT_COOKIE = 'continent';
2019-12-16 12:44:31 -05:00
2020-03-12 21:54:51 +01:00
function generateStreamUrl(claimName, claimId, apiUrl) {
2020-03-17 14:58:34 -04:00
let prefix = LBRY_TV_STREAMING_API || apiUrl;
const continent = getCookie(CONTINENT_COOKIE);
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 17:46:37 -04:00
return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
2019-10-21 10:50:34 -04:00
}
2019-10-22 10:40:57 -04:00
2020-03-17 14:58:34 -04:00
function getSupportedCDN(continent) {
switch (continent) {
case 'NA':
case 'EU':
return continent;
default:
return 'NA';
}
}
2019-12-16 12:44:31 -05:00
function generateEmbedUrl(claimName, claimId) {
return `${URL}/$/embed/${claimName}/${claimId}`;
2019-12-16 12:44:31 -05:00
}
2020-01-07 13:17:43 -05:00
function generateDownloadUrl(claimName, claimId, apiUrl) {
const streamUrl = generateStreamUrl(claimName, claimId, apiUrl);
return `${streamUrl}?download=1`;
}
2019-11-07 14:39:22 -05:00
// module.exports needed since the web server imports this function
2020-01-07 13:17:43 -05:00
module.exports = { generateStreamUrl, generateEmbedUrl, generateDownloadUrl };