cloudinary-video-player
Version:
Cloudinary Video Player
93 lines (85 loc) • 4.41 kB
JavaScript
import { g as getCloudinaryConfigFromOptions, i as isRawUrl, a as appendQueryParams, u as utf8ToBase64 } from './cloudinary-config-from-options.js';
import { g as getCloudinaryUrlPrefix } from './cloudinary-url-prefix.js';
var dist = {};
var hasRequiredDist;
function requireDist () {
if (hasRequiredDist) return dist;
hasRequiredDist = 1;
(function (exports$1) {
var e={607:function(e,o,t){var l=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:true}),o.defaultProfiles=o.cldLiveStreamingProfile=o.cldAdaptiveStreamProfile=o.cldLoopingProfile=o.cldDefaultProfile=void 0;const r=l(t(704)),i=l(t(83)),a=l(t(832)),s=l(t(877));o.cldDefaultProfile={name:"cld-default",isDefault:true,config:r.default},o.cldLoopingProfile={name:"cld-looping",isDefault:true,config:i.default},o.cldAdaptiveStreamProfile={name:"cld-adaptive-stream",isDefault:true,config:a.default},o.cldLiveStreamingProfile={name:"cld-live-streaming",isDefault:true,config:s.default},o.defaultProfiles=[o.cldDefaultProfile,o.cldLoopingProfile,o.cldAdaptiveStreamProfile,o.cldLiveStreamingProfile];},832:e=>{e.exports=JSON.parse('{"playerOptions":{"fluid":true,"controls":true,"controlBar":{"fullscreenToggle":false},"showJumpControls":true,"hideContextMenu":false,"floatingWhenNotVisible":"none"},"sourceOptions":{"chapters":true,"sourceTypes":["hls"]}}');},704:e=>{e.exports=JSON.parse('{"playerOptions":{},"sourceOptions":{}}');},877:e=>{e.exports=JSON.parse('{"playerOptions":{},"sourceOptions":{"type":"live","sourceTypes":["hls"]}}');},83:e=>{e.exports=JSON.parse('{"playerOptions":{"fluid":true,"controls":false,"muted":true,"floatingWhenNotVisible":"none","hideContextMenu":false,"autoplay":true,"loop":true},"sourceOptions":{}}');}},o={},t=function t(l){var r=o[l];if(void 0!==r)return r.exports;var i=o[l]={exports:{}};return e[l].call(i.exports,i,i.exports,t),i.exports}(607),l=exports$1;for(var r in t)l[r]=t[r];t.__esModule&&Object.defineProperty(l,"__esModule",{value:true});
} (dist));
return dist;
}
var distExports = requireDist();
const isDefaultProfile = profileName => !!distExports.defaultProfiles.find(_ref => {
let {
name
} = _ref;
return profileName === name;
});
const getDefaultProfileConfig = profileName => {
const profile = distExports.defaultProfiles.find(_ref2 => {
let {
name
} = _ref2;
return profileName === name;
});
if (!profile) {
throw new Error(`Default profile with name ${profileName} does not exist`);
}
return profile.config;
};
const fetchConfig = async options => {
const {
profile,
publicId,
type = 'upload',
videoConfig,
allowUsageReport = true
} = options;
if (profile && isDefaultProfile(profile)) {
return getDefaultProfileConfig(profile);
}
const cloudinaryConfig = getCloudinaryConfigFromOptions(options);
const urlPrefix = getCloudinaryUrlPrefix(cloudinaryConfig) + '/_applet_/video_service';
const queryParams = allowUsageReport ? {
_s: 'vp'
} : null;
let configUrl;
if (profile) {
configUrl = isRawUrl(profile) ? profile : appendQueryParams(`${urlPrefix}/video_player_profiles/${profile.replaceAll(' ', '+')}.json`, queryParams);
} else if (publicId && videoConfig !== false) {
configUrl = appendQueryParams(`${urlPrefix}/video_player_config/video/${type}/${utf8ToBase64(publicId)}.json`, queryParams);
} else {
return {};
}
return fetch(configUrl, {
method: 'GET'
}).then(res => {
if (!res.ok) {
// fail silently
return {};
}
return res.json();
});
};
const fetchAndMergeConfig = async options => {
const profileOptions = await fetchConfig(options);
const fetchedConfig = profileOptions.playerOptions ? Object.keys(profileOptions.playerOptions) : [];
const profileAnalytics = {
_internalAnalyticsMetadata: {
newPlayerMethod: true,
...(options.profile ? {
profile: isDefaultProfile(options.profile) ? options.profile : true
} : {}),
...(!options.profile && options.videoConfig !== false && options.publicId ? {
videoConfig: true
} : {}),
...(fetchedConfig.length > 0 ? {
fetchedConfig: fetchedConfig.join(',')
} : {})
}
};
return Object.assign({}, profileOptions.playerOptions || {}, profileOptions.sourceOptions || {}, options, profileAnalytics);
};
export { fetchAndMergeConfig };