Localized player urls for lbry.tv #3836
2 changed files with 15 additions and 19 deletions
|
@ -1,27 +1,23 @@
|
||||||
const { Lbryio } = require('lbryinc');
|
const { Lbryio } = require('lbryinc');
|
||||||
const { URL, LBRY_TV_STREAMING_API } = require('../../config');
|
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) {
|
function generateStreamUrl(claimName, claimId, apiUrl) {
|
||||||
let prefix = LBRY_TV_STREAMING_API || apiUrl;
|
let prefix = LBRY_TV_STREAMING_API || apiUrl;
|
||||||
if (prefix.includes('localhost')) {
|
const continent = getCookie(CONTINENT_COOKIE);
|
||||||
return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
|
|
||||||
}
|
if (continent && prefix.split('//').length > 1) {
|
||||||
new Promise((resolve, reject) => {
|
prefix = prefix.replace('//', '//' + continent + '.');
|
||||||
|
} else {
|
||||||
Lbryio.call('locale', 'get', {}, 'post').then(result => {
|
Lbryio.call('locale', 'get', {}, 'post').then(result => {
|
||||||
if (prefix.split('//').length > 1) {
|
const userContinent = result.continent;
|
||||||
prefix = prefix.replace('//', '//' + result.continent + '.');
|
setCookie(CONTINENT_COOKIE, userContinent, 1);
|
||||||
}
|
|
||||||
resolve(prefix);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.then(p => {
|
|
||||||
console.log(`${p}/content/claims/${claimName}/${claimId}/stream`);
|
|
||||||
return `${p}/content/claims/${claimName}/${claimId}/stream`;
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
console.error(err.stack || err);
|
|
||||||
return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateEmbedUrl(claimName, claimId) {
|
function generateEmbedUrl(claimName, claimId) {
|
||||||
|
|
|
@ -10,7 +10,7 @@ const isProduction = process.env.NODE_ENV === 'production';
|
||||||
const maxExpiration = 2147483647;
|
const maxExpiration = 2147483647;
|
||||||
let sessionPassword;
|
let sessionPassword;
|
||||||
|
|
||||||
function setCookie(name: string, value: string, expirationDaysOnWeb: number) {
|
export function setCookie(name: string, value: string, expirationDaysOnWeb: number) {
|
||||||
let expires = '';
|
let expires = '';
|
||||||
if (expirationDaysOnWeb) {
|
if (expirationDaysOnWeb) {
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
|
@ -27,7 +27,7 @@ function setCookie(name: string, value: string, expirationDaysOnWeb: number) {
|
||||||
document.cookie = cookie;
|
document.cookie = cookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCookie(name: string) {
|
export function getCookie(name: string) {
|
||||||
const nameEQ = name + '=';
|
const nameEQ = name + '=';
|
||||||
const cookies = document.cookie.split(';');
|
const cookies = document.cookie.split(';');
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue