-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Split poster and thumbs handling to separate ott & ovp files. Handle ott poster logic.
- Loading branch information
Dan Ziv
authored
Mar 12, 2018
1 parent
9b21393
commit 96a51b3
Showing
9 changed files
with
159 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// @flow | ||
import {DEFAULT_THUMBS_SLICES, DEFAULT_THUMBS_WIDTH} from '../common/utils/thumbs' | ||
import {Utils} from 'playkit-js' | ||
import {UIManager} from 'playkit-js-ui' | ||
|
||
/** | ||
* Add poster with player dimensions. | ||
* If poster is string and width and height exists in template we need to make a thumbnail API call. | ||
* If poster is array of objects we need to choose the best fit dimensions according to the player dimensions. | ||
* @param {Object} metadata - metadata container | ||
* @param {number} width - player width in px | ||
* @param {number} height - player height in px | ||
* @returns {void} | ||
*/ | ||
function addKalturaPoster(metadata: Object, width: number, height: number): void { | ||
if (typeof metadata.poster === 'string') { | ||
const regex = /.*\/thumbnail\/.*(?:width|height)\/\d+\/(?:height|width)\/\d+/; | ||
if (regex.test(metadata.poster)) { | ||
metadata.poster = setPlayerDimensionsOnPoster(metadata.poster, width, height); | ||
} | ||
} else if (Array.isArray(metadata.poster)) { | ||
metadata.poster = selectPosterByPlayerDimensions(metadata.poster, width, height); | ||
} | ||
} | ||
|
||
/** | ||
* Sets the preview thumbnail config for the ui seekbar component. | ||
* @param {UIManager} uiManager - The ui manager. | ||
* @returns {void} | ||
*/ | ||
function setUISeekbarConfig(uiManager: UIManager): void { | ||
let seekbarConfig = Utils.Object.getPropertyPath(uiManager, 'config.components.seekbar'); | ||
if (seekbarConfig) { | ||
seekbarConfig = Utils.Object.mergeDeep({ | ||
thumbsWidth: DEFAULT_THUMBS_WIDTH, | ||
thumbsSlices: DEFAULT_THUMBS_SLICES | ||
}, seekbarConfig); | ||
uiManager.setConfig(seekbarConfig, "seekbar"); | ||
} | ||
} | ||
|
||
/** | ||
* Replace the current dimensions with the player dimensions. | ||
* @param {string} poster - Player url. | ||
* @param {number} playerWidth - Player width. | ||
* @param {height} playerHeight - Player height. | ||
* @return {string} - The new poster url including the player dimensions. | ||
*/ | ||
function setPlayerDimensionsOnPoster(poster: string, playerWidth: number, playerHeight: number): string { | ||
const widthMatch = poster.match(/width\/(\d+)/); | ||
const heightMatch = poster.match(/height\/(\d+)/); | ||
if (Array.isArray(widthMatch)) { | ||
poster = poster.replace(widthMatch[1], playerWidth.toString()); | ||
} | ||
if (Array.isArray(heightMatch)) { | ||
poster = poster.replace(heightMatch[1], playerHeight.toString()); | ||
} | ||
return poster; | ||
} | ||
|
||
/** | ||
* Selects the best fit poster depends on the player dimensions. | ||
* @param {string} posters - Array of posters candidates. | ||
* @param {number} playerWidth - Player width. | ||
* @param {height} playerHeight - Player height. | ||
* @return {string} - The poster url. | ||
*/ | ||
function selectPosterByPlayerDimensions(posters: Array<Object>, playerWidth: number, playerHeight: number): string { | ||
let min = Infinity; | ||
let url = ''; | ||
posters.forEach(picture => { | ||
const picWidth = picture.width; | ||
const picHeight = picture.height; | ||
const widthDelta = Math.abs(picWidth - playerWidth); | ||
const heightDelta = Math.abs(picHeight - playerHeight); | ||
const delta = widthDelta + heightDelta; | ||
if (delta < min) { | ||
min = delta; | ||
url = picture.url; | ||
} | ||
}); | ||
return url; | ||
} | ||
|
||
export {addKalturaPoster, setUISeekbarConfig}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// @flow | ||
import {DEFAULT_THUMBS_SLICES, DEFAULT_THUMBS_WIDTH, getThumbSlicesUrl} from '../common/utils/thumbs' | ||
import {UIManager} from 'playkit-js-ui' | ||
|
||
/** | ||
* Add poster with player dimensions to thumbnail API call | ||
* @param {Object} metadata - metadata container | ||
* @param {number} playerWidth - player width in px | ||
* @param {number} playerHeight - player height in px | ||
* @returns {void} | ||
*/ | ||
function addKalturaPoster(metadata: Object, playerWidth: number, playerHeight: number): void { | ||
if (metadata.poster) { | ||
metadata.poster = `${metadata.poster}/height/${playerHeight}/width/${playerWidth}`; | ||
} | ||
} | ||
|
||
/** | ||
* Sets the preview thumbnail config for the ui seekbar component. | ||
* @param {UIManager} uiManager - The ui manager. | ||
* @param {Object} mediaConfig - The provider media config. | ||
* @returns {void} | ||
*/ | ||
function setUISeekbarConfig(uiManager: UIManager, mediaConfig: Object): void { | ||
uiManager.setConfig({ | ||
thumbsSprite: getThumbSlicesUrl(mediaConfig), | ||
thumbsWidth: DEFAULT_THUMBS_WIDTH, | ||
thumbsSlices: DEFAULT_THUMBS_SLICES | ||
}, "seekbar"); | ||
} | ||
|
||
export {addKalturaPoster, setUISeekbarConfig}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {addKalturaPoster} from '../../../src/ovp/poster-and-thumbs' | ||
|
||
describe('addKalturaPoster', function () { | ||
it('should append width and height to kaltura poster', function () { | ||
let metadata = {poster: 'https//my/kaltura/poster'}; | ||
addKalturaPoster(metadata, 640, 360); | ||
metadata.poster.should.equal('https//my/kaltura/poster/height/360/width/640'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters