Localized player urls for lbry.tv #3836

Merged
neb-b merged 4 commits from localized_player into master 2020-03-17 18:38:02 +01:00
2 changed files with 28 additions and 3 deletions

View file

@ -1,10 +1,35 @@
const { Lbryio } = require('lbryinc');
const { URL, LBRY_TV_STREAMING_API } = require('../../config');
const { getCookie, setCookie } = require('../../ui/util/saved-passwords');
const CONTINENT_COOKIE = 'continent';
function generateStreamUrl(claimName, claimId, apiUrl) {
const prefix = LBRY_TV_STREAMING_API || apiUrl;
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);
});
}
return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
}
function getSupportedCDN(continent) {
switch (continent) {
case 'NA':
case 'EU':
return continent;
default:
return 'NA';
}
}
function generateEmbedUrl(claimName, claimId) {
return `${URL}/$/embed/${claimName}/${claimId}`;
}

View file

@ -10,7 +10,7 @@ const isProduction = process.env.NODE_ENV === 'production';
const maxExpiration = 2147483647;
let sessionPassword;
function setCookie(name: string, value: string, expirationDaysOnWeb: number) {
export function setCookie(name: string, value: string, expirationDaysOnWeb: number) {
let expires = '';
if (expirationDaysOnWeb) {
let date = new Date();
@ -27,7 +27,7 @@ function setCookie(name: string, value: string, expirationDaysOnWeb: number) {
document.cookie = cookie;
}
function getCookie(name: string) {
export function getCookie(name: string) {
const nameEQ = name + '=';
const cookies = document.cookie.split(';');