demo with dynamic player url

This commit is contained in:
Sean Yesmunt 2020-03-12 17:46:37 -04:00 committed by Niko Storni
parent 2b2607df61
commit 7afaeb8333
2 changed files with 15 additions and 19 deletions

View file

@ -1,27 +1,23 @@
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) {
let prefix = LBRY_TV_STREAMING_API || apiUrl;
if (prefix.includes('localhost')) {
return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
}
new Promise((resolve, reject) => {
const continent = getCookie(CONTINENT_COOKIE);
if (continent && prefix.split('//').length > 1) {
prefix = prefix.replace('//', '//' + continent + '.');
} else {
Lbryio.call('locale', 'get', {}, 'post').then(result => {
if (prefix.split('//').length > 1) {
prefix = prefix.replace('//', '//' + result.continent + '.');
}
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`;
const userContinent = result.continent;
setCookie(CONTINENT_COOKIE, userContinent, 1);
});
}
return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
}
function generateEmbedUrl(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(';');