Skip to content

Commit

Permalink
Merge pull request #416 from cloudinary/ME-4810-support-cloudName
Browse files Browse the repository at this point in the history
ME-4810-support-cloudName
  • Loading branch information
tsi authored Aug 24, 2023
2 parents 0336ee0 + 3f3360c commit 65497c4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<script type="text/javascript">
window.addEventListener('load', function(){

player = cloudinary.videoPlayer('player', { cloud_name: 'demo' });
player = cloudinary.videoPlayer('player', { cloudName: 'demo' });

}, false);
</script>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"dependencies": {
"@cloudinary/url-gen": "^1.10.2",
"dashjs": "^4.7.1",
"lodash": "^4.17.21",
"uuid": "^9.0.0",
"video.js": "8.3.0",
"videojs-contrib-ads": "^6.9.0",
Expand Down
27 changes: 18 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import 'assets/styles/main.scss';
import VideoPlayer from './video-player';
import { assign } from 'utils/assign';
import { omit, pick } from './utils/object';
import { pick, convertKeysToSnakeCase } from './utils/object';
import { CLOUDINARY_CONFIG_PARAM } from './video-player.const';

if (window.cloudinary && window.cloudinary.Cloudinary) {
console.warn('For version 1.9.0 and above, cloudinary-core is not needed for using the Cloudinary Video Player');
console.warn(
'For version 1.9.0 and above, cloudinary-core is not needed for using the Cloudinary Video Player'
);
}

const getConfig = (playerOptions = {}, cloudinaryConfig) => assign(
omit(playerOptions, CLOUDINARY_CONFIG_PARAM),
{ cloudinaryConfig: cloudinaryConfig || pick(playerOptions, CLOUDINARY_CONFIG_PARAM) });
const getConfig = (playerOptions = {}, cloudinaryConfig) => {
const snakeCaseCloudinaryConfig = pick(convertKeysToSnakeCase(playerOptions), CLOUDINARY_CONFIG_PARAM);

const getVideoPlayer = (config) => (id, playerOptions, ready) => new VideoPlayer(id, getConfig(playerOptions, config), ready);
// pick cld-configurations and assign them to cloudinaryConfig
return assign(playerOptions, {
cloudinaryConfig: cloudinaryConfig || snakeCaseCloudinaryConfig
});
};

const getVideoPlayer = config => (id, playerOptions, ready) =>
new VideoPlayer(id, getConfig(playerOptions, config), ready);

const getVideoPlayers = (config) => (selector, playerOptions, ready) => VideoPlayer.all(selector, getConfig(playerOptions, config), ready);
const getVideoPlayers = config => (selector, playerOptions, ready) =>
VideoPlayer.all(selector, getConfig(playerOptions, config), ready);

const cloudinaryVideoPlayerConfig = (config) => ({
const cloudinaryVideoPlayerConfig = config => ({
videoPlayer: getVideoPlayer(config),
videoPlayers: getVideoPlayers(config)
});
Expand All @@ -36,4 +45,4 @@ const cloudinary = {

window.cloudinary = cloudinary;

export default cloudinary;
export default cloudinary;
13 changes: 12 additions & 1 deletion src/utils/object.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import snakeCase from 'lodash/snakeCase';

/**
* a nested value from an object
Expand Down Expand Up @@ -25,7 +26,6 @@ export const get = (value, path, defaultValue) => {
return defaultValue;
};


export const pick = (obj, keys) => {
return keys.reduce((acc, key) => {
const value = obj[key];
Expand All @@ -49,3 +49,14 @@ export const omit = (obj, keys) => {
return acc;
}, {});
};

export const convertKeysToSnakeCase = (obj) => {
let snakeCaseObj = {};

for (const key of Object.keys(obj)) {
const snakeCaseKey = snakeCase(key);
snakeCaseObj[snakeCaseKey] = obj[key];
}

return snakeCaseObj;
};
1 change: 0 additions & 1 deletion src/utils/string.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function camelize(str) {
return str.replace(/[_.-](\w|$)/g, (_, x) => x.toUpperCase());
}
Expand Down
8 changes: 4 additions & 4 deletions src/video-player.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class VideoPlayer extends Utils.mixin(Eventable) {
};
}

get playerOptions() {
return this.options.playerOptions;
}

constructor(elem, initOptions, ready) {
super();

Expand Down Expand Up @@ -516,10 +520,6 @@ class VideoPlayer extends Utils.mixin(Eventable) {
return this.videojs.cloudinary.cloudinaryConfig(config);
}

get playerOptions() {
return this.options.playerOptions;
}

currentPublicId() {
return this.videojs.cloudinary.currentPublicId();
}
Expand Down

0 comments on commit 65497c4

Please sign in to comment.