@mcmhomes/panorama-viewer
Version:
Provides React components to render panoramas.
58 lines (54 loc) • 1.96 kB
JSX
import {each, FLOAT_LAX_ANY, STRING} from './PanoramaUtils.jsx';
let hasLoggedMissingBasisTranscoder = false;
/**
* Returns the given props with corrected values.
*
* @param {Object} props
* @returns {Object}
*/
export const getCorrectedGivenProps = (props) =>
{
const result = {};
each(props, (value, key) =>
{
let newValue = value;
switch(key)
{
case 'homeId':
case 'locationId':
case 'styleId':
newValue = STRING(value).replace(/[^a-zA-Z0-9_]+/g, '');
break;
case 'groupId':
case 'sku':
newValue = STRING(value).trim();
break;
case 'homeVersion':
newValue = (STRING(value).trim() || 'latest').toLowerCase();
break;
case 'host':
newValue = (STRING(value).trim() || 'https://d1i78mubvvqzk6.cloudfront.net');
break;
case 'minFov':
newValue = Math.max(1, FLOAT_LAX_ANY(value, 20));
break;
case 'maxFov':
newValue = Math.min(179, FLOAT_LAX_ANY(value, 130));
break;
case 'basisTranscoderPath':
newValue = STRING(value).trim();
if(!newValue)
{
newValue = 'https://d11xh1fqz0z9k8.cloudfront.net/basis_transcoder/';
if(!hasLoggedMissingBasisTranscoder)
{
console.warn('[PanoramaViewer] Warning: basisTranscoderPath is not set, the demo website\'s URL is used instead. \n\nThis is not recommended for production use!!! \n\nPlease host the [basis_universal webgl transcoder] yourself and set the basisTranscoderPath prop to it. \nSee the demo website\'s project on how to do that. \n\nFor example: \n1) napa "basis_universal": "git+https://github.com/BinomialLLC/basis_universal.git" \n2) on build: copy "node_modules/basis_universal/webgl/transcoder/build/*" to "dist/basis_transcoder/*" \n3) in react: <' + 'PanoramaViewer basisTranscoderPath="https://yourwebsite.cloudfront.net/basis_transcoder/" ... /' + '> \n\n');
hasLoggedMissingBasisTranscoder = true;
}
}
break;
}
result[key] = newValue;
});
return result;
};