Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLD-340-fixed-video-image-issue #98

Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,31 +1,4 @@
function initializeCloudinaryPlayers() {
const convertToSnakeCase = obj => JSON.parse(JSON.stringify(obj).replace(/"([^"]+)":/g, (_, p1) => `"${p1.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()}":`));
window.players.forEach(player => {
if (player) {
const pCnf = JSON.parse(player.playerConf);
const p = window.cld.videoPlayer(player.id, pCnf.playerConfig);
pCnf.sourceConfig['transformation'] = convertToSnakeCase(pCnf.sourceConfig.transformation)
pCnf.playerConfig['cloudName'] = pCnf.cloudName;
p.source(pCnf.publicId, pCnf.sourceConfig);
p.on('error', function (e) {
const error = e.Player.videojs.error();
if (error && error.code === 10) {
p.videojs.error(null);
p.videojs.error({ code: null, message: "Generating the video, please wait." });
}
})
}
});
}


$(document).ready(function () {
/**
* Page Designer does not become active until document.ready. Because if this
* it waits until streaming videos fully load. We need to delay initializing
* Cloudinary video player a little bit.
*/

if (!document.cloudinaryInit) {
document.cloudinaryInit = true;
let conf = {
Expand All @@ -35,7 +8,33 @@ $(document).ready(function () {
conf.secure_distribution = window.cname;
conf.private_cdn = true;
}
window.cld = window.cloudinary.Cloudinary.new(conf);
initializeCloudinaryPlayers();
var cld = window.cldPDVideoPlayer.Cloudinary.new(conf);
const convertToSnakeCase = obj => JSON.parse(JSON.stringify(obj).replace(/"([^"]+)":/g, (_, p1) => `"${p1.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()}":`));
window.players.forEach(player => {
if (player) {
const pCnf = JSON.parse(player.playerConf);
const p = cld.videoPlayer(player.id, pCnf.playerConfig);
pCnf.sourceConfig['transformation'] = convertToSnakeCase(pCnf.sourceConfig.transformation)
pCnf.playerConfig['cloudName'] = pCnf.cloudName;
p.source(pCnf.publicId, pCnf.sourceConfig);
p.on('error', function (e) {
const error = e.Player.videojs.error();
if (error && error.code === 10) {
p.videojs.error(null);
p.videojs.error({ code: null, message: "Generating the video, please wait." });
}
})
}
});
}
}


$(document).ready(function () {
/**
* Page Designer does not become active until document.ready. Because if this
* it waits until streaming videos fully load. We need to delay initializing
* Cloudinary video player a little bit.
*/
initializeCloudinaryPlayers();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asad-rafter This should be part of the script onload

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuval-cloudinary is our custom method, it will not work on script onLoad because when the cloudinary script loads our custom script hasn't loaded yet and it gives an error that initializeCloudinaryPlayers(); it is not a function.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asad-rafter Then please move the call to cloudinaryVideos.js so it is loaded before trying to execute initializeCloudinaryPlayers()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asad-rafter Our end goal is that each page to have the following structure:

  1. A single line calling CLDPDShrinkwrapJSURL
  2. One or more div sections of cloudinary-video-container
  3. A call to initializeCloudinaryPlayers()

These sections should be introduced one following the other without any delays or async operations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuval-cloudinary we are not using CLDPDShrinkwrapJSURL in video

Copy link
Contributor Author

@asad-rafter asad-rafter Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asad-rafter Then please move the call to cloudinaryVideos.js so it is loaded before trying to execute initializeCloudinaryPlayers()

@yuval-cloudinary Its already in cloudinaryVideos.js, I didn't get your point here

});
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
window.players.push(value);
window.cloudName = value.cloudName;
window.cname = value.cname || null;
window.cldPDVideoPlayer = cloudinary;
</script>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
<div class="cloudinary-media-library-container sfdc-component-mock sfdc-component-assets-media_library-mock">
<img class="component-media_library ml-image" src="${pdict.viewmodel.placeholder}"
data-real-url="${pdict.viewmodel.src}" id="${pdict.viewmodel.id}" alt="${pdict.viewmodel.altText}"
style="max-width: 100%">
style="max-width: 100%" />
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
window.players.push(value);
window.cloudName = value.cloudName;
window.cname = value.cname || null;

// Check if the Cloudinary Core JS is inculded
const shrinkWrapJs = document.querySelector('script[src="'+value.CLDPDShrinkwrapJSURL+'"]');
if (shrinkWrapJs) {
shrinkWrapJs.parentNode.removeChild(shrinkWrapJs);
}
window.cldPDVideoPlayer = cloudinary;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asad-rafter This should be part of the script onload

</script>
</div>