-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat: new 'player' method with support async loading & profiles #678
Changes from 2 commits
fbf819e
0ebde6d
9095313
ec66e77
b6c4aae
704e5be
c42c014
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import 'assets/styles/main.scss'; | |
import pick from 'lodash/pick'; | ||
import VideoPlayer from './video-player'; | ||
import createVideoPlayerProfile from './video-player-profile'; | ||
import createPlayer from './player'; | ||
import { convertKeysToSnakeCase } from './utils/object'; | ||
import { CLOUDINARY_CONFIG_PARAM } from './video-player.const'; | ||
|
||
|
@@ -22,10 +23,14 @@ const getVideoPlayers = config => (selector, playerOptions, ready) => | |
|
||
const getVideoPlayerWithProfile = config => (id, playerOptions, ready) => createVideoPlayerProfile(id, getConfig(playerOptions, config), ready); | ||
|
||
const getPlayer = config => (id, playerOptions, ready) => createPlayer(id, getConfig(playerOptions, config), ready); | ||
|
||
export const videoPlayer = getVideoPlayer(); | ||
export const videoPlayers = getVideoPlayers(); | ||
export const videoPlayerWithProfile = getVideoPlayerWithProfile(); | ||
|
||
export const player = getPlayer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what abut There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ➕ |
||
|
||
const cloudinaryVideoPlayerLegacyConfig = config => { | ||
console.warn( | ||
'Cloudinary.new() is deprecated and will be removed. Please use cloudinary.videoPlayer() instead.' | ||
|
@@ -41,6 +46,7 @@ const cloudinary = { | |
videoPlayer, | ||
videoPlayers, | ||
videoPlayerWithProfile, | ||
player, | ||
Cloudinary: { | ||
// Backwards compatibility with SDK v1 | ||
new: cloudinaryVideoPlayerLegacyConfig | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// This file is bundled as `player.js` to be imported as a tree-shaken module. | ||
|
||
// Usage: | ||
// import player from 'cloudinary-video-player/player'; | ||
|
||
export { player as default } from './index.js'; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,34 @@ | ||||||
import VideoPlayer from './video-player'; | ||||||
import { defaultProfiles } from './config/profiles'; | ||||||
|
||||||
export const getProfile = async (cloudName, profile) => { | ||||||
if (Object.keys(defaultProfiles).includes(profile)) { | ||||||
return defaultProfiles[profile]; | ||||||
} | ||||||
|
||||||
console.warn('Custom profiles loading mechanism will be changed soon'); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? As a developer, if I see this, what do I do? |
||||||
return await fetch(profile, { method: 'GET' }).then(res => res.json()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The await here is redundant (So is the async in the function declaration)
Suggested change
|
||||||
}; | ||||||
|
||||||
const player = async (elem, initOptions, ready) => { | ||||||
const { profile, ...filteredInitOptions } = initOptions; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
try { | ||||||
const profileOptions = profile ? await getProfile(filteredInitOptions.cloud_name, profile) : {}; | ||||||
const options = Object.assign({}, profileOptions.playerOptions, filteredInitOptions); | ||||||
const videoPlayer = new VideoPlayer(elem, options, ready); | ||||||
|
||||||
const nativeVideoPlayerSourceMethod = videoPlayer.source; | ||||||
videoPlayer.source = (id, options) => { | ||||||
const extendedOptions = Object.assign({}, profileOptions.sourceOptions, options); | ||||||
return nativeVideoPlayerSourceMethod.call(videoPlayer, id, extendedOptions); | ||||||
}; | ||||||
|
||||||
return videoPlayer; | ||||||
} catch (e) { | ||||||
const videoPlayer = new VideoPlayer(elem, filteredInitOptions); | ||||||
videoPlayer.videojs.error('Invalid profile'); | ||||||
throw e; | ||||||
} | ||||||
}; | ||||||
|
||||||
export default player; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we having two separate methods that does exactly the same?
If we really must, just do
export const videoPlayerWithProfile = player
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is small difference between them (profile property as optional one) and there is possibility that some people are using it - in this case first we should deprecate it and later after some time just remove it